def main(options, args): if not options.srcfile: print "Please specify a --src" sys.exit(1) info = fitsutils.getFrameInfoFromPath(options.srcfile) (old_frameid, old_fitsname, old_srcdir, old_inscode, old_frametype, old_frameno) = info if not options.dstfile: print "Please specify a --dst" sys.exit(1) info = fitsutils.getFrameInfoFromPath(options.dstfile) (new_frameid, new_fitsname, new_dstdir, new_inscode, new_frametype, new_frameno) = info if new_dstdir == '': new_dstdir = '.' count = options.numframes out_f = open('/tmp/frames.txt', 'w') for i in xrange(count): # Construct new frameid newframeid = ('%3.3s%1.1s%08.8d' % (new_inscode, new_frametype, new_frameno + i)) # FITS headers to update kwdvals = { 'FRAMEID': newframeid, 'EXP-ID': newframeid, } if options.propid: kwdvals.update({'PROP-ID': options.propid}) srcpath = options.srcfile dstpath = new_dstdir + os.path.sep + newframeid + '.fits' fitsutils.update_fits(srcpath, dstpath, kwdvals) if options.daqperms: os.chmod(dstpath, 0440) out_f.write('%s\n' % newframeid) sys.stderr out_f.close()
def archive_fitsbuf(self, frameid, fitsbuf, modtime): info = getFrameInfoFromPath(frameid) if not info: raise DAQerror("Malformed frameid: '%s'" % frameid) (frameid, fitsname, fitsdir, inscode, frametype, frame_no) = info insno = self.insconfig.getNumberByCode(inscode) fitspath = ('%s/obcp%02d/%s.fits' % (self.fitsdir, insno, frameid)) if os.path.exists(fitspath): raise DAQerror("File already exists: %s" % fitspath) # Decode binary data data = ro.binary_decode(fitsbuf) try: out_f = open(fitspath, 'w') out_f.write(data) out_f.close() except IOError, e: raise DAQerror("Error saving file '%s': %s" % (fitspath, str(e)))
def _dropfifo(self, fitspath, kind): self.logger.info("Processing %-8.8s: %s" % (kind, fitspath)) # Convert to absolute file path abspath = os.path.abspath(fitspath) if not os.path.exists(abspath): raise DAQerror("Nonexistant FITS file: '%s'" % abspath) # Get frame info from fits path on disk info = getFrameInfoFromPath(abspath) if not info: raise DAQerror("Malformed FITS file path: '%s'" % abspath) (frameid, fitsname, fitsdir, inscode, frametype, frame_no) = info # Double check instrument is valid try: insno = self.insconfig.getNumberByCode(inscode) except KeyError: raise DAQerror("Frameid '%s' doesn't match a valid Subaru instrument." % \ (frameid)) # Sanity check DAQ control word kind = kind.upper().strip() if not kind in ('FLOWCTRL', 'FLOWSND', 'FLOWSAVE'): raise DAQerror("DAQ fifo message '%s' doesn't match valid types." % \ (kind)) # Pad field kind = ('%-8.8s' % kind) # Create appropriate DAQ FIFO message msg = DAQfifoMsg() # TODO: abstract and enforce checks msg.set(kind=kind, frame=frameid, host=insno, manual=' ') self.logger.debug(str(msg)) # Torpedo away! self.daqfifo_f.write(str(msg)) self.daqfifo_f.flush()
sys.stderr.write("Not a valid DAQ fifo command: '%s'" % options.kind) sys.exit(1) # For each fits file listed, generate a DAQ flow control FIFO message if options.manual: manual = _FIFO_MANUAL['first'] else: manual = _FIFO_MANUAL['neither'] while len(args) > 0: fitspath = args.pop(0) if options.manual and (len(args) == 0): manual = _FIFO_MANUAL['last'] # Separate leading directory res = fitsutils.getFrameInfoFromPath(fitspath) if not res: error("File name '%s' doesn't match a valid Subaru FITS name." % \ (fitspath)) error("Please rename the file as 'XXX{A|Q}DDDDDDDD.fits'") error("Skipping this file...") continue (frameid, fitsfile, fitsdir, inscode, frametype, frameno) = res try: insno = insconfig.getNumberByCode(inscode) except KeyError: error("File name '%s' doesn't match a valid Subaru instrument." % \ (fitsfile)) error("Skipping this file...")
def main(options, args): # Get an instrument configuration object insconfig = INSconfig() if options.check_stars: # Only import this if they are asking if file is in STARS import STARSquery for fitspath in args: # Separate leading directory res = fitsutils.getFrameInfoFromPath(fitspath) if not res: print "File name '%s' doesn't match a valid Subaru FITS name." % \ (fitspath) print "Please rename the file as 'XXX{A|Q}DDDDDDDD.fits'" print "Skipping this file..." continue (frameid, fitsfile, fitsdir, inscode, frametype, frameno) = res try: insname = insconfig.getNameByCode(inscode) except KeyError: print "File name '%s' doesn't match a valid Subaru instrument." % \ (fitsfile) print "Skipping this file..." continue if options.check_stars: print "Checking if frame %s is in STARS..." % frameid if STARSquery.GetStarsInfoForFitsID(frameid): print "Frame %s IS in STARS!" % frameid print "Skipping this file..." continue # Look up the instrument number and figure out the path where # the file should end up insnum = insconfig.getNumberByCode(inscode) obcInstrPath = '/mdata/fits/obcp%2d' % insnum obcIndexPath = '/mdata/index' indexfile = frameid + '.index' # Get some metadata by reading the file (if necessary) metadata = {} get_fits_metadata(metadata, fitspath=fitspath, use_mtime=not options.use_ctime) # Substitute path where file should end up metadata['fitspath'] = obcInstrPath + '/' + fitsfile metadata['indexpath'] = obcIndexPath + '/' + indexfile indexpath = options.indexdir + '/' + indexfile # Make the index file if options.create_index: print "Creating index file for %s fits file '%s'..." % \ (insname, fitsfile) create_index_file(metadata, indexpath=indexpath) if options.copy_mdata: # chmod 440 fitspath--what DAQ expects try: os.chmod(fitspath, 0440) except OSError, e: print "Error chmod on '%s': %s" % (fitsfile, str(e)) # FITS file dstpath = obcInstrPath + '/' + fitsfile sshcmd = "ssh [email protected] ls -ld %s" % dstpath res = os.system(sshcmd) if res != 512: print "File may already exist: %s" % dstpath print "Skipping file transfer..." else: scpcmd = "scp -p %s [email protected]:%s" % (fitspath, dstpath) print scpcmd res = 0 res = os.system(scpcmd) if res != 0: print "Error code transferring file: %d" % res # Index file dstpath = obcIndexPath + '/' + indexfile sshcmd = "ssh [email protected] ls -ld %s" % dstpath res = os.system(sshcmd) if res != 512: print "File may already exist: %s" % dstpath print "Skipping file transfer..." else: scpcmd = "scp -p %s [email protected]:%s" % (indexpath, dstpath) print scpcmd res = 0 res = os.system(scpcmd) if res != 0: print "Error code transferring file: %d" % res if options.insert_flowqueue: sshcmd = "ssh [email protected] /soss/SRC/TOOL/bin/DAQobcQueueInsert %s 10000000 -y" % frameid res = 0 print sshcmd res = os.system(sshcmd) if res != 0: print "May have been problem with DAQobcQueueInsert"
def main(options, args): logname = 'least_sq' logger = ssdlog.make_logger(logname, options) # make an instance of LeastSquareFits before importing getFrameInfoFromPath # otherwise, some pyfits error is caused. lsf = curvefit.LeastSquareFits(logger) focusfit = CurveFitGraph(logger, lsf) if not options.fitsdir: logger.error("No --fitsdir given!") sys.exit(1) if not options.startframe: logger.error("No --startframe given!") sys.exit(1) # Get the starting frame (frameid, fitsname, fitsdir, inscode, frametype, frame_no) = fitsutils.getFrameInfoFromPath(options.startframe) st_fnum = frame_no # We'd better have an --endframe or a --numframes if options.endframe: (frameid, fitsname, fitsdir, inscode, frametype, frame_no) = fitsutils.getFrameInfoFromPath(options.endframe) en_fnum = frame_no elif options.numframes: en_fnum = st_fnum + options.numframes else: logger.error("No --endframe or --numframes given!") sys.exit(1) if options.region: region = options.region.split(',') logger.debug("frame region<%s> " % region) x1 = region[0].strip() y1 = region[1].strip() x2 = region[2].strip() y2 = region[3].strip() x1 = int(x1[3:]) y1 = int(y1[3:]) x2 = int(x2[3:]) y2 = int(y2[3:]) logger.debug("frame region x1<%s> y1<%s> x2<%s> y2<%s> " % (x1, y1, x2, y2)) else: x1 = y1 = x2 = y2 = None if options.cutout: cutout = options.cutout logger.debug("cutout image <%s> " % cutout) else: cutout = None # Calculate the frame list framelist = [ "%s%s%08d" % (inscode, frametype, i) \ for i in range(st_fnum, en_fnum) ] logger.debug("framelist=%s" % str(framelist)) try: gtk.gdk.threads_init() focusfit.set_title('focus fitting test') file_list = lsf.make_file_list(options.fitsdir, framelist) z = focusfit.focus_fitting(file_list, x1, y1, x2, y2) logger.debug('z=%s' % str(z)) focusfit.mainloop() except KeyboardInterrupt, e: logger.error('Caught keyboard interrupt!')
startframe = 1354880 with open('frames.txt', 'r') as in_f: buf = in_f.read() lines = buf.split('\n') framecount = startframe for frameid in lines: if len(frameid) == 0: continue if frameid.startswith('#'): continue path = os.path.join(fromdir, frameid + '.fits') tup = fitsutils.getFrameInfoFromPath(path) (frameid, fitsname, fitsdir, inscode, frametype, frame_no) = tup expid = int(str(framecount)[:-1] + '0') newframeid = "%3.3s%1.1s%08d" % (inscode, frametype, framecount) updateDict = { 'FRAMEID': newframeid, 'EXP-ID': "%3.3sE%08d" % (inscode, expid), } newpath = os.path.join(todir, newframeid + '.fits') print "updating old(%s) new(%s) dict=%s" % (path, newpath, updateDict) fitsobj = pyfits.open(path, 'readonly') try: for hdu in fitsobj: