PDS_VERSION_ID = PDS3 RECORD_TYPE = FIXED_LENGTH RECORD_BYTES = 80 OBJECT = TEXT PUBLICATION_DATE = 2011-07-31 NOTE = "Stardust-NExT CIDA /DOCUMENT/SAMPLES/SAMPINFO.TXT" END_OBJECT = TEXT END SAMPLES/ contents ================= This file describes the contents of this /DOCUMENT/SAMPLES/ directory. The documents in this directory are samples for a PDS user to compare with their own products to confirm that they are reading the data correctly. For the Stardust-NExT CIDA data in this data set, the documents are plots of the eighty-one encounter events which occurred on the day of the flyby of comet 9P/Tempel 1 by the Stardust spacecraft. The plots are in the form of PNG images, and there is an HTML index page, containing thumbnail versions of the plots, ten to a row, to simplify browsing through the plots. SAMPLES/ directory layout ========================= /DOCUMENT/ | +--DOCINFO.TXT Information about data set /DOCUMENT/ directory +--*.LBL PDS labels for data set documents +--*.* Data set documents | +--SAMPLES/ This directory | +--SAMPLES.LBL PDS label of documents in this directory +--SAMPLES.HTM Index page for browsing plots +--Tyyyymoddhhmmssx.PNG Full-size plots as PNG images +--Tyyyymoddhhmmssx_S.PNG Thumbnail plots as PNG images +--SAMPINFO.TXT This file SAMPLES/ generation scripts =========================== The code used to generate the plots is provided below as an example of how to read the CIDA Spectrum EDFs. ######################################################################## ######################################################################## ### Start of sampleedf.py import os import re import sys import pprint import datetime from pds import pdsify import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt """ Sample Python script to convert Stardust-NExT Spectrum (Event) EDF files to images and to HTML index page Usage: python sampleedf.py ../../data/*/T20110215*.TAB * See import statements above for dependencies * This routine is provided as is with no support or guarantee. """ ######################################################################## ### Utility routine: convert ISO UTC (e.g. PDS START_TIME) to datetime def utc2dt(utc): exec('rtn=datetime.datetime(' + ','.join(re.split('[-T:]0?',utc))+')') return rtn ######################################################################## ### Initialization: ### - Convert TCA to datetime ### - Determine destination directory: ### - Get plot scaling for use with in generating thumbnails ### - Set plot labels ### - Open image index page as HTML file samples.htm, write initial info dtTca=utc2dt('2011-02-15T04:39:12') if 'SAMPLESDIR' in os.environ: subdir=os.environ['SAMPLESDIR'] else:subdir='./' xi,yi=plt.gcf().get_size_inches() labels = ('Target','Low Delayed','Low Straight','High Delayed','High Straight') fHtml=open(os.path.join(subdir,'samples.htm'),'w') fHtml.write("""\r

Sample plots of CIDA encounter Spectrum (Event) EDFs\r

