def main(args): # Load fits file cfg_lines, data_files, frametype, usrdata, setups = parse_pypeit_file(args.file, runtime=False) # Get the raw fits file name sciIdx = get_science_frame(usrdata) fname = data_files[sciIdx] # Load the spectrograph cfg = ConfigObj(cfg_lines) spectrograph_name = cfg['rdx']['spectrograph'] spectrograph = load_spectrograph(spectrograph_name, ifile=data_files[sciIdx]) msgs.info('Loaded spectrograph {0}'.format(spectrograph.spectrograph)) spectrograph_cfg_lines = spectrograph.config_specific_par(fname).to_config() par = PypeItPar.from_cfg_lines(cfg_lines=spectrograph_cfg_lines, merge_with=cfg_lines) # Get the master key file_base = os.path.basename(fname) ftdict = dict({file_base: 'science'}) fitstbl = PypeItMetaData(spectrograph, par, files=[data_files[sciIdx]], usrdata=Table(usrdata[sciIdx]), strict=True) fitstbl.finalize_usr_build(ftdict, setups[0]) mkey = fitstbl.master_key(0, det=args.det) # Load the frame data rawimage, _, _, datasec, _ = spectrograph.get_rawimage(fname, args.det) rawimage = procimg.trim_frame(rawimage, datasec < 1) frame = spectrograph.orient_image(rawimage, args.det) # Set paths if par['calibrations']['caldir'] == 'default': mdir = os.path.join(par['rdx']['redux_path'], 'Masters') else: mdir = par['calibrations']['caldir'] if not os.path.exists(mdir): mdir_base = os.path.join(os.getcwd(), os.path.basename(mdir)) msgs.warn('Master file dir: {0} does not exist. Using {1}'.format(mdir, mdir_base)) mdir = mdir_base # Load the tslits_dict trc_file = os.path.join(mdir, MasterFrame.construct_file_name('Edges', mkey)) + '.gz' tslits_dict = edgetrace.EdgeTraceSet.from_file(trc_file).convert_to_tslits_dict() # Derive an appropriate output filename prefix = os.path.splitext(file_base) if prefix[1] == ".gz": prefix = os.path.splitext(prefix[0])[0] else: prefix = prefix[0] outname = "{0:s}_skyregions.fits".format(prefix) # Finally, initialise the GUI skyreg = SkySubGUI.initialize(args.det, frame, tslits_dict, outname=outname, runtime=False, printout=True) # Get the results skyreg.get_result()
def main(args): import os from pypeit.core.gui.skysub_regions import SkySubGUI from pypeit.core import flexure from pypeit.scripts import utils from pypeit import masterframe from pypeit.images import buildimage # Generate a utilities class info = utils.Utilities(None, pypeit_file=args.file, det=args.det) # Interactively select a science frame sciIdx = info.select_science_frame(standard=args.standard) # Load the spectrograph and parset info.load_spectrograph_parset(sciIdx) # Get the master key and directory mdir, mkey = info.get_master_dirkey() # Load the image data frame = info.load_frame(sciIdx) # Load the slits information slits = utils.get_slits(mkey, mdir) spat_flexure = None if args.flexure: spat_flexure = flexure.spat_flexure_shift(frame, slits) # Derive an appropriate output filename file_base = info.get_basename(sciIdx) prefix = os.path.splitext(file_base) if prefix[1] == ".gz": outname = os.path.splitext(prefix[0])[0] else: outname = prefix[0] ext = buildimage.SkyRegions.master_file_format regfile = masterframe.construct_file_name(buildimage.SkyRegions, master_key=mkey, master_dir=mdir) regfile = regfile.replace(".{0:s}".format(ext), "_{0:s}.{1:s}".format(outname, ext)) #outname = "{0:s}/MasterSkyRegions_{1:s}_{2:s}.fits.gz".format(mdir, mkey, outname) # Finally, initialise the GUI skyreg = SkySubGUI.initialize(args.det, frame, slits, info.spectrograph.pypeline, info.spectrograph.name, outname=regfile, overwrite=args.overwrite, runtime=False, printout=True, initial=args.initial, flexure=spat_flexure) # Get the results skyreg.get_result()
def main(args): # Generate a utilities class info = utils.Utilities(args.file, args.det) # Interactively select a science frame sciIdx = info.select_science_frame() # Load the spectrograph and parset info.load_spectrograph_parset(sciIdx) # Get the master key and directory mdir, mkey = info.get_master_dirkey() # Load the image data frame = info.load_frame(sciIdx) # Load the slits information slits = utils.get_slits(mkey, mdir) spat_flexure = None if args.flexure: spat_flexure = flexure.spat_flexure_shift(frame, slits) # Derive an appropriate output filename file_base = info.get_basename(sciIdx) prefix = os.path.splitext(file_base) if prefix[1] == ".gz": outname = os.path.splitext(prefix[0])[0] else: outname = prefix[0] outname = "{0:s}/MasterSkyRegions_{1:s}_{2:s}.fits.gz".format( mdir, mkey, outname) # Finally, initialise the GUI skyreg = SkySubGUI.initialize(args.det, frame, slits, info.spectrograph.pypeline, outname=outname, overwrite=args.overwrite, runtime=False, printout=True, initial=args.initial, flexure=spat_flexure) # Get the results skyreg.get_result()