import matplotlib
# Allow running headless from the command line
matplotlib.use("agg")

# To install:
#  get anaconda
# For headless/scripting operation:
#  yum install xorg-x11-server-Xvfb

from numpy import *
from pylab import *
import sys
import os;
import glob;
import datetime

# 
# Usage doFFTPNGaxis.py Filename.png
#
# Loading in a receiver generated FFT PNG file (Filename.png) and adds
# an axis to it, the result is saved as Filename-out.png
#

fileName = sys.argv[1]
print(fileName)
fig = figure(figsize=(18,10))
try:
  A=imread(fileName)
except:
  print("Error\n")
else:
  # Remove everthing up until the date
  tmp = fileName[:-16]
  day = tmp[-2:]
  month = tmp[-4:-2]
  year = tmp[-8:-4]
  YYYYMMDD = year + "-" + month + "-" + day

  if(fileName.find('L1') > 0):
    imshow(A,extent=[1560,1610,0,-1439/60],aspect='auto')
    title('L1 Spectrogram - ' + YYYYMMDD)
  elif(fileName.find('L2') > 0):
    imshow(A,extent=[1210,1260,0,-1439/60],aspect='auto')
    title('L2 Spectrogram - ' + YYYYMMDD)
  elif(fileName.find('E6') > 0):
    imshow(A,extent=[1255,1305,0,-1439/60],aspect='auto')
    title('E6 Spectrogram - ' + YYYYMMDD)
  else:
    imshow(A,extent=[1160,1210,0,-1439/60],aspect='auto')
    title('L5 Spectrogram - ' + YYYYMMDD)

  xlabel('Frequency [MHz]')
  ylabel('Time Before Day Roll [Hours]')
  grid('on')
  
  # Remove the ".png" from the input file name
  fileName = fileName[:-4] + "-out.png"
  savefig(fileName,dpi=150,bbox_inches='tight')
  
  close()