\r \r
\r \r """) pngList=[] ### Full-size and thumbnail images modHtml=10 ### Number of images per row in image index page HTML iImg=0 ### Image number; (iImg % 10) == 0 starts new row) ######################################################################## ### Loop through command line arguments (Spectrum EDF filenames) for av in sys.argv[1:]: ###################################################################### ### Check basename: Tyyyymoddhhmmssx.TAB bn = os.path.basename(av) if bn[-4:].upper()!='.TAB' or bn[0].upper()!='T': print( dict( xpass=True,av=av,bn=bn) ) continue ###################################################################### ### Read all lines of Spectrum EDF into list of strings alllines = open(av,'r').readlines() ###################################################################### ### Simple robust PDS parser for Spectrum EDF parses lines up to just ### before last 8194 lines (8192-line spectrum + 1-line geom + 1-line ### header); does not get all keywords or handle objects, but will ### get the ones we want for oneline in [stripit.rstrip() for stripit in alllines[:-8194]]: try: toks=oneline.split() if len(toks)<3: continue if toks[1]!='=': continue c=toks[2][0].upper() if c>='A' and c<='Z' or c=='^' or c=='{' or c=='(' : continue exec(oneline) except: try: exec( toks[0] + '=' + '"'+' '.join(toks[2:]) + '"' ) except: pass ###################################################################### ### Move the ones we want into more convenient variables utc,pid,targ,mode=( START_TIME, PRODUCT_ID ,TARGET_NAME ,INSTRUMENT_MODE_ID[:8] ,) ###################################################################### ### Parse spectrum data (10 comma-separated values per line) from last ### 8192 lines: chdata[0:5] are EDR data; chdata[5:10] are RDR data ### in picoCoulombs; ### Clamp EDR and RDR data to a minimum of 0.01 so semilogy() does not ### fail chdata=[] for i in range(10): chdata+=[[]] for row in alllines[-8192:]: for i,v in enumerate( eval('['+row[:-2]+']')[:10] ): chdata[i]+=[max(.01,v)] ###################################################################### ### Make thumbnail plot of RDR data vs estimated mass thumbFn=os.path.join(subdir,bn.lower()[:-4]+'_s.png') fullFn=os.path.join(subdir,bn.lower()[:-4]+'.png') title=' // '.join( [pid,targ,mode] ) try: open(thumbFn,"r").close() open(fullFn,"r").close() if "SHOWSKIPS" in os.environ: print( dict(skipping=(thumbFn,fullFn)) ) except: if "SHOWPLOTS" in os.environ: print( dict(plotting=(thumbFn,fullFn)) ) plt.gcf().set_size_inches((xi/8,yi/8)) plt.semilogy() plt.gca().set_axis_off() colors = 'bgrcm' for i,L in enumerate(labels): plt.plot(range(8192),chdata[9-i],color=colors[i]) plt.savefig(thumbFn) plt.clf() plt.cla() plt.gcf().set_size_inches((xi,yi)) #################################################################### ### Make full-size plot ### Title is PRODUCT_ID // TARGET_NAME // INSTRUMENT_MODE_ID[:8] ### - will be title in plot and text in tooltip of image on index page plt.semilogy() plt.xlabel('25ns bin number') plt.ylabel('Charge, pC') for i,L in enumerate(labels): plt.plot(range(8192),chdata[9-i],label=L,color=colors[i]) ###plt.legend(shadow=False,loc='lower left') plt.legend(shadow=False,loc=(.48,.6)) plt.title( title ) plt.savefig(fullFn) plt.clf() plt.cla() ###################################################################### ### End current row, start new row every modHtml images on index page if (iImg%modHtml)==0: fHtml.write( """ %s\r\n""" % ( ''*(iImg>0) ,) ) iImg+=1 ###################################################################### ### Calculate time wrt TCA deltaT = utc2dt(utc) - dtTca deltaSecs = 86400*deltaT.days + deltaT.seconds ###################################################################### ### Write \r\n""" % (tyme ,'+-'[mode[:3]=='NEG'] ,) ) pngList+=[os.path.basename(fullFn),os.path.basename(thumbFn)] chdata=alllines=[] fHtml.flush() ### End of loop ###################################################################### ######################################################################## ### Finish index page fHtml.write("""%s
stanza to index page ### Add images to list ### Clear spectrum data fHtml.write( """ """ % (os.path.basename(fullFn) ,title ,title ,) ) fHtml.write( """""" % ( os.path.basename(thumbFn) ,) ) if "USEUTC" in os.environ: tyme = utc[:10] else : tyme = "TCA%+ds" % (deltaSecs,) fHtml.write( """
%s
; I %s
\r\n""" % ( ' \r\n'*(iImg>0) ,) ) fHtml.close() ######################################################################## ### Write SAMPLES.TXT and SAMPLES.LBL (PDS label for images and for ### index page) sampInfoFmt = """ ########################################################################### ### SAMPINFO.TXT text was here ... ########################################################################### """[22:-21] sampLblFmt=""" ########################################################################### ### SAMPLES.LBL text was here ... ########################################################################### """[22:-22] codetoks = open(__file__,"r").read().split('###__SAMPLES'+'_SPLIT__') codetoks[1]='\n'.join(['#'*75,'### SAMPINFO.TXT text was here ...','#'*75]) codetoks[3]='\n'.join(['#'*75,'### SAMPLES.LBL text was here ...','#'*75]) code = ''.join(codetoks) pngDocs = '"\n , "'.join(pngList).upper() nPngs = len(pngList) cr='\r' nl='\n' crlf=cr+nl sampInfo = crlf.join( (sampInfoFmt % locals()).split(nl) ) sampLblList=[] for sampLblLine in (sampLblFmt % locals()).split(nl): sampLblList += pdsify.sout(sampLblLine)[1] sampLbl = nl.join( sampLblList ) + nl open(os.path.join(subdir,'__sampinfo.txt'),"w").write(sampInfo) open(os.path.join(subdir,'samples.lbl'),"w").write(sampLbl) ########################################################################### ### End of sampleedf.py ######################################################################## ########################################################################