"""This Python script is a solution to the following problem: Write a program that will plot the last hour of NEL long pulse data above 70 degrees elevation at Poker Flat. Saves plot in $PWD/test.png. $Id: plotLastPoker.py,v 1.4 2011/07/14 16:06:20 brideout Exp $ """ import os, os.path, sys import datetime import madrigalWeb.madrigalWeb import madrigalWebPlot.madrigalPlot # constants url = 'http://isr.sri.com/madrigal/' user_fullname = 'Bill Rideout' user_email = 'brideout@haystack.mit.edu' user_affiliation = 'MIT Haystack' outputPlot = os.path.join(os.getcwd(), 'test.png') instCode = 61 # Poker Flat ISR (PFISR) kindat = 5950 # SRI's kindat for Long pulse data files # connect to Madrigal web site madObj = madrigalWeb.madrigalWeb.MadrigalData(url) # set start time to six months ago, and end time to now endTime = datetime.datetime.now() startTime = endTime - datetime.timedelta(31*6) # call API to list all experiments for given instruments and a time range expList = madObj.getExperiments(instCode, startTime.year, startTime.month, startTime.day, startTime.hour, startTime.minute, startTime.second, endTime.year, endTime.month, endTime.day, endTime.hour, endTime.minute, endTime.second) expList.sort() lastExp = expList[-1] # print the time the last experiment ran print 'End time of last experiment = %04i-%02i-%02i %02i:%02i:%02i' % (lastExp.endyear, lastExp.endmonth, lastExp.endday, lastExp.endhour, lastExp.endmin, lastExp.endsec) # get a list of all files in that experiment fileList = madObj.getExperimentFiles(lastExp.id) # filter out all but last hour of data lastTime = datetime.datetime(lastExp.endyear, lastExp.endmonth, lastExp.endday, lastExp.endhour, lastExp.endmin, lastExp.endsec) # set one hour earlier lastTime -= datetime.timedelta(hours=1) filterStr = lastTime.strftime(' date1=%m/%d/%Y time1=%H:%M:%S ') filterStr += 'filter=elm,70, ' for thisFile in fileList: if thisFile.kindat == kindat: # make sure we plot the long pulse file isprintText = madObj.isprint(thisFile.name, 'ut1,gdalt,nel', filterStr, user_fullname, user_email, user_affiliation) plotObj = madrigalWebPlot.madrigalPlot.madPcolorPlot(isprintText, 'Last hour of Poker Flat NEL', 'Time', 'NEL above 70 degrees elevation', outputPlot, useAbsoluteTime = True) print('plot created at %s' % (outputPlot)) break