def __init__(self, tslits_dict, tilts, wv_calib, spectrograph, det, maskslits, master_key=None, master_dir=None, reuse_masters=False): # Image pypeitimage.PypeItImage.__init__(self, spectrograph, det) # MasterFrame MasterFrame.__init__(self, self.master_type, master_dir=master_dir, master_key=master_key, reuse_masters=reuse_masters) # Required parameters self.spectrograph = spectrograph self.tslits_dict = tslits_dict self.tilts = tilts self.wv_calib = wv_calib if tslits_dict is not None: self.slitmask = pixels.tslits2mask(self.tslits_dict) self.slit_spat_pos = trace_slits.slit_spat_pos(self.tslits_dict) else: self.slitmask = None self.slit_spat_pos = None # TODO: only echelle is ever used. Do we need to keep the whole # thing? self.par = wv_calib['par'] if wv_calib is not None else None self.maskslits = maskslits # For echelle order, primarily # List to hold ouptut from inspect about what module create the image? self.steps = [] # Main output self.image = None
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 __init__(self, tslits_dict, tilts, wv_calib, spectrograph, maskslits, master_key=None, master_dir=None, reuse_masters=False): # def __init__(self, spectrograph, tslits_dict, tilts, wv_calib, maskslits, # master_key=None, master_dir=None, reuse_masters=False): # MasterFrame MasterFrame.__init__(self, self.master_type, master_dir=master_dir, master_key=master_key, reuse_masters=reuse_masters) # Required parameters self.spectrograph = spectrograph self.tslits_dict = tslits_dict self.tilts = tilts self.wv_calib = wv_calib self.slitmask = pixels.tslits2mask( self.tslits_dict) if tslits_dict is not None else None # TODO: only echelle is ever used. Do we need to keep the whole # thing? self.par = wv_calib['par'] if wv_calib is not None else None self.maskslits = maskslits # List to hold ouptut from inspect about what module create the image? self.steps = [] # Main output self.mswave = None
def load_from_file(filename, return_header=False): """ Load the wavelength image data from a saved master frame. Args: filename (:obj:`str`, optional): Name of the master frame file. return_header (:obj:`bool`, optional): Return the header Returns: tuple: Returns an `numpy.ndarray`_ with the wavelength image. Also returns the primary header, if requested. """ # Use of super() to call staticmethods of the base class seems # like a bit of a mess (bound vs. unbound methods). There's a # syntax that works, but for now, I'm just going to call the # static method explicitly without using super(). See: # https://stackoverflow.com/questions/26788214/super-and-staticmethod-interaction return MasterFrame.load_from_file(filename, 'WAVE', return_header=return_header)
def main(args): # List only? hdu = fits.open(args.file) head0 = hdu[0].header if args.list: hdu.info() return # Setup for PYPIT imports msgs.reset(verbosity=2) # Init sdet = get_dnum(args.det, prefix=False) # One detector, sky sub for now names = [hdu[i].name for i in range(len(hdu))] try: exten = names.index('DET{:s}-PROCESSED'.format(sdet)) except: # Backwards compatability msgs.error( 'Requested detector {:s} was not processed.\n' 'Maybe you chose the wrong one to view?\n' 'Set with --det= or check file contents with --list'.format(sdet)) sciimg = hdu[exten].data try: exten = names.index('DET{:s}-SKY'.format(sdet)) except: # Backwards compatability msgs.error( 'Requested detector {:s} has no sky model.\n' 'Maybe you chose the wrong one to view?\n' 'Set with --det= or check file contents with --list'.format(sdet)) skymodel = hdu[exten].data try: exten = names.index('DET{:s}-MASK'.format(sdet)) except ValueError: # Backwards compatability msgs.error( 'Requested detector {:s} has no bit mask.\n' 'Maybe you chose the wrong one to view?\n' 'Set with --det= or check file contents with --list'.format(sdet)) mask = hdu[exten].data try: exten = names.index('DET{:s}-IVARMODEL'.format(sdet)) except ValueError: # Backwards compatability msgs.error( 'Requested detector {:s} has no IVARMODEL.\n' 'Maybe you chose the wrong one to view?\n' + 'Set with --det= or check file contents with --list'.format(sdet)) ivarmodel = hdu[exten].data # Read in the object model for residual map try: exten = names.index('DET{:s}-OBJ'.format(sdet)) except ValueError: # Backwards compatability msgs.error( 'Requested detector {:s} has no object model.\n' 'Maybe you chose the wrong one to view?\n' + 'Set with --det= or check file contents with --list'.format(sdet)) objmodel = hdu[exten].data # Get waveimg mdir = head0['PYPMFDIR'] + '/' if not os.path.exists(mdir): mdir_base = os.path.basename(os.path.dirname(mdir)) + '/' msgs.warn('Master file dir: {0} does not exist. Using ./{1}'.format( mdir, mdir_base)) mdir = mdir_base trace_key = '{0}_{1:02d}'.format(head0['TRACMKEY'], args.det) trc_file = os.path.join( mdir, MasterFrame.construct_file_name('Trace', trace_key)) wave_key = '{0}_{1:02d}'.format(head0['ARCMKEY'], args.det) waveimg = os.path.join(mdir, MasterFrame.construct_file_name('Wave', wave_key)) tslits_dict = TraceSlits.load_from_file(trc_file)[0] slitmask = pixels.tslits2mask(tslits_dict) shape = (tslits_dict['nspec'], tslits_dict['nspat']) slit_ids = [ trace_slits.get_slitid(shape, tslits_dict['slit_left'], tslits_dict['slit_righ'], ii)[0] for ii in range(tslits_dict['slit_left'].shape[1]) ] # Show the bitmask? mask_in = mask if args.showmask else None # Object traces spec1d_file = args.file.replace('spec2d', 'spec1d') det_nm = 'DET{:s}'.format(sdet) if os.path.isfile(spec1d_file): hdulist_1d = fits.open(spec1d_file) else: hdulist_1d = [] msgs.warn('Could not find spec1d file: {:s}'.format(spec1d_file) + msgs.newline() + ' No objects were extracted.') # Unpack the bitmask bitMask = bitmask() bpm, crmask, satmask, minmask, offslitmask, nanmask, ivar0mask, ivarnanmask, extractmask \ = bitMask.unpack(mask) # Now show each image to a separate channel # SCIIMG image = sciimg # Raw science image (mean, med, sigma) = sigma_clipped_stats(image[mask == 0], sigma_lower=5.0, sigma_upper=5.0) cut_min = mean - 1.0 * sigma cut_max = mean + 4.0 * sigma chname_skysub = 'sciimg-det{:s}'.format(sdet) # Clear all channels at the beginning viewer, ch = ginga.show_image(image, chname=chname_skysub, waveimg=waveimg, bitmask=mask_in, clear=True) #, cuts=(cut_min, cut_max), wcs_match=True) ginga.show_slits(viewer, ch, tslits_dict['slit_left'], tslits_dict['slit_righ'], slit_ids) #, args.det) # SKYSUB image = (sciimg - skymodel) * (mask == 0) # sky subtracted image (mean, med, sigma) = sigma_clipped_stats(image[mask == 0], sigma_lower=5.0, sigma_upper=5.0) cut_min = mean - 1.0 * sigma cut_max = mean + 4.0 * sigma chname_skysub = 'skysub-det{:s}'.format(sdet) # Clear all channels at the beginning # TODO: JFH For some reason Ginga crashes when I try to put cuts in here. viewer, ch = ginga.show_image( image, chname=chname_skysub, waveimg=waveimg, bitmask=mask_in) #, cuts=(cut_min, cut_max),wcs_match=True) show_trace(hdulist_1d, det_nm, viewer, ch) ginga.show_slits(viewer, ch, tslits_dict['slit_left'], tslits_dict['slit_righ'], slit_ids) #, args.det) # SKRESIDS chname_skyresids = 'sky_resid-det{:s}'.format(sdet) image = (sciimg - skymodel) * np.sqrt(ivarmodel) * (mask == 0 ) # sky residual map viewer, ch = ginga.show_image(image, chname_skyresids, waveimg=waveimg, cuts=(-5.0, 5.0), bitmask=mask_in) #,wcs_match=True) show_trace(hdulist_1d, det_nm, viewer, ch) ginga.show_slits(viewer, ch, tslits_dict['slit_left'], tslits_dict['slit_righ'], slit_ids) #, args.det) # RESIDS chname_resids = 'resid-det{:s}'.format(sdet) # full model residual map image = (sciimg - skymodel - objmodel) * np.sqrt(ivarmodel) * (mask == 0) viewer, ch = ginga.show_image(image, chname=chname_resids, waveimg=waveimg, cuts=(-5.0, 5.0), bitmask=mask_in) #,wcs_match=True) show_trace(hdulist_1d, det_nm, viewer, ch) ginga.show_slits(viewer, ch, tslits_dict['slit_left'], tslits_dict['slit_righ'], slit_ids) #, args.det) # After displaying all the images sync up the images with WCS_MATCH shell = viewer.shell() out = shell.start_global_plugin('WCSMatch') out = shell.call_global_plugin_method('WCSMatch', 'set_reference_channel', [chname_resids], {}) if args.embed: IPython.embed()
def load_coadd2d_stacks(spec2d_files, det): """ Args: spec2d_files: list List of spec2d filenames det: int detector in question Returns: stack_dict: dict Dictionary containing all the images and keys required for perfomring 2d coadds. """ # Get the detector string sdet = parse.get_dnum(det, prefix=False) # Get the master dir head0 = fits.getheader(spec2d_files[0]) master_dir = os.path.basename(head0['PYPMFDIR']) redux_path = os.getcwd() master_path = os.path.join(redux_path, master_dir) # Grab the files head2d_list=[] tracefiles = [] waveimgfiles = [] tiltfiles = [] spec1d_files = [] for f in spec2d_files: head = fits.getheader(f) trace_key = '{0}_{1:02d}'.format(head['TRACMKEY'], det) wave_key = '{0}_{1:02d}'.format(head['ARCMKEY'], det) head2d_list.append(head) spec1d_files.append(f.replace('spec2d', 'spec1d')) tracefiles.append(os.path.join(master_path, MasterFrame.construct_file_name('Trace', trace_key))) waveimgfiles.append(os.path.join(master_path, MasterFrame.construct_file_name('Wave', wave_key))) tiltfiles.append(os.path.join(master_path, MasterFrame.construct_file_name('Tilts', wave_key))) nfiles = len(spec2d_files) specobjs_list = [] head1d_list=[] # TODO Sort this out with the correct detector extensions etc. # Read in the image stacks for ifile in range(nfiles): waveimg = WaveImage.load_from_file(waveimgfiles[ifile]) tilts = WaveTilts.load_from_file(tiltfiles[ifile]) hdu = fits.open(spec2d_files[ifile]) # One detector, sky sub for now names = [hdu[i].name for i in range(len(hdu))] # science image try: exten = names.index('DET{:s}-PROCESSED'.format(sdet)) except: # Backwards compatability det_error_msg(exten, sdet) sciimg = hdu[exten].data # skymodel try: exten = names.index('DET{:s}-SKY'.format(sdet)) except: # Backwards compatability det_error_msg(exten, sdet) skymodel = hdu[exten].data # Inverse variance model try: exten = names.index('DET{:s}-IVARMODEL'.format(sdet)) except ValueError: # Backwards compatability det_error_msg(exten, sdet) sciivar = hdu[exten].data # Mask try: exten = names.index('DET{:s}-MASK'.format(sdet)) except ValueError: # Backwards compatability det_error_msg(exten, sdet) mask = hdu[exten].data if ifile == 0: # the two shapes accomodate the possibility that waveimg and tilts are binned differently shape_wave = (nfiles,waveimg.shape[0],waveimg.shape[1]) shape_sci = (nfiles,sciimg.shape[0],sciimg.shape[1]) waveimg_stack = np.zeros(shape_wave,dtype=float) tilts_stack = np.zeros(shape_wave,dtype=float) sciimg_stack = np.zeros(shape_sci,dtype=float) skymodel_stack = np.zeros(shape_sci,dtype=float) sciivar_stack = np.zeros(shape_sci,dtype=float) mask_stack = np.zeros(shape_sci,dtype=float) waveimg_stack[ifile,:,:] = waveimg tilts_stack[ifile,:,:] = tilts['tilts'] sciimg_stack[ifile,:,:] = sciimg sciivar_stack[ifile,:,:] = sciivar mask_stack[ifile,:,:] = mask skymodel_stack[ifile,:,:] = skymodel sobjs, head = load.load_specobjs(spec1d_files[ifile]) head1d_list.append(head) specobjs_list.append(sobjs) # Right now we assume there is a single tslits_dict for all images and read in the first one # TODO this needs to become a tslits_dict for each file to accomodate slits defined by flats taken on different # nights tslits_dict, _ = TraceSlits.load_from_file(tracefiles[0]) spectrograph = util.load_spectrograph(tslits_dict['spectrograph']) slitmask = pixels.tslits2mask(tslits_dict) slitmask_stack = np.einsum('i,jk->ijk', np.ones(nfiles), slitmask) # Fill the master key dict head2d = head2d_list[0] master_key_dict = {} master_key_dict['frame'] = head2d['FRAMMKEY'] + '_{:02d}'.format(det) master_key_dict['bpm'] = head2d['BPMMKEY'] + '_{:02d}'.format(det) master_key_dict['bias'] = head2d['BIASMKEY'] + '_{:02d}'.format(det) master_key_dict['arc'] = head2d['ARCMKEY'] + '_{:02d}'.format(det) master_key_dict['trace'] = head2d['TRACMKEY'] + '_{:02d}'.format(det) master_key_dict['flat'] = head2d['FLATMKEY'] + '_{:02d}'.format(det) stack_dict = dict(specobjs_list=specobjs_list, tslits_dict=tslits_dict, slitmask_stack=slitmask_stack, sciimg_stack=sciimg_stack, sciivar_stack=sciivar_stack, skymodel_stack=skymodel_stack, mask_stack=mask_stack, tilts_stack=tilts_stack, waveimg_stack=waveimg_stack, head1d_list = head1d_list, head2d_list=head2d_list, redux_path=redux_path, master_path=master_path, master_dir=master_dir, master_key_dict=master_key_dict, spectrograph = tslits_dict['spectrograph']) return stack_dict
def load_kast_blue_masters(aimg=False, edges=False, tilts=False, wvcalib=False, pixflat=False): """ Load up the set of shane_kast_blue master frames Order is Arc, edges, tilts_dict, wv_calib, pixflat Args: get_spectrograph: aimg: edges (bool, optional): Load the slit edges tilts: datasec: wvcalib: Returns: list: List of calibration items """ spectrograph = load_spectrograph('shane_kast_blue') spectrograph.naxis = (2112, 350) # Image shape with overscan master_dir = os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked', 'Shane_Kast_blue') reuse_masters = True # Load up the Masters ret = [] master_key = 'A_1_01' if aimg: AImg = arcimage.ArcImage(spectrograph, master_key=master_key, master_dir=master_dir, reuse_masters=reuse_masters) msarc = AImg.load() ret.append(msarc) if edges: trace_file = '{0}.gz'.format( os.path.join(master_dir, MasterFrame.construct_file_name('Edges', master_key))) ret.append(edgetrace.EdgeTraceSet.from_file(trace_file)) if tilts: tilts_file = os.path.join( master_dir, MasterFrame.construct_file_name('Tilts', master_key)) tilts_dict = wavetilts.WaveTilts.from_master_file( tilts_file).tilts_dict ret.append(tilts_dict) if wvcalib: calib_file = os.path.join( master_dir, MasterFrame.construct_file_name('WaveCalib', master_key, file_format='json')) wv_calib = waveio.load_wavelength_calibration(calib_file) ret.append(wv_calib) # Pixelflat if pixflat: calib_file = os.path.join( master_dir, MasterFrame.construct_file_name('Flat', master_key)) flatField = flatfield.FlatField.from_master_file(calib_file) ret.append(flatField.mspixelflat) # Return return ret
def main(args): # List only? hdu = fits.open(args.file) head0 = hdu[0].header if args.list: hdu.info() return # Init sdet = get_dnum(args.det, prefix=False) # One detector, sky sub for now names = [hdu[i].name for i in range(len(hdu))] try: exten = names.index('DET{:s}-PROCESSED'.format(sdet)) except: # Backwards compatability msgs.error('Requested detector {:s} was not processed.\n' 'Maybe you chose the wrong one to view?\n' 'Set with --det= or check file contents with --list'.format(sdet)) sciimg = hdu[exten].data try: exten = names.index('DET{:s}-SKY'.format(sdet)) except: # Backwards compatability msgs.error('Requested detector {:s} has no sky model.\n' 'Maybe you chose the wrong one to view?\n' 'Set with --det= or check file contents with --list'.format(sdet)) skymodel = hdu[exten].data try: exten = names.index('DET{:s}-MASK'.format(sdet)) except ValueError: # Backwards compatability msgs.error('Requested detector {:s} has no bit mask.\n' 'Maybe you chose the wrong one to view?\n' 'Set with --det= or check file contents with --list'.format(sdet)) mask = hdu[exten].data frame = (sciimg - skymodel) * (mask == 0) mdir = head0['PYPMFDIR'] 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 trace_key = '{0}_{1:02d}'.format(head0['TRACMKEY'], args.det) trc_file = os.path.join(mdir, MasterFrame.construct_file_name('Trace', trace_key)) # TODO -- Remove this once the move to Edges is complete if args.old: tslits_dict = TraceSlits.load_from_file(trc_file)[0] else: trc_file = trc_file.replace('Trace', 'Edges')+'.gz' tslits_dict = edgetrace.EdgeTraceSet.from_file(trc_file).convert_to_tslits_dict() shape = (tslits_dict['nspec'], tslits_dict['nspat']) slit_ids = [trace_slits.get_slitid(shape, tslits_dict['slit_left'], tslits_dict['slit_righ'], ii)[0] for ii in range(tslits_dict['slit_left'].shape[1])] # Object traces spec1d_file = args.file.replace('spec2d', 'spec1d') det_nm = 'DET{:s}'.format(sdet) if os.path.isfile(spec1d_file): hdulist_1d = fits.open(spec1d_file) else: hdulist_1d = [] msgs.warn('Could not find spec1d file: {:s}'.format(spec1d_file) + msgs.newline() + ' No objects were extracted.') tslits_dict['objtrc'] = parse_traces(hdulist_1d, det_nm) # TODO :: Need to include standard star trace in the spec2d files std_trace = None # Extract some trace models fwhm = 2 # Start with some default value # Brightest object on slit trace_model_obj = None trace_model_dict = dict() if len(tslits_dict['objtrc']['pkflux']) > 0: smash_peakflux = tslits_dict['objtrc']['pkflux'] ibri = smash_peakflux.argmax() trace_model_obj = tslits_dict['objtrc']['traces'][ibri] fwhm = tslits_dict['objtrc']['fwhm'][ibri] trace_model_dict['object'] = dict(trace_model=trace_model_obj, fwhm=fwhm) # Standard star trace trace_model_dict['std'] = dict(trace_model=std_trace, fwhm=fwhm) # Trace of the slit edge trace_model_dict['slit'] = dict(trace_model=tslits_dict['slit_left'].copy(), fwhm=fwhm) tslits_dict['trace_model'] = trace_model_dict # Finally, initialise the GUI gui_object_find.initialise(args.det, frame, tslits_dict, None, printout=True, slit_ids=slit_ids)
def load_kast_blue_masters(aimg=False, tslits=False, tilts=False, wvcalib=False, pixflat=False): """ Load up the set of shane_kast_blue master frames Order is Arc, tslits_dict, tilts_dict, wv_calib, pixflat Args: get_spectrograph: aimg: tslits (bool, optional): Load the tslits_dict tilts: datasec: wvcalib: Returns: list: List of calibration items """ spectrograph = load_spectrograph('shane_kast_blue') spectrograph.naxis = (2112, 350) # Image shape with overscan master_dir = os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked', 'Shane_Kast_blue') # master_dir = root_path+'_'+spectrograph.spectrograph reuse_masters = True # Load up the Masters ret = [] # if get_spectrograph: # ret.append(spectrograph) master_key = 'A_1_01' if aimg: AImg = arcimage.ArcImage(spectrograph, master_key=master_key, master_dir=master_dir, reuse_masters=reuse_masters) msarc = AImg.load() ret.append(msarc) if tslits: trace_file = os.path.join( master_dir, MasterFrame.construct_file_name('Trace', master_key)) tslits_dict, mstrace = traceslits.TraceSlits.load_from_file(trace_file) ret.append(tslits_dict) ret.append(mstrace) if tilts: tilts_file = os.path.join( master_dir, MasterFrame.construct_file_name('Tilts', master_key)) tilts_dict = wavetilts.WaveTilts.load_from_file(tilts_file) ret.append(tilts_dict) if wvcalib: calib_file = os.path.join( master_dir, MasterFrame.construct_file_name('WaveCalib', master_key, file_format='json')) wv_calib = waveio.load_wavelength_calibration(calib_file) ret.append(wv_calib) # Pixelflat if pixflat: flatField = flatfield.FlatField( spectrograph, spectrograph.default_pypeit_par()['calibrations'] ['pixelflatframe']) calib_file = os.path.join( master_dir, MasterFrame.construct_file_name('Flat', master_key)) pixelflat = flatField.load_from_file(calib_file, 2) ret.append(pixelflat) # Return return ret
def main(args): import os import sys import astropy.io.fits as fits from pypeit.masterframe import MasterFrame from pypeit.spectrographs.util import load_spectrograph from pypeit.core import parse from pypeit.core.gui import identify as gui_identify from pypeit.core.wavecal import waveio, templates from pypeit.wavecalib import WaveCalib from pypeit import edgetrace from pypeit.images import pypeitimage # Load the MasterArc file if os.path.exists(args.file): arcfil = args.file else: try: arcfil = "Masters/{0:s}".format(args.file) except FileNotFoundError: print("Could not find MasterArc file.") sys.exit() msarc = pypeitimage.PypeItImage.from_file(arcfil) mdir = msarc.head0['MSTRDIR'] mkey = msarc.head0['MSTRKEY'] # Load the spectrograph specname = msarc.head0['PYP_SPEC'] spec = load_spectrograph(specname) par = spec.default_pypeit_par()['calibrations']['wavelengths'] # Get the lamp list if args.lamps is None: lamplist = par['lamps'] if lamplist is None: print("ERROR :: Cannot determine the lamps") sys.exit() else: lamplist = args.lamps.split(",") par['lamps'] = lamplist # Load the tslits_dict trc_file = os.path.join(mdir, MasterFrame.construct_file_name('Edges', mkey, file_format='fits.gz')) tslits_dict = edgetrace.EdgeTraceSet.from_file(trc_file).convert_to_tslits_dict() # Check if a solution exists solnname = os.path.join(mdir, MasterFrame.construct_file_name('WaveCalib', mkey, file_format='json')) wv_calib = waveio.load_wavelength_calibration(solnname) if os.path.exists(solnname) else None # Load the MasterFrame (if it exists and is desired)? wavecal = WaveCalib(msarc, tslits_dict, spec, par) arccen, arc_maskslit = wavecal.extract_arcs() binspec, binspat = parse.parse_binning(spec.get_meta_value(msarc.head0['F1'], 'binning')) # Launch the identify window arcfitter = gui_identify.initialise(arccen, slit=int(args.slit), par=par, wv_calib_all=wv_calib) final_fit = arcfitter.get_results() # Ask the user if they wish to store the result in PypeIt calibrations ans = '' while ans != 'y' and ans != 'n': ans = input("Would you like to store this wavelength solution in the archive? (y/n):") if ans == 'y' and final_fit['rms'] < 0.1: gratname = fits.getheader(msarc.head0['F1'])[spec.meta['dispname']['card']].replace("/", "_") dispangl = "UNKNOWN" templates.pypeit_identify_record(final_fit, binspec, specname, gratname, dispangl, outdir=mdir) print("Your wavelength solution has been stored") print("Please consider sending your solution to the PypeIt team!")
def load_kast_blue_masters(aimg=False, tslits=False, tilts=False, datasec=False, wvcalib=False): """ Load up the set of shane_kast_blue master frames Args: get_spectrograph: aimg: tslits: tilts: datasec: wvcalib: Returns: """ spectrograph = load_spectrograph('shane_kast_blue') spectrograph.naxis = (2112, 350) # Image shape with overscan master_dir = os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked', 'Shane_Kast_blue') # master_dir = root_path+'_'+spectrograph.spectrograph reuse_masters = True # Load up the Masters ret = [] # if get_spectrograph: # ret.append(spectrograph) master_key = 'A_1_01' if aimg: AImg = arcimage.ArcImage(spectrograph, master_key=master_key, master_dir=master_dir, reuse_masters=reuse_masters) msarc = AImg.load() ret.append(msarc) if tslits: trace_file = os.path.join( master_dir, MasterFrame.construct_file_name('Trace', master_key)) tslits_dict, mstrace = traceslits.TraceSlits.load_from_file(trace_file) ret.append(tslits_dict) ret.append(mstrace) if tilts: tilts_file = os.path.join( master_dir, MasterFrame.construct_file_name('Tilts', master_key)) tilts_dict = wavetilts.WaveTilts.load_from_file(tilts_file) ret.append(tilts_dict) if datasec: datasec_img = spectrograph.get_datasec_img(data_path('b1.fits.gz'), 1) ret.append(datasec_img) if wvcalib: calib_file = os.path.join( master_dir, MasterFrame.construct_file_name('WaveCalib', master_key, file_format='json')) wv_calib = waveio.load_wavelength_calibration(calib_file) ret.append(wv_calib) # Return return ret