def run(crdFormat, aor_crd, filetype, r, rIn, rOut, ap_corr, channel, pixLen, rejection = True): #initializing table to hold results result = Table(names = ('AORKEY', 'Target RA', 'Target Dec', 'DateObs', 'Mission', 'Read Mode', 'Workable/Total Files in AOR', 'Cycling DPattern', 'DScale', 'DPosition', 'FTime (sec)', 'Time (MJD)', 'Flux (mJy)', 'Error (mJy)', 'Spread (%)', 'Outliers Rejected'), dtype = ('i4', 'f8', 'f8', 'S25', 'S5', 'S5', 'S10', 'S5', 'S10', 'S5', 'f8', 'f8', 'f8', 'f8', 'f8', 'i4')) problem = [] #Putting coordinates and filepaths in the correct format #........................................................ if crdFormat.lower() == 'single_hms': AORs = glob.glob(aor_crd[0]) skyList = [SkyCoord(aor_crd[1], unit=(u.hourangle, u.deg))]*len(AORs) aorList = [glob.glob(aor + '/ch%i/bcd/*_%s.fits' % (channel, filetype)) for aor in AORs] elif crdFormat.lower() == 'single_deg': AORs = glob.glob(aor_crd[0]) skyList = [SkyCoord(aor_crd[1], unit=u.deg)]*len(AORs) aorList = [glob.glob(aor + '/ch%i/bcd/*_%s.fits' % (channel, filetype)) for aor in AORs] elif crdFormat.lower() == 'multiple_hms': skyTable = ascii.read(aor_crd) AORs = skyTable['AOR Filepath'] skyList = [SkyCoord(st, unit=(u.hourangle, u.deg)) for st in skyTable['Target Coordinates']] aorList = [glob.glob(aor + '/ch%i/bcd/*_%s.fits' % (channel, filetype)) for aor in AORs] elif crdFormat.lower() == 'multiple_deg': skyTable = ascii.read(aor_crd) AORs = skyTable['AOR Filepath'] skyList = [SkyCoord(st, unit=u.deg) for st in skyTable['Target Coordinates']] aorList = [glob.glob(aor + '/ch%i/bcd/*_%s.fits' % (channel, filetype)) for aor in AORs] else: print('Please input one of these 4 values for crdFormat: single_hms, single_deg, multiple_hms, multiple_deg') return #.......................................................... counter = 0 #Generate data for each aor for i, (aor, sky) in tqdm(enumerate(zip(aorList, skyList))): #Performing photometry on every image in an AOR= if len(aor)>0: data, header = func.single_target_phot(aor, sky, r, rIn, rOut) counter += 1 else: problem.append(AORs[i].split('/r')[1]) print('Empty AOR encountered: %s' % AORs[i].split('/r')[1]) continue #Cumulating all the data tables from every aor if counter==1: cum_data = data else: cum_data = vstack([cum_data, data]) #Getting relevant information from data table Xc = data['Xc'][np.isnan(np.array(data['Xc']).astype('Float64')) == False] Yc = data['Yc'][np.isnan(np.array(data['Yc']).astype('Float64')) == False] Res_Flux = data['Res_Flux'][np.isnan(np.array(data['Res_Flux']).astype('Float64')) == False] #Defining every table element except for flux terms #.................................................. aKey = header['AORKEY'] #AORKEY dObs = header['DATE_OBS'] #Date of observation in UT dPat = 'YES' if 'cycl'in header['AORLABEL'] else 'NO' #Dither pattern fTim = header['FRAMTIME'] #frame time in sec time = header['MJD_OBS'] #Date of observation in MJD mssn = 'CRYO' if (time<=54968) else 'WARM' #Spitzer mission mode = header['READMODE'] #Readout mode: full or sub fLen = '%i/%i' % (len(Res_Flux), len(aor)) #workable file/total file tRA = sky.ra.deg #Target RA tDEC = sky.dec.deg try: dScl = header['DITHSCAL'] #Dither scale: small, medium or large except KeyError: dScl = '--' try: dPos = str(header['DITHPOS']) #Dither position except KeyError: dPos = '--' #................................................... #Using IDL to remove systematics #................................ if len(Res_Flux) > 0: idl.setVariable('cenX', Xc) idl.setVariable('cenY', Yc) idl.setVariable('obsFlux', Res_Flux) idl.setVariable('ch', channel) if mode == 'SUB': if mssn == 'CRYO': idl.execute('corFlux = IRAC_APHOT_CORR(obsFlux, cenX, cenY, ch, /CRYO, /SUBARRAY)') else: idl.execute('corFlux = IRAC_APHOT_CORR(obsFlux, cenX, cenY, ch, /SUBARRAY)') else: if mssn =='CRYO': idl.execute('corFlux = IRAC_APHOT_CORR(obsFlux, cenX, cenY, ch, /CRYO)') else: idl.execute('corFlux = IRAC_APHOT_CORR(obsFlux, cenX, cenY, ch)') corFlux = idl.getVariable('corFlux') corFlux = np.array([corFlux]) if type(corFlux)==float else np.array(corFlux).astype('Float64') else: problem.append(aKey) result.add_row([aKey, tRA, tDEC, dObs, mssn, mode, fLen, dPat, dScl, dPos, fTim, time, np.nan, np.nan, np.nan, 0]) continue #................................. #Rejecting Outliers #................... sig = (np.std(corFlux)/np.std(corFlux))*100 if (rejection == False) | (len(corFlux)<=10) | (sig<2): refFlux = corFlux else: refFlux = np.delete(corFlux, [np.argmin(corFlux), np.argmax(corFlux)]) clipped = len(corFlux) - len(refFlux) #................... #Final Flux calculations #........................ #applying aperture correction flux_bUnit = refFlux*ap_corr #Flux in bad units (MJy/Sr)! #Fluxes in proper units (mJy) pixArea = (pixLen**2)/(206265**2) #Steradian flux_arr = flux_bUnit*(pixArea*(10**9)) #Analysis flux = np.mean(flux_arr) error = np.std(flux_arr) spread = (error/flux)*100 #........................ result.add_row([aKey, tRA, tDEC, dObs, mssn, mode, fLen, dPat, dScl, dPos, fTim, time, flux, error, spread, clipped]) return result, cum_data, problem
#更改当前工作目录 #'/Applications/exelis/idl82/bin/bin.darwin.x86_64/libXm.3.0.2.dylib' os.chdir('/Applications/exelis/idl82/bin/bin.darwin.x86_64/') os.getcwd() # Import mirpyidl. import mirpyidl as idl import numpy as np # Execute a command in IDL. # This will print 'Hello mom!' from IDL. idl.execute("PRINT, 'Hello mom!'") # Create a numpy array in python. py_array = np.random.normal(size=1000) # Copy this data to IDL. idl.setVariable('idl_array', py_array) # Calculate the standard devation and the mean in IDL. idl.execute('idl_stddev = STDDEV(idl_array)') idl.execute('idl_mean = MEAN(idl_array)') # Copy the results back to python. py_stddev = idl.getVariable('idl_stddev') py_mean = idl.getVariable('idl_mean') # Print out the results. print('Mean: {}, StdDev: {}'.format(py_mean, py_stddev)) # endregion