def udb_process_1spec(ufb_1_in, antlist, reprocess=False): '''This process inputs a single UFDB entry, creates a FITS file, then spawns an IDL process to make summary plots''' #string may be a list if isinstance(ufb_1_in, list): ufb = ufb_1_in[0] else: ufb = ufb_1_in #end else #If I am here, I have a valid ufb, but do I have status = 0, If #so, process it. if ufb.pstatus == 0: do_this_file = 1 else: do_this_file = -1 #end else #if do_this_file is -1, then no processing happens #check for reprocess if reprocess == True: idlfile = "/home/user/workdir/udb_reprocess_spec.pro" else: idlfile = "/home/user/workdir/udb_process_spec.pro" #endelse if do_this_file == -1: print "UDB_PROCESS_1SPEC: no data to process" print 'UDB_PROCESS_1SPEC: finished successfully' sys.stdout.flush() ufb_out = [] f = open(idlfile, 'w') s = "pr_path_lib, 'eovsa_write_pwrfits', /multi\n" f.write(s) s = "message, /info, 'No data to process'\n" f.write(s) s = "end\n" f.write(s) f.close return ufb_out #endif ufileid = ufb.fileid uprojectid = ufb.projectid uantlist = antlist print 'UDB_PROCESS_1SPEC - Antlist: ', uantlist yyyy = ufileid[3:7] print 'UDB_PROCESS_1SPEC - Processing: ', ufileid sys.stdout.flush() # Check for YYYY directories if os.path.isdir(udbdir + yyyy) != True: os.mkdir(udbdir + yyyy) if os.path.isdir(udbtxtdir + yyyy) != True: os.mkdir(udbtxtdir + yyyy) ufilename = udbdir + yyyy + '/' + ufileid # write a fits file, ignoring tpcal for the moment print ufilename sys.stdout.flush() udat = dump_tsys_ext.rd_miriad_tsys_file(ufilename) if udat == None: print "UDB_PROCESS_1SPEC: Bad Miriad Dataset (2):" print ufilename sys.stdout.flush() ufb_out = [] return ufb_out #endif calflag = False ufile_out = dump_tsys_ext.tsys_writeudbfits(udat, calflag) if len(ufile_out) == 0: print "UDB_PROCESS_1SPEC: write failed:" print filelist[0] sys.stdout.flush() return [] #endif # Here figure out how to call the IDL process from here, write a # batch file and run ssw_batch using the subprocess command # 2014-06-26. Instead, just create the batch file and we will run # ssw_batch directly from the shell script # 2014-12-15 added projectid to eovsa_write_pwrfits.pro call # 2016-04-19 The fits file already has been written, so just plot it if reprocess == True: idlfile = "/home/user/workdir/udb_reprocess_spec.pro" else: idlfile = "/home/user/workdir/udb_process_spec.pro" #endelse f = open(idlfile, 'w') s = "pr_path_lib, 'eovsa_write_pwrfits', /multi\n" f.write(s) s = "fitsfile = '" + ufile_out + "'\n" f.write(s) s = "eovsa_plot_tpower_fits, fitsfile\n" f.write(s) s = "end\n" f.write(s) f.close() ufb.pstatus = 1 ufb_out = [ufb] print 'UDB_PROCESS_1SPEC: Processed Spectra for: ' + ufileid print 'UDB_PROCESS_1SPEC: finished successfully' sys.stdout.flush() return ufb_out
def process_1ifb(ifb0): '''Creates an IDB fits file for the input ifb entry, and copies the IDB Miriad file to the local disk. Added antennalist output 2015-01-06, jmm''' #ifb0 may be a list if isinstance(ifb0, list): ifb = ifb0[0] else: ifb = ifb0 #end else filelist = [idbdir + ifb.fileid] #Check validity file_test = dump_tsys_ext.valid_miriad_dataset(filelist) if len(file_test) == 0 or file_test[0] == False: print "process_1ifb: Bad Miriad Dataset:" print filelist[0] return '', '' #endif #If you are here you have a good IDB dataset, error check anyway xdat = dump_tsys_ext.rd_miriad_tsys_file(filelist) if xdat == None: print "process_1ifb: Bad Miriad Dataset (2):" print filelist[0] return '', '' #endif #Hold onto antennalist for output antlist = xdat['antennalist'] #Calibrate, but only for normal observing, No calibration sid = ifb.sourceid[:3] prid = ifb.projectid[:15] calflag = False # if sid == "Sun" and prid == "NormalObserving": # t1 = Time(xdat['ut_mjd'][0],format='mjd') # fghz, calfac, offsun = calibration.sp_read_calfac(t1) # if fghz != None: # xdat = calibration.sp_apply_cal(xdat, fghz, calfac, offsun) # calflag = True # else: # calflag = False # #endif # else: #endif #write the file print "CALFLAG", calflag file_out = dump_tsys_ext.tsys_writetofits(xdat, calflag) if len(file_out) == 0: print "process_1ifb: write failed:" print filelist[0] return file_out, '' #endif #copy the IDB dataset from /dppdata1/IDB to /data1/eovsa/fits/IDB/yyyymmdd filename = filelist[0] yyyymmdd = filename[len(filename) - 14:len(filename) - 6] outdir = idbfinaldir + yyyymmdd if os.path.isdir(outdir) != True: os.mkdir(outdir) #end if full_filename = outdir + '/' + ifb.fileid #If the file exists, you need to delete it before using shutil.copytree if os.path.isdir(full_filename) == True: print "process_1ifb: dataset: ", full_filename, " will be overwritten" shutil.rmtree(full_filename) #end if shutil.copytree(filename, full_filename) #the second output is passed into udb_fitsfile return file_out, antlist