def create_insert(db, ImageHeader, FileNameString, PipelineFileNameString): #set up all the image header variables ExposureTimeString = createstring(ImageHeader, 'EXPTIME', '%5.3f') TelEpochString = createstring(ImageHeader, 'EQUINOX', '%6.2f', '2000.0') TargetNameString = createstring(ImageHeader, 'OBJECT', '%s') InstrueNameString = createstring(ImageHeader, 'INSTRUME', '%s') ObsModeString = createstring(ImageHeader, 'OBSMODE', '%s') DetModeString = createstring(ImageHeader, 'DETMODE', '%s') InstrueNameString = createstring(ImageHeader, 'INSTRUME', '%s') ProposalCodeString = createstring(ImageHeader, 'PROPID', '%s', default='UNKNOWN') ObservatString = createstring(ImageHeader, 'OBSERVAT', '%s') ProposalString = createstring(ImageHeader, 'PROPOSAL', '%s') #get the ProposalCode_Id if not ProposalCodeString.strip(): ProposalCodeString = 'NONE' ProposalCodeId = getpropcodeid(db, ProposalCodeString) #set the pipeline strings that are a little more difficult to set try: UTStartString = ImageHeader['DATE-OBS'] + ' ' + ImageHeader['TIME-OBS'] except: UTStartString = '1000-01-01 00:00:00' if not UTStartString.strip(): UTStartString = '1000-01-01 00:00:00' try: TelRA = 15.0 * sex2dec(ImageHeader['TELRA']) TelDec = sex2dec(ImageHeader['TELDEC']) TelRAString = '%10.7f' % TelRA TelDecString = '%10.7f' % TelDec except Exception, e: UTStartString = '1000-01-01 00:00:00' TelRAString = '0.00000' TelDecString = '100.0000'
def create_insert(db, ImageHeader, FileNameString, PipelineFileNameString): #set up all the image header variables ExposureTimeString=createstring(ImageHeader, 'EXPTIME', '%5.3f') TelEpochString=createstring(ImageHeader, 'EQUINOX', '%6.2f') TargetNameString=createstring(ImageHeader, 'OBJECT', '%s') InstrueNameString=createstring(ImageHeader, 'INSTRUME', '%s') ObsModeString=createstring(ImageHeader, 'OBSMODE', '%s') DetModeString=createstring(ImageHeader, 'DETMODE', '%s') InstrueNameString=createstring(ImageHeader, 'INSTRUME', '%s') ProposalCodeString=createstring(ImageHeader, 'PROPID', '%s', default='UNKNOWN') ObservatString=createstring(ImageHeader, 'OBSERVAT', '%s') ProposalString=createstring(ImageHeader, 'PROPOSAL', '%s') #get the ProposalCode_Id if not ProposalCodeString.strip(): ProposalCodeString='NONE' ProposalCodeId=getpropcodeid(db, ProposalCodeString) #set the pipeline strings that are a little more difficult to set try: UTStartString=ImageHeader['DATE-OBS']+' '+ImageHeader['TIME-OBS'] except: UTStartString='1000-01-01 00:00:00' if not UTStartString.strip(): UTStartString='1000-01-01 00:00:00' try: TelRA=15.0*sex2dec(ImageHeader['TELRA']) TelDec=sex2dec(ImageHeader['TELDEC']) TelRAString='%10.7f' % TelRA TelDecString='%10.7f' % TelDec except Exception, e: UTStartString='1000-01-01 00:00:00' TelRAString='0.00000' TelDecString='100.0000'
def updateheaders(struct, ext, tdiff, real_expt, utc, infile): # exit if tdiff wasn't updated if tdiff == real_expt: msg='No adequate correction found for frame %i in file %s' % (ext, infile) raise SaltError(msg) return struct # calculate the new utc value try: ntime=salttime.sex2dec(utc) ntime=ntime-tdiff/3600.0 newutc=salttime.dec2sex(ntime) except Exception as e: msg='Could not update UTC in %i header of image %s because %s' % (ext, infile, e) raise SaltError(msg) return struct # update the headers if utc==saltsafekey.get('UTC-OBS', struct): expt_string='%5.4f' % real_expt td_string='%5.4f' % tdiff if not saltsafekey.found('DUTC', struct): try: saltsafekey.put('UTC-OBS', newutc, struct, infile) saltsafekey.put('TIME-OBS', newutc, struct, infile) saltsafekey.new('DWETIME', expt_string, 'Dwell Time', struct, infile) saltsafekey.new('DUTC', td_string, 'Change in UTC time', struct, infile) except Exception as e: msg='Could not update %i header of image %s because %s' % (ext, infile, e) raise SaltIOError(msg) else: try: saltsafekey.put('UTC-OBS', newutc, struct, infile) saltsafekey.put('TIME-OBS', newutc, struct, infile) saltsafekey.put('DWETIME', real_expt, struct, infile) saltsafekey.put('DUTC', tdiff, struct, infile) except Exception as e: msg='Could not update %i header of image %s because %s' % (ext, infile, e) raise SaltError(msg) else: raise SaltIOError('Frame missing from list of times') return struct
def updateheaders(struct, ext, tdiff, real_expt, utc, infile): # exit if tdiff wasn't updated if tdiff == real_expt: msg='No adequate correction found for frame %i in file %s' % (ext, infile) raise SaltError(msg) return struct # calculate the new utc value try: ntime=salttime.sex2dec(utc) ntime=ntime-tdiff/3600.0 newutc=salttime.dec2sex(ntime) except Exception,e: msg='Could not update UTC in %i header of image %s because %s' % (ext, infile, e) raise SaltError(msg) return struct
def updateheaders(struct, ext, tdiff, real_expt, utc, infile): # exit if tdiff wasn't updated if tdiff == real_expt: msg = 'No adequate correction found for frame %i in file %s' % (ext, infile) raise SaltError(msg) return struct # calculate the new utc value try: ntime = salttime.sex2dec(utc) ntime = ntime - tdiff / 3600.0 newutc = salttime.dec2sex(ntime) except Exception, e: msg = 'Could not update UTC in %i header of image %s because %s' % ( ext, infile, e) raise SaltError(msg) return struct
def create_insert(db, ImageHeader, FileNameString, PipelineFileNameString): #set up all the image header variables ExposureTimeString=createstring(ImageHeader, 'EXPTIME', '%5.3f') TelEpochString=createstring(ImageHeader, 'EQUINOX', '%6.2f', '2000.0') TargetNameString=createstring(ImageHeader, 'OBJECT', '%s') InstrueNameString=createstring(ImageHeader, 'INSTRUME', '%s') ObsModeString=createstring(ImageHeader, 'OBSMODE', '%s') DetModeString=createstring(ImageHeader, 'DETMODE', '%s') InstrueNameString=createstring(ImageHeader, 'INSTRUME', '%s') ProposalCodeString=createstring(ImageHeader, 'PROPID', '%s', default='UNKNOWN') ObservatString=createstring(ImageHeader, 'OBSERVAT', '%s') ProposalString=createstring(ImageHeader, 'PROPOSAL', '%s') #get the ProposalCode_Id if not ProposalCodeString.strip(): ProposalCodeString='NONE' ProposalCodeId=getpropcodeid(db, ProposalCodeString) #set the pipeline strings that are a little more difficult to set try: UTStartString=ImageHeader['DATE-OBS']+' '+ImageHeader['TIME-OBS'] except: UTStartString='1000-01-01 00:00:00' if not UTStartString.strip(): UTStartString='1000-01-01 00:00:00' try: TelRA=15.0*sex2dec(ImageHeader['TELRA']) TelDec=sex2dec(ImageHeader['TELDEC']) TelRAString='%10.7f' % TelRA TelDecString='%10.7f' % TelDec except Exception as e: UTStartString='1000-01-01 00:00:00' TelRAString='0.00000' TelDecString='100.0000' try: PipelineStartString=datatimeobs2DateTime(ImageHeader['SAL-TLM']) except Exception as inst: PipelineStartString='1000-01-01 00:00:00' #set the number of exposures nexposures=1 try: if ImageHeader['DETMODE'].count('SLOT'): nexposures=ImageHeader['NEXTEND'] #this is hardwired but should be changed to use NAMPS if ImageHeader['INSTRUME'] is 'RSS': nexposures=nexposures/6 else: nexposures=nexposures/4 except: pass if not PipelineFileNameString: PipelineFileNameString=FileNameString try: name=os.path.basename(FileNameString).split('.')[0] date = '%s-%s-%s' % (name[1:5], name[5:7], name[7:9]) except Exception as e: message='Could not determine the date for %s because %s' \ % (FileNameString, e) raise SALTMySQLError(message) #get the obsstats #ObsStatsId=getobsstatsid(db, date) try: filesize=os.path.getsize(PipelineFileNameString)/1024.0 except OSError: filesize=os.path.getsize(FileNameString)/1024.0 except: filesize=0 #get the block id try: BlockString=ImageHeader['BLOCKID'].strip() BlockString=saltio.checkfornone(BlockString) try: if int(BlockString)==0: BlockString=None except: pass except KeyError: BlockString='' #get the block id try: BlockVisitString=ImageHeader['BVISITID'].strip() BlockVisitString=saltio.checkfornone(BlockVisitString) try: if int(BlockVisitString)==0: BlockVisitString=None except: pass except KeyError: BlockVisitString='' #create the insertion command for the data try: insert_command='StepStats_Id=1,' insert_command += "UTStart='"+UTStartString+"'," insert_command += "ProposalCode_Id=%i," % ProposalCodeId insert_command += "Target_Name='"+TargetNameString+"'," insert_command += "ExposureTime='"+ExposureTimeString+"'," insert_command += "TelRA='"+TelRAString+"'," insert_command += "TelDec='"+TelDecString+"'," insert_command += "TelEpoch='"+TelEpochString+"'," insert_command += "FileName='"+FileNameString+"'," insert_command += "PipelineDate='"+PipelineStartString+"'," insert_command += "PipelineFileName='"+PipelineFileNameString+"'," insert_command += "INSTRUME='"+InstrueNameString+"'," insert_command += "OBSMODE='"+ObsModeString+"'," insert_command += "DETMODE='"+DetModeString+"'," insert_command += "NExposures='%i',"%nexposures insert_command += "FileSize='%i'"%filesize if BlockString: insert_command += ",Block_Id='%s'"%BlockString if BlockVisitString: insert_command += ",BlockVisit_Id='%s'"%BlockVisitString except Exception as e: message='Could not create insert command because %s' % e raise SALTMySQLError(message) return insert_command