def processCommands(self): try: optlist, args = getopt(self.argv[1:], "c:m:h", ['color=', 'method=', 'scale=', 'help']) except GetoptError: printError('Invalid command line options') return for o, a in optlist: if a[:1] == ':': a = a[1:] elif o == '-m' or o == '--method': if not a in Colorize.scaleMethods: printError("Invalid scaling method value: %s" % (a)) self.opt['scaleMethod'] = a elif o == '--scale': self.opt['scaling'] = float(a) elif o == '-c' or o == '--color': if a in ['Gi', 'Bi', 'Ri']: self.opt['color'] = a else: print( "Invalid color code %s. Available color codes are: Gi, Bi, Ri" ) elif o == '-h' or o == '--help': self.usage() exit(0) self.opt['baseFolder'] = args[0] if self.opt['baseFolder'].endswith('/'): self.opt['baseFolder'] = args[0][:-1] print("scaling method: %s" % (self.opt['scaleMethod']))
def process_photometry(self, seqFolder, photFolder, title): printInfo("%s: Make photometry on sequence file(s)." % (title)) # Create the photometry dir, if not exists if not exists(photFolder): mkdir(photFolder) # Photometry reference file: sf = seqFolder basedir = sf.replace(self.pplSetup['SEQ_FOLDER_NAME'], '') PMREFS = glob(basedir + '/*.cat') if len(PMREFS) > 0 and exists(PMREFS[0]): PMREF = PMREFS[0] else: printError("No reference catalog file (.cat) in folder %s" % (basedir)) printInfo( "Use ppl-refcat command to create reference catalog for the object." ) return False for color in self.opt['color']: self.photometry(seqFolder, photFolder, PMREF, color) self.calculateMags(photFolder, self.opt['color']) # TODO: cleanup - delete light FITS files return True
def invoked(self, cmd): if self.opt['debug']: printDebug(cmd) result = invoke(cmd) if result.startswith('ERROR:'): printError(result[len('ERROR: '):]) elif self.opt['debug']: printDebug(result) return result
def calculateMgsLinearFit(self, refCat, color, bestCompId): ''' Calculate magnitudes with naive linear fit ''' # TODO: calculate comp mag error stdcolor = self.stdColor(color) mvPos = getHeaderPos(refCat, 'MAG_' + stdcolor) miPos = getHeaderPos(refCat, fieldMgInstrumental) evPos = getHeaderPos(refCat, 'ERR_' + stdcolor) eiPos = getHeaderPos(refCat, fieldMgErrInstrumental) rolePos = getHeaderPos(refCat, fieldRole) bestComp = self.findRow(refCat['cat'], bestCompId) bestComp[rolePos] = 'K' # TODO mi = [] mv = [] er = [] # p = [1.0, 0.0] ep = 0.0 N = 0 for pm in refCat['cat']: if pm[rolePos] == 'C' and pm[mvPos] != '-': mi.append(float(pm[miPos])) mv.append(float(pm[mvPos])) ei = float(pm[eiPos]) ev = float(pm[evPos] ) if pm[evPos] != '-' and pm[evPos] != '0.0' else ei e2 = ei * ei + ev * ev ep = ep + e2 N = N + 1 er.append(1.0 / e2) if len(mi) < 2: pm.printError("Not enough comp stars for linear fit ensemble") return [] # p = Polynomial.fit(mi, mv, 1, w = er) coef = pm.linfit(mi, mv, er) ep = np.sqrt(ep / float(N)) print('polyfit result:', coef, 'error:', ep) if self.opt['showGraphs']: plotcolor = color[0].lower() plt.subplot(311 + self.opt['color'].index(color)) xr = arange(min(mi), max(mi), 0.01) plt.plot(mi, mv, plotcolor + 'o', xr, coef[0] * xr + coef[1], 'k') plt.xlabel(color) plt.ylabel(stdcolor) return coef, ep
def findBestCompStar(self, allCatalogs, color): refCat = allCatalogs[color] stdcolor = self.stdColor(color) idPos = getHeaderPos(refCat, fieldAuid) eiPos = getHeaderPos(refCat, fieldMgErrInstrumental) rolePos = getHeaderPos(refCat, fieldRole) mvPosList = {} evPosList = {} for c in self.opt['color']: mvPosList[c] = getHeaderPos(refCat, 'MAG_' + self.stdColor(c)) evPosList[c] = getHeaderPos(refCat, 'ERR_' + self.stdColor(c)) emin = 1.0 bestComp = None for pms in refCat['cat']: mvs = pms[mvPosList[color]] evs = pms[evPosList[color]] if pms[rolePos] == 'C' and mvs != '-': ei = float( pms[eiPos]) if pms[eiPos] != '-' else MAG_ERR_DEFAULT ev = float(evs) if evs != '-' and evs != '0.0' else ei e = ei * ei + ev * ev if e < emin: haveAllMags = True for c in self.opt['color']: if c != color: if pms[mvPosList[c]] == '-' or pms[ evPosList[c]] == '-': haveAllMags = False break if not haveAllMags: continue emin = e bestComp = pms if bestComp: ei = float( bestComp[eiPos]) if bestComp[eiPos] != '-' else MAG_ERR_DEFAULT ev = float(bestComp[evPosList[color]]) if bestComp[ evPosList[color]] != '-' else MAG_ERR_DEFAULT e = pm.quad(ei, ev) bestComp[rolePos] = 'K' print('Best comp star: %s, mag: %s, err: %4.3f' % (bestComp[idPos], bestComp[mvPosList[color]], e)) return bestComp[idPos] else: pm.printError( 'No usable comp star found ; check the comp stars if they exist in all colors you need' ) return None
def processCommands(self): try: optlist, args = getopt(self.argv[1:], "u:h", ['use=', 'help']) except GetoptError: printError('Invalid command line options') return for o, a in optlist: if a[:1] == ':': a = a[1:] if o == '-u' or '--use': self.opt['use'] = a elif o == '-h' or o == '--help': self.usage() exit(0) self.opt['fileName'] = args[0]
def processCommands(self): try: optlist, args = getopt( argv[1:], "c:smo:p:", ['color=', 'std', 'make-std', 'out=', 'comp=']) except GetoptError: pm.printError('Invalid command line options') return for o, a in optlist: if a[:1] == ':': a = a[1:] elif o == '-c' or o == '--color': self.opt['color'] = [a] elif o == '-s' or o == '--std': self.opt['std'] = True elif o == '-m' or o == '--make-std': self.opt['makestd'] = True elif o == '-p' or o == '--comp': self.opt['comp'] = a elif o == '-o' or o == '--': self.opt['out'] = a self.opt['files'] = args
def createImage(self, baseFolder, colors): rgb = [] seqFolder = self.pplSetup['SEQ_FOLDER_NAME'] # TODO: before addition, images should be reregistered with Gi as reference, for more exact alignment imgFileName = "%s/%s.jpg" % (baseFolder, baseFolder.split('/')[-1]) for c in colors: fitsFileName = "%s/%s/Combined-%s.fits" % (baseFolder, seqFolder, c) print("%s color source image: %s" % (c, fitsFileName)) if not exists(fitsFileName): printError("image file %s not exists." % (fitsFileName)) return rgb.append(fits.open(fitsFileName)[0].data) img = np.zeros((rgb[1].shape[0], rgb[1].shape[1], 3), dtype=float) # TODO: with log method, save is failed: Floating point image RGB values must be in the 0..1 range. # need some normalization try: self.doSubtractBackground(rgb) self.doScaling(img, rgb) self.saveImage(img, imgFileName) except ValueError as e: printError( "creating color image with %s scaling mathod is failed: %s" % (self.SCALE_METHOD, str(e))) if self.SCALE_METHOD != self.scaleMethods[0]: self.SCALE_METHOD = self.scaleMethods[0] try: self.doScaling(img, rgb) self.saveImage(img, imgFileName) except ValueError as ex: printError( "creating color image with alternative %s scaling mathod is failed: %s" % (self.SCALE_METHOD, str(ex))) return
def photometry(self, seqFolder, photFolder, refcatFileName, color): # Names of the sequence/combined files: SEQLIST = glob(seqFolder + '/' + self.pplSetup['SEQ_FILE_PREFIX'] + '*-' + color + '.fits') SEQLIST.sort() if len(SEQLIST) == 0: SEQLIST = glob(seqFolder + '/Combined-' + color + '.fits') if len(SEQLIST) == 0: printWarning("No files for photometry in folder %s" % (seqFolder)) return False for f in SEQLIST: print("photometry of %s" % (f)) AST_FILE = photFolder + '/' + basename(f).replace( '.fits', '.ast.fits') PMCAT_FILE = photFolder + '/' + basename(f).replace( '.fits', '.cat') printInfo("Make astrometry for %s" % (f)) if not exists(AST_FILE) or self.opt['overwrite']: print("%s/solve-field %s -D %s -N %s %s" % (self.pplSetup['AST_BIN_FOLDER'], self.SOLVE_ARGS, photFolder, AST_FILE, f)) invoke("%s/solve-field %s -D %s -N %s %s" % (self.pplSetup['AST_BIN_FOLDER'], self.SOLVE_ARGS, photFolder, AST_FILE, f)) fsolved = PMCAT_FILE.replace('.cat', '.solved') if not exists(fsolved): printError("Astrometry of %s failed." % (fsolved)) break else: print("astrometry file %s already exists." % (AST_FILE)) printInfo("Make photometry for %s" % (f)) if not exists(PMCAT_FILE) or self.opt['overwrite']: invoke( "sextractor %s -c %s -CATALOG_NAME %s -CATALOG_TYPE ASCII_HEAD" % (AST_FILE, self.SEX_CFG, PMCAT_FILE)) else: print("photometry file %s already exists." % (PMCAT_FILE)) PMCAT_FILE_FLT = PMCAT_FILE + ".cat" printInfo("Filtering result catalog to %s" % (PMCAT_FILE_FLT)) if not exists(PMCAT_FILE_FLT) or self.opt['overwrite']: opt = { 'ref': refcatFileName, 'out': PMCAT_FILE_FLT, 'color': color, 'files': [PMCAT_FILE], } matcher = CatalogMatcher(opt) matcher.process() else: print("filtered photometry file %s already exists." % (PMCAT_FILE_FLT)) return True
def processCommands(self): try: optlist, args = getopt (argv[1:], "ac:s:o:n:i:f:rl:wh", ['all', 'coord=', 'source=', 'object=', 'field-name=', 'image=', 'field=', 'field-stars', 'limit=', 'overwrite', 'help']) except GetoptError: print ('Invalid command line options') exit(1) fieldStarsIndicated = False for o, a in optlist: if a[:1] == ':': a = a[1:] elif o == '-c' or o == '--coord': self.opt['coords'] = a elif o == '-s' or o == '--source': self.opt['source'] = a fieldStarsIndicated = True elif o == '-o' or o == '--object': self.opt['object'] = a.replace('_', ' ') elif o == '-n' or o == '--field-name': self.opt['stdFieldName'] = a elif o == '-i' or o == '--image': self.opt['image'] = a elif o == '-f' or o == '--field': if a.isdigit(): self.opt['field'] = int(a) else: printError("Invalid field size parameter: %s. Use default 60 arcmin instead." % (a)) elif o == '-a' or o == '--all': self.opt['auidOnly'] = False elif o == '-r' or o == '--field-stars': self.opt['fieldStars'] = True elif o == '-l' or o == '--limit': err = False if a.isfloat(): ml = float(a) if ml > 0.0 or ml <= 25.0: self.opt['mgLimit'] = float(a) else: err = True else: err = True if err: printError("Invalid mg limit: %s. Use default instead." % (a)) fieldStarsIndicated = True elif o == '-w' or o == '--overwrite': self.opt['overwrite'] = True elif o == '-h' or o == '--help': self.usage() exit(0) if len(args) > 0: if not isdir(args[0]): printError('%s is not a folder.' % (args[0])) exit(1) self.opt['folder'] = args[0] if not self.opt['folder'].endswith('/'): self.opt['folder'] += '/' if self.opt['object'] == None and self.opt['coords'] == None and self.opt['stdFieldName'] == None and self.opt['image'] == None: printError("Either object name (-o), coordinates (-c), standard field name (-n) or image file (-i) must be given.") exit(1) if self.opt['coords'] != None: c = self.opt['coords'].split(',', maxsplit = 2) ok = True if len(c) != 2: ok = False else: if re.fullmatch("(\d){2}:(\d){2}:(\d){2}(\.\d)*", c[0]) == None: ok = False if re.fullmatch("[+-]*(\d){2}:(\d){2}:(\d){2}(\.\d)*", c[1]) == None: ok = False if not ok: printError("Invalid coordinate format") exit(1) self.opt['ra'] = hexa2deg(c[0]) * 15.0 self.opt['dec'] = hexa2deg(c[1]) if not self.opt['fieldStars'] and fieldStarsIndicated: printError("Options -s or -l indicates collecting field stars, but -r option was not given. These options will be ignored.")
def loadStdFieldData(self, stdFieldName): saName = self.opt['stdFieldName'] configFolder = self.ppl["CONFIG_FOLDER"] if configFolder == None: configFolder = "$HOME/.pmlib" # load stdArea file saFieldsFile = configFolder + "/landolt_fields.txt" if not exists(saFieldsFile): printError("Landolt standard field catalog file %s not found" % (saFieldsFile)) return 'NoFile' saFields = Table.read(saFieldsFile, format = 'ascii') # find std area rows = list(filter(lambda r: r['FIELD_NAME'] == saName, saFields)) if len(rows) == 0: printError("No field name %s found in standard area file %s." % (saName, saFieldsFile)) return 'NoField' sa = rows[0] printInfo("StdArea: %s, Coords: %s %s, NumStars: %d, Comment: %s" % (saName, sa['RA_2000'], sa['DEC_2000'], sa['NS'], sa['COMMENT'])) self.opt['ra'] = hexa2deg(sa['RA_2000']) * 15.0 self.opt['dec'] = hexa2deg(sa['DEC_2000']) self.chartId = saName # load stdStars file saStarsFile = configFolder + "/landolt_stars.txt" if not exists(saStarsFile): printError("Landolt standard stars catalog file %s not found" % (saStarsFile)) return 'NoFile' saStars = Table.read(saStarsFile, format = 'ascii') # find std stars stars = list(filter(lambda r: r['FIELD_NAME'] == saName, saStars)) if len(stars) == 0: printError("No stars for standard field %s in standard area file %s." % (saName, saStarsFile)) return 'NoStars' # write stars to catalog file nrUnknown = 1 for star in stars: auid = '999-STD-%03d' % (nrUnknown) nrUnknown = nrUnknown + 1 role = "C" ra = star['RA_2000'] raDeg = "%10.8f" % (hexa2deg(ra) * 15.0) dec = star['DEC_2000'] decDeg = "%+10.8f" % (hexa2deg(dec)) mv = float(star['MAG_V']) ev = float(star['ERR_V']) magB = "%+6.4f" % (float(star['MAG_BV']) + mv) errB = "%+7.4f" % (max(ev, float(star['ERR_BV']))) magV = "%+6.4f" % (mv) errV = "%+7.4f" % (ev) magR = "%+6.4f" % (mv - float(star['MAG_VR'])) errR = "%+7.4f" % (max(ev, float(star['ERR_VR']))) label = saName + ":" + star['STAR'] self.writeRecord(auid, role, ra, raDeg, dec, decDeg, magB, errB, magV, errV, magR, errR, label) self.xmatchTable.add_row([auid, raDeg, decDeg, label]) print("%d standard star found for standard area %s" % (len(stars), saName)) return None
def execute(self): ########################## # step 0. setup photometry ########################## self.pplSetup = loadPplSetup() self.discoverFolders() if self.opt['masterFlat']: if not isdir(self.opt['masterFlat']): printError("Master-flat folder %s not exists." % (self.opt['masterFlat'])) exit(1) else: hasMaster = True for c in self.opt['color']: mfc = "%s/%s-%s.fits" % (self.opt['masterFlat'], self.pplSetup['MASTER_FLAT_FILE'], c) print(mfc) if not exists(mfc): printError( "No %s master-flat file in the directory %s" % (c, self.opt['masterFlat'])) hasMaster = False if hasMaster: self.FLAT_FOLDER = self.opt['masterFlat'] print("master-flat: " + self.opt['masterFlat']) else: exit(1) # create the temp dir, if not exists if not exists(self.TEMPDIR): makedirs(self.TEMPDIR) #################################### # step 1. create master bias frame #################################### if not self.opt['flatOnly']: self.processBias(self.BIAS_FOLDER, "BIAS") #################################### # step 2. create master dark frame #################################### self.processDark(self.DARK_FOLDER, self.BIAS_FOLDER, "DARK") if not self.opt['useMasterFlat']: # process flat bias, flat dark and flat, only if flat master is not exist ex = self.mastersExist(self.FLAT_FOLDER, self.pplSetup['MASTER_FLAT_FILE']) if self.opt['overwrite'] or not ex: ############################################################################ # step 3. create master flat bias frame, if it is differs from master bias ############################################################################ self.processBias(self.FLAT_BIAS_FOLDER, "FLAT BIAS") ############################################################################ # step 4. create master flat dark frame, if it is differs from mastre dark ############################################################################ self.processDark(self.FLAT_DARK_FOLDER, self.FLAT_BIAS_FOLDER, "FLAT DARK") ############################## # step 5. create master flat ############################## self.processFlat(self.FLAT_FOLDER, self.FLAT_BIAS_FOLDER, self.FLAT_DARK_FOLDER, "FLAT") else: printInfo("FLAT: Master flat file(s) are already created.") ################################## # step 6. calibrate light frames ################################## if not self.opt['flatOnly']: for lf in self.LIGHT_FOLDERS: cf = lf.replace(self.pplSetup['LIGHT_FOLDER_NAME'], self.pplSetup['CALIB_FOLDER_NAME']) self.processCalibration(lf, cf, "CALIBRATE") ############################################### # step 7. registrate and combine light frames ############################################### sf = lf.replace(self.pplSetup['LIGHT_FOLDER_NAME'], self.pplSetup['SEQ_FOLDER_NAME']) self.processRegistration(cf, sf, "REGISTRATE") print() print(Blue + "Calibration is ready." + Color_Off)
def registrate(self, calibFolder, seqFolder, color): # Names of the individual files storing the raw bias, dark, flat and object frames: CALIB_PATTERN = "%s/%s*-%s.fits" % ( calibFolder, self.pplSetup['LIGHT_FILE_PREFIX'], color) COBJLIST = glob.glob(CALIB_PATTERN) COBJLIST.sort() if len(COBJLIST) == 0: return 1 COMBINED_FILE = "%s/Combined-%s.fits" % (seqFolder, color) print("%s -> %s" % (CALIB_PATTERN, COMBINED_FILE)) # search for reference image by the best average FWHM bestFwhm = 999.9 REF = None REF_IMG = None for f in COBJLIST: fstars = self.TEMPDIR + '/' + basename(f) + ".stars" self.invoked("fistar %s %s -o %s" % (f, self.FISTAR_ARGS, fstars)) if not self.REF: fwhm = self.calculateAvgFwhm(fstars) # printDebug("FWHM: %7.4f - %s" % (fwhm, f)) if fwhm < bestFwhm: bestFwhm = fwhm REF = fstars REF_IMG = f if not self.REF: self.REF = REF_IMG.replace(color, '{color}') if self.opt['debug']: printDebug("Reference image average FWHM: %7.4f" % (bestFwhm)) else: REF_IMG = self.REF.replace("{color}", color) REF = self.TEMPDIR + '/' + basename(REF_IMG) + ".stars" print("Set reference image: " + REF_IMG) copyfile(REF_IMG, "%s/%s" % (self.TEMPDIR, basename(REF_IMG))) # Registration of the source images: for f in COBJLIST: if f == REF_IMG: continue bn = basename(f) pbn = self.TEMPDIR + '/' + bn print("transform %s -> %s" % (f, pbn)) fstars = pbn + ".stars" ftrans = pbn + ".trans" matchFailed = 0 answer = self.invoked( "grmatch %s --input %s --reference %s --output-transformation %s" % (self.GRMATCH_ARGS, fstars, REF, ftrans)) if answer.startswith('ERROR'): matchFailed = 1 else: ln = findInFile(ftrans, 'Match failed') answer = '' matchFailed = 1 if ln != None else 0 if matchFailed == 1: printError("Match failed on %s." % (f)) if answer: print(' ' + answer) if self.opt['onError'] == "stop": self.exitOnError() if matchFailed == 0 or self.opt['onError'] == "noop": self.invoked( "fitrans %s --input-transformation %s --reverse -k -o %s" % (f, ftrans, pbn)) # list of transformed frames TR_PATTERN = "%s/%s*-%s.fits" % ( self.TEMPDIR, self.pplSetup['LIGHT_FILE_PREFIX'], color) TROBJLIST = glob.glob(TR_PATTERN) TROBJLIST.sort() # create a sequence of combined frames cc = self.opt['countCombine'] if cc != 0: for a in range(0, len(TROBJLIST), cc): fi = "%03d" % (a / cc) combined = "%s/%s%s-%s.fits" % ( seqFolder, self.pplSetup['SEQ_FILE_PREFIX'], fi, color) print("combine " + combined) self.invoked("ficombine %s %s -o %s" % (' '.join( TROBJLIST[a:a + cc]), self.FICOMBINE_ARGS, combined)) self.sumDateObs(combined, TROBJLIST[a:a + cc]) # create a combined frame of all images print("combine %s -> %s" % (TR_PATTERN, COMBINED_FILE)) self.invoked("ficombine %s %s -o %s" % (' '.join(TROBJLIST), self.FICOMBINE_ARGS, COMBINED_FILE)) self.sumDateObs(COMBINED_FILE, TROBJLIST) # cleanup - remove temp files for f in TROBJLIST: os.remove(f) os.remove(REF) if not self.opt['debug']: for f in glob.glob(self.TEMPDIR + '/*.stars'): os.remove(f) for f in glob.glob(self.TEMPDIR + '/*.trans'): os.remove(f)
def process(self): if not self.opt['files']: pm.printError('No input files are given.') return allCatalogs = {} # load refcats for j in range(len(self.opt['color'])): fileName = self.opt['files'][j] color = self.opt['color'][j] if not exists(fileName): pm.printError("File %s is not exists." % (fileName)) return refCat = loadCatalog(fileName) if not self.pos: self.pos = self.getHeaderPositions(refCat) allCatalogs[color] = refCat # find best comp star in Gi frame color = 'Gi' # TODO: what if no Gi color, just G, g, gi, or V ? indexGi = self.opt['color'].index(color) self.loadFitsHeaders(self.opt['files'][indexGi]) dateObs = self.fits['DATE-OBS'] dateObsDate = dateObs.split('T')[0] bestComp = self.findBestCompStar( allCatalogs, color) # refcat record of best comp in Gi if not bestComp: return False # calculate instrumental mgs allResults = {} # calculate virtual comp star p_a, err_a = self.calculateEnsembleParams(allCatalogs, bestComp) vcomp = self.calcVComp(self.opt['color'], allCatalogs, bestComp, p_a, err_a) # calculate or load std coeffs if self.opt['useCoeffs'] or self.opt['makeCoeffs']: # standardization coeffs = None target = pm.guess(self.opt['files'][0])['target'] if self.opt['makeCoeffs']: mergedCat = self.mergeCatalogs(allCatalogs) coeffs = self.calculateCoeffs(mergedCat) if self.opt['saveCoeffs']: self.saveCoeffs(coeffs, dateObsDate, target) elif self.opt['loadCoeffs']: coeffs = self.loadCoeffs(dateObsDate, target) if not coeffs: pm.printError( 'No std coefficients for transformation ; use Tv = 0, Tvr = 1, Tbv = 1 for comp star method.' ) coeffs = [0.0, 1.0, 1.0] # this is for non-std transformation else: coeffs = [0.0, 1.0, 1.0] # apply virtual comp and std coeffs to calculate magnitudes if len(self.opt['color']) == 3: allResults = self.calculateStdMgs(coeffs, allCatalogs, vcomp) else: allResults = self.calculateSimpleMgs(self.opt['color'], allCatalogs, vcomp) # save results for j in range(len(self.opt['color'])): fileName = self.opt['files'][j] color = self.opt['color'][j] self.reportResult(allResults[color], allCatalogs[color], fileName + '.pm', color, dateObs) return True
def execute(self): ########################## # step 0. setup photometry ########################## self.pplSetup = loadPplSetup() seqFolders = discoverFolders(self.opt['baseFolder'], self.pplSetup['SEQ_FOLDER_NAME']) if len(seqFolders) == 0: printError('No sequence folder found in base folder %s' % (self.opt['baseFolder'])) exit(1) print("Sequence folders discovered:", seqFolders) # ## Common arguments (saturation level, image section & trimming, etc.): self.AST_CFG = self.pplSetup['CONFIG_FOLDER'] + "/astrometry.cfg" self.SEX_CFG = self.pplSetup['CONFIG_FOLDER'] + "/sex.cfg" # SOLVE_ARGS="-O --config $AST_CFG --use-sextractor --sextractor-path sextractor -i ${PHOTDIR}/scamp.cat -n ${PHOTDIR}/scamp.cfg -j ${PHOTDIR}/scamp.ref -r -y -p" self.SOLVE_ARGS = "-O --config %s --use-sextractor --sextractor-path sextractor -r -y -p" % ( self.AST_CFG) #################################### # step 1. do photometry for all file #################################### PMERROR = False requestedColors = self.opt['color'] requestedStd = self.opt['useStd'] for sf in seqFolders: baseFolder = sf.replace('/' + self.pplSetup['SEQ_FOLDER_NAME'], '') self.opt['color'] = requestedColors self.opt['useStd'] = requestedStd refcatAvailable = self.inspectRefCat(baseFolder) if not refcatAvailable: printError( 'Reference catalog is not usable for photometry ; skip folder %s' % (sf)) continue pf = sf.replace(self.pplSetup['SEQ_FOLDER_NAME'], self.pplSetup['PHOT_FOLDER_NAME']) success = self.process_photometry(sf, pf, "PHOTOMETRY") if not success: PMERROR = True break ######################################## # step 2. create report from all results ######################################## if not PMERROR: if self.opt['baseFolder'] != None: PM_FILES = glob('*' + self.opt['baseFolder'] + '*/' + self.pplSetup['PHOT_FOLDER_NAME'] + '/*.pm') BASE_FOLDERS = glob('*' + self.opt['baseFolder'] + '*') REPORT_FOLDER = BASE_FOLDERS[0] else: PM_FILES = glob(self.pplSetup['PHOT_FOLDER_NAME'] + '/*.pm') REPORT_FOLDER = getcwd() printInfo("Create report into %s folder." % (REPORT_FOLDER)) opt = { 'out': REPORT_FOLDER, # output folder 'rpt': 'aavso', # report format, default: aavso extended 'name': self.opt['nameCode'], # observer name code 'method': self. opt['method'], # mg calculation method, comp - single com star, gcx/lfit - ensemble 'files': PM_FILES, } proc = ReportProcessor(opt) proc.process() print() print(Blue + "Photometry is ready." + Color_Off)
def processCommands(self): try: optlist, args = getopt(self.argv[1:], "c:n:msat:wh", [ 'color=', 'name=', 'make-std', 'use-std', 'adhoc-std', 'show-graph', 'method=', 'overwrite', 'help' ]) except GetoptError: printError('Invalid command line options.') return for o, a in optlist: if a[:1] == ':': a = a[1:] elif o == '-c' or o == '--color': color = a.lower() if not color in self.availableBands: printError( 'Invalid color: %s, use on of these: Gi, g, Bi, b, Ri, r, all' % (a)) exit(1) if color == 'all': self.opt['color'] = ['Ri', 'Gi', 'Bi'] else: self.opt['color'] = [a] elif o == '-n' or o == '--name': self.opt['nameCode'] = a.upper() elif o == '-m' or o == '--make-std': self.opt['makeStd'] = True elif o == '-s' or o == '--use-std': self.opt['useStd'] = True elif o == '-a' or o == '--adhoc-std': self.opt['adhocStd'] = True elif o == '--show-graph': self.opt['showGraphs'] = True elif o == '--camera': self.opt['camera'] = a elif o == '--telescope': self.opt['telescope'] = a elif o == '-t' or o == '--method': if not a in self.mgCalcMethods.keys(): printWarning( 'Invalid mg calculation method %s ; use gcx instead.') else: self.opt['method'] = a elif o == '-w' or o == '--overwrite': self.opt['overwrite'] = True elif o == '-h' or o == '--help': self.usage() exit(0) if self.opt['adhocStd'] and (self.opt['makeStd'] or self.opt['useStd']): printWarning( 'Both -a and either -m or -s option cannot be used at once.') exit(0) if len(args) > 0: self.opt['baseFolder'] = args[0] if args[0].endswith('/'): self.opt['baseFolder'] = args[0][:-1] if self.opt['nameCode'] == None: printWarning('No observer code was given. Use \'XYZ\' instead.') self.opt['nameCode'] = 'XYZ' print('Mg calculation method: ' + self.mgCalcMethods[self.opt['method']])
def processCommands(self): try: optlist, args = getopt(self.argv[1:], "c:n:fm:t:we:h", [ 'color=', 'count-combine=', 'flat', 'master-flat=', 'image-time=', 'overwrite', 'on-error=', 'help', 'calib-folder=', 'debug' ]) except GetoptError: printError('Invalid command line options.') return for o, a in optlist: if a[:1] == ':': a = a[1:] elif o == '-c' or o == '--color': color = a.lower() if not color in self.availableBands: printError( 'Invalid color: %s, use on of these: Gi, g, Bi, b, Ri, r, all' % (a)) exit(1) if color == 'all': self.opt['color'] = ['Gi', 'Ri', 'Bi'] else: self.opt['color'] = [a] elif o == '-f' or o == '--flat': self.opt['flatOnly'] = True elif o == '-m' or o == '--master-flat': self.opt['useMasterFlat'] = True self.opt['masterFlat'] = a elif o == '-n' or o == '--count-combine': self.opt['countCombine'] = int(a) elif o == '-t' or o == '--image-time': if a in ['LT', 'UT']: self.opt['imageTime'] = a else: printWarning( "Bad image time zone value: %s, using default %s instead." % (a, self.opt['imageTime'])) elif o == '-e' or o == '--on-error': if not a in ['noop', 'skip', 'stop']: printWarning( "Bad on-error instruction; available values are: noop, stop, skip." ) else: self.opt['onError'] = a elif o == '--calib-folder': if not isdir(a): printError( "%s is not a folder. Calibration folder option is ignored." % (a)) else: self.opt['calibFolder'] = a elif o == '-w' or o == '--overwrite': self.opt['overwrite'] = True elif o == '--debug': self.opt['debug'] = True elif o == '-h' or o == '--help': self.usage() exit(0) if len(args) > 0: self.opt['baseFolder'] = args[0] if args[0].endswith('/'): self.opt['baseFolder'] = args[0][:-1] if not isdir(self.opt['baseFolder']): printError("Base folder %s not exists or not a directory." % (self.opt['baseFolder'])) exit(1) else: print("base folder: %s" % (self.opt['baseFolder'])) print("colors: " + ' '.join(self.opt['color'])) print("overwrite: " + str(self.opt['overwrite'])) print("count combine: " + str(self.opt['countCombine'])) print("image timezone: " + str(self.opt['imageTime']))