def rd_dqc(infile=None, debug=None): """ read the dqc file """ print('dqc: ', infile) if not os.path.exists(infile): print(infile, 'does not exist') print('Exiting') sys.exit(0) # open catalogue file handle fh = pyfits.open(infile) data = fh[1].data print('Number of rows: ', len(data)) #help(data) if debug: table_stats(infile) #data['ra']=np.degrees(data['ra']) #data['dec']=np.degrees(data['dec']) return data
result.write('results1.fits', overwrite=True) sys.exit() # extract the project ID from the file project = [] # table = ascii.read(infile, header_start=0, data_start=1) # print() # print(table[0]) # table = Table.read(infile) table_stats('sources.fits', debug=False) alma.info() alma.info('stats') Image_SourceStats(alma, filename=infile, verbose=False) print(len(alma), 'Sources') SourceStats(alma, verbose=False) # limit to source with CUNIT3 == 'Hz' and CTYPE3 == 'FREQ' itest = (alma['CTYPE3'] == 'FREQ') & (alma['NAXIS3'] == 1) alma = alma[itest] print('Number of sources with CTYPE3 = FREQ:', len(alma)) SourceStats(alma, verbose=False) key=raw_input("Enter any key to continue: ")
logdata = "Delete lockfile %s " % lockfile logger(flog, logdata) logger(flogerr, logdata) os.remove(lockfile) continue else: logdata = "imcore_list Finished" logger(flog, logdata) hdulist = pyfits.open(outfile) logdata = "Number of extensions: %d " % len(hdulist) logger(flog, logdata) n_ext = len(hdulist) for ext in range(1, n_ext): table_stats(outfile, ext=ext) print "listdriven photometry completed" # key=raw_input("Enter any key to continue: ") print "Deleting data files used" if os.path.exists(imagefile): print "Remove the image file:" + imagefile cmd = "rm -v " + imagefile try: result = os.popen(cmd) except OSError as (errno, strerror): logdata = "OS error({0}): {1}".format(errno, strerror) logger(flogerr, logdata) logdata = "error removing imagefile %s " % imagefile logger(flogerr, logdata)
def imcore_list_run(args=None, imagefile=None, confmapfile=None, listfile=None, outfile=None): """ runs imcore_list using subprocess """ # set the imcorelist parameters; maybe need to check these againsts # values in the header of the catalogue file nustep=-1 print('args.vhs: ', args.vhs) print('args.cache: ', args.cache) if not args.vhs: nustep=pyfits.getval(imagefile,'NUSTEP',0) print('nustep = ', nustep) if args.vhs: rcore = "3.0" nbsize = "64" threshold = "1.5" # UKIDSS values if (nustep==1): rcore = "2.5" nbsize = "64" threshold = "1.5" elif (nustep==4): # i.e., 2x2 rcore = "5.0" nbsize = "128" threshold = "1.25" elif (nustep==9): # i.e., 3x3 rcore = "7.5" nbsize = "192" threshold = "1.25" print('rcore, nbsize, threshold: ', rcore, nbsize, threshold) # needs the binary location to be a parameter for portability #command = 'time nice -n19 ' + IMCORE_LIST \ command = 'time nice -n19 /home/rgm/bin/imcore_list ' \ + ' ' + imagefile \ + ' ' + confmapfile \ + ' ' + listfile \ + ' ' + outfile \ + ' ' + threshold \ + ' --nbsize=' + nbsize \ + ' --rcore=' + rcore \ + ' --cattype=6 ' # + ' --verbose ' # save stdout and stderr to a logfile stdoutlog = open(logpath+'Logfile_stdout', 'w+') stderrlog = open(logpath+'Logfile_stderr', 'w+') logdata=command logger(flog, logdata) # convert comamd to string list for subprocess command = shlex.split(command) print('Print command as args: ') print(command) result = subprocess.call(command, \ stderr=stderrlog, stdout=stdoutlog) Popen=False if Popen: result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print('Using subprocess.Popen and communicate') output, errors = result.communicate() result=subprocess.check_output(command) #help(result) print('subprocesss output: ', output) print('subprocess errors: ', errors) #logdata='subprocess error status: ' + str(result) #logger(flog, logdata) trace = traceback.extract_stack()[-1] print(os.path.basename(trace[0]), ' line :', str(trace[1])) #if result is not 0: print(len(result)) #print(result) result=0 if result is not 0: print(result) trace = traceback.extract_stack()[-1] print(os.path.basename(trace[0]), ' line :', str(trace[1])) print('Something went wrong: ', args) logger(flogerr, logdata) logdata = 'Something went wrong: ' + command logger(flogerr, logdata) logger(flogerr, line_save) logger(flogerr, command) while True: line = result.readline() if line == "": break logdata = line logger(flog, logdata) print(line,) if debug: key=raw_input("Enter any key to continue: ") # delete the outfile if created if os.path.exists(outfile): logdata = "Delete %s " % outfile logger(flog, logdata) logger(flogerr, logdata) os.remove(outfile) if os.path.exists(lockfile): logdata = "Delete lockfile %s " % lockfile logger(flog, logdata) logger(flogerr, logdata) os.remove(lockfile) #continue usage = resource.getrusage(resource.RUSAGE_CHILD) for name, desc in [ ('ru_utime', 'User time'), ('ru_stime', 'System time'), ]: print('%-25s (%-10s) = %s' % (desc, name, getattr(usage, name))) else: logdata='imcore_list Finished' logger(flog, logdata) print('Read back the results and check integrity: ', outfile) if not os.path.exists(outfile): print('File does not exist: ', outfile) try: hdulist = pyfits.open(outfile) except: traceback.print_exc(file=sys.stdout) logdata= 'Number of extensions: %d ' % len(hdulist) logger(flog, logdata) n_ext=len(hdulist) for ext in range(1, n_ext): table_stats(outfile, ext=ext) print('listdriven photometry completed')
debug = False verbose = False inpath = '/data/vhs/dqc/vsa/2014/VHSv20140409/' filename = 'vhs_vsa_dqc_tiles_fs_metadata.fits' dqcfile = inpath + filename print('Elpased time: %.2f seconds' % (time.time() - t0)) print('Get table stats: ', dqcfile) dqc = libdqc.rd_dqc(infile=dqcfile) table_stats(dqcfile) print('Elpased time: %.2f seconds' % (time.time() - t0)) #libdqc.dqc_stats(dqc=dqc) test = False if test: test = (data['nite'] >= '20120901') & (data['nite'] <= '20130401') data = data[test] interactive = True showplots = True t0 = time.time()
debug=False verbose=False inpath= '/data/vhs/dqc/vsa/2014/VHSv20140409/' filename= 'vhs_vsa_dqc_tiles_fs_metadata.fits' dqcfile= inpath + filename print('Elpased time: %.2f seconds' %(time.time() - t0)) print('Get table stats: ', dqcfile) dqc = libdqc.rd_dqc(infile=dqcfile) table_stats(dqcfile) print('Elpased time: %.2f seconds' %(time.time() - t0)) #libdqc.dqc_stats(dqc=dqc) test=False if test: test = (data['nite'] >= '20120901') & (data['nite'] <= '20130401') data=data[test] interactive=True showplots=True