def loaddata(fid, filename, sdb, das): """Load the data from the sdb to the das database for file with filedata_id given by fid""" print fid #load the data in filed data select="FileData_Id, UTStart, Target_Name, ExposureTime, FileName, INSTRUME, OBSMODE, DETMODE, Proposal_Code, Filter, TelRa, TelDec, FileName, FileSize" table="FileData join ProposalCode using (ProposalCode_Id)" if filename.startswith('S'): table += "join FitsHeaderSalticam using (FileData_Id)" elif filename.startswith('P'): table += "join FitsHeaderRss using (FileData_Id)" logic="FileData_ID=%i" % fid record = saltmysql.select(sdb, select, table, logic) print '%s' % record[0][1] record=record[0] insert="filedata_id=%i, UTSTART='%s', object='%s', exposuretime=%f, filename='%s', instrume='%s', obsmode='%s', detmode='%s', proposal_id='%s', filter='%s'" % \ (record[0], record[1], record[2], record[3], record[4], record[5], record[6], record[7], record[8], record[9]) insert+=",ra='%s'" % (dec2sex(record[10]/15.0)) insert+=",decl='%s'" % (dec2sex(record[11])) insert+=",filepath='%s', filesize=%f" % (makepath(filename), record[13]) print insert
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 checkInput(targetRA, targetDec, imfilter, instrument, targetRadius, maxRadius=300): "validates input to the main function" if isDecimal(targetDec): # dec is decimal if isDecimal(targetRA) == False: # check RA in same format raise BadInput, 'RA and dec appear to be in different formats' if targetDec > 0: targetDec = '+' + dec2sex(float(targetDec)) else: targetDec = dec2sex(float(targetDec)) targetRA = dec2sex(float(targetRA) / 15.0) elif isDecimal(targetRA): # RA is in decimal, but dec wasn't # pretty sure there are no valid target names which are decimals... # need to check this as decimals pass as valid sexa! raise BadInput, 'RA and dec appear to be in different formats' elif checkdms(targetDec) == True: # target already colon-seperated value # couldn't check this first as this function returns True # for decimals (for some reason), but False if space seperated sexa if checkdms(targetRA) == False: # check RA in same format raise BadInput, 'RA and dec appear to be in different formats' pass # both already in correct format elif checkdms(targetDec.replace(' ', ':')) == True: # is a valid space seperated sexa, convert to colon seperated if (checkdmsStr(targetRA.replace(' ', ':')) == False or (targetRA.replace(' ', ':') == targetRA)): # check RA works colon seperated and wasn't to start with raise BadInput, 'RA and dec appear to be in different formats' targetDec = targetDec.replace(' ', ':') targetRA = targetRA.replace(' ', ':') else: # dec isn't decimal, or space/colon seperated sexa, or blank raise BadInput, 'Format of declination not recognised, was given: ' + str( targetDec) # convert filters to those in the GSC if imfilter == "": warnings.warn('No filter specified, defaulting to V') imfilter = 'V' elif imfilter in ('j', 'F', 'V', 'N'): pass # these are the native filters in the GSC elif imfilter in ('U', "u'", 'u'): warnings.warn( 'Specified ' + imfilter + ' filter, but GSC has very little data this far blue. Falling back to photographic Bj' ) imfilter = 'j' # there IS a U field in GSC, but hardly any entries elif imfilter in ('B', "g'", 'b', 'v'): warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic Bj') imfilter = 'j' # there is also a Bmag field in GSC, but less entries elif imfilter in 'y': warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic V') imfilter = 'V' elif imfilter in ('R', "r'"): warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic F') imfilter = 'F' elif imfilter in ('I', "i'", "z'"): warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic N') imfilter = 'N' else: raise BadInput, "Filter '%s' not recognised" % str(imfilter) # check instrument input instrument = instrument.lower() if instrument == "": warnings.warn('No instrument specified, defaulting to RSS') instrument = 'rss' elif instrument in ['rss', 'pfis']: instrument = 'rss' elif instrument in ["salticam", "scam"]: warnings.warn('Selected SALTICAM; SALTICAM values not yet validated') instrument = 'scam' elif instrument == "hrs": warnings.warn('Selected HRS; HRS values not yet validated') instrument = 'hrs' else: raise BadInput, 'Instrument "' + str(instrument) + '" not recognised' # check radius if targetRadius == '': warnings.warn('No target radius specified, defaulting to 2 arcsec') targetRadius = 2. elif 0 < targetRadius < maxRadius: pass elif targetRadius > maxRadius: raise BadInput, 'Target radius ' + str( targetRadius) + ' arcsec is larger than the science FoV' else: raise BadInput, 'Target radius of ' + str( targetRadius) + 'arcsec is invalid' return (targetRA, targetDec, imfilter, instrument, targetRadius)
def checkInput(targetRA, targetDec, imfilter, instrument, targetRadius, maxRadius=300): "validates input to the main function" if isDecimal(targetDec): # dec is decimal if isDecimal(targetRA)==False: # check RA in same format raise BadInput, 'RA and dec appear to be in different formats' if targetDec>0: targetDec='+'+dec2sex(float(targetDec)) else: targetDec=dec2sex(float(targetDec)) targetRA=dec2sex(float(targetRA)/15.0) elif isDecimal(targetRA): # RA is in decimal, but dec wasn't # pretty sure there are no valid target names which are decimals... # need to check this as decimals pass as valid sexa! raise BadInput, 'RA and dec appear to be in different formats' elif checkdms(targetDec) == True: # target already colon-seperated value # couldn't check this first as this function returns True # for decimals (for some reason), but False if space seperated sexa if checkdms(targetRA) == False: # check RA in same format raise BadInput, 'RA and dec appear to be in different formats' pass # both already in correct format elif checkdms(targetDec.replace(' ',':')) == True: # is a valid space seperated sexa, convert to colon seperated if (checkdmsStr(targetRA.replace(' ',':')) == False or (targetRA.replace(' ',':')==targetRA)): # check RA works colon seperated and wasn't to start with raise BadInput, 'RA and dec appear to be in different formats' targetDec=targetDec.replace(' ',':') targetRA=targetRA.replace(' ',':') else: # dec isn't decimal, or space/colon seperated sexa, or blank raise BadInput, 'Format of declination not recognised, was given: '+str(targetDec) # convert filters to those in the GSC if imfilter == "": warnings.warn('No filter specified, defaulting to V') imfilter = 'V' elif imfilter in ('j', 'F', 'V', 'N'): pass # these are the native filters in the GSC elif imfilter in ('U', "u'", 'u'): warnings.warn('Specified '+ imfilter + ' filter, but GSC has very little data this far blue. Falling back to photographic Bj') imfilter = 'j' # there IS a U field in GSC, but hardly any entries elif imfilter in ('B', "g'", 'b', 'v'): warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic Bj') imfilter = 'j' # there is also a Bmag field in GSC, but less entries elif imfilter in 'y': warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic V') imfilter = 'V' elif imfilter in ('R', "r'"): warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic F') imfilter = 'F' elif imfilter in ('I', "i'", "z'"): warnings.warn('Specified ' + imfilter + ' filter, closest GSC band is photographic N') imfilter = 'N' else: raise BadInput, "Filter '%s' not recognised" % str(imfilter) # check instrument input instrument = instrument.lower() if instrument == "": warnings.warn('No instrument specified, defaulting to RSS') instrument = 'rss' elif instrument in ['rss','pfis']: instrument = 'rss' elif instrument in ["salticam","scam"]: warnings.warn('Selected SALTICAM; SALTICAM values not yet validated') instrument = 'scam' elif instrument == "hrs": warnings.warn('Selected HRS; HRS values not yet validated') instrument = 'hrs' else: raise BadInput, 'Instrument "' + str(instrument) + '" not recognised' # check radius if targetRadius == '': warnings.warn('No target radius specified, defaulting to 2 arcsec') targetRadius = 2. elif 0 < targetRadius < maxRadius: pass elif targetRadius > maxRadius: raise BadInput, 'Target radius '+str(targetRadius)+' arcsec is larger than the science FoV' else: raise BadInput, 'Target radius of ' + str(targetRadius) + 'arcsec is invalid' return (targetRA, targetDec, imfilter, instrument, targetRadius)