Example #1
0
    def find_objects_pypeline(self,
                              image,
                              std=False,
                              std_trace=None,
                              maskslits=None,
                              show=False,
                              show_peaks=False,
                              show_fits=False,
                              show_trace=False,
                              debug=False,
                              manual_extract_dict=None):
        # For echelle orders
        slit_spat_pos = trace_slits.slit_spat_pos(self.tslits_dict)

        # create the ouptut image for skymask
        skymask = np.zeros_like(image, dtype=bool)

        order_vec = self.spectrograph.order_vec(slit_spat_pos)
        plate_scale = self.spectrograph.order_platescale(order_vec,
                                                         binning=self.binning)
        inmask = self.sciImg.mask == 0
        # Find objects
        specobj_dict = {
            'setup': self.setup,
            'slitid': 999,
            'orderindx': 999,
            'det': self.det,
            'objtype': self.objtype,
            'pypeline': self.pypeline
        }
        # ToDO implement parsets here!
        sig_thresh = 30.0 if std else self.redux_par['sig_thresh']
        sobjs_ech, skymask[self.slitmask > -1] = \
            extract.ech_objfind(image, self.sciImg.ivar, self.slitmask, self.tslits_dict['slit_left'], self.tslits_dict['slit_righ'],
                                inmask=inmask, ncoeff=self.redux_par['trace_npoly'],
                                order_vec=order_vec,
                                hand_extract_dict=manual_extract_dict,
                                plate_scale=plate_scale, std_trace=std_trace,
                                specobj_dict=specobj_dict,sig_thresh=sig_thresh,
                                show_peaks=show_peaks, show_fits=show_fits,
                                trim_edg=self.redux_par['find_trim_edge'],
                                show_trace=show_trace, debug=debug)

        # Steps
        self.steps.append(inspect.stack()[0][3])
        if show:
            self.show('image',
                      image=image * (self.sciImg.mask == 0),
                      chname='ech_objfind',
                      sobjs=sobjs_ech,
                      slits=False)

        return sobjs_ech, len(sobjs_ech), skymask
Example #2
0
    def _fill_tslits_dict(self):
        """
        Build a simple dictionary holding the key trace bits and pieces that PypeIt wants

        Returns:
            dict: Trace slits dict

        """
        self.tslits_dict = {}

        # Have the slit boundaries been tweaked? If so use the tweaked
        # boundaries.  TODO: Have the dict keys have the same name as
        # the attribute
        self.tslits_dict['slit_left_orig'] = self.slit_left
        self.tslits_dict['slit_righ_orig'] = self.slit_righ

        if self.slit_left_tweak is not None:
            self.tslits_dict['slit_left_tweak'] = self.slit_left_tweak
            self.tslits_dict['slit_righ_tweak'] = self.slit_righ_tweak

            self.tslits_dict['slit_left'] = self.slit_left_tweak
            self.tslits_dict['slit_righ'] = self.slit_righ_tweak
        else:
            self.tslits_dict['slit_left'] = self.slit_left
            self.tslits_dict['slit_righ'] = self.slit_righ

        # Fill in the rest of the keys that were generated by
        # make_pixel_arrays from the slit boundaries. This was done with
        # tweaked boundaries if they exist.  TODO: Some of these
        # quantities may be deprecated.

        #for key in ['slitcen', 'pixwid', 'lordpix','rordpix', 'extrapord']:
        #    self.tslits_dict[key] = getattr(self, key)
        # add in the image size and some stuff to create the slitmask

        self.tslits_dict['maskslits'] = self.maskslits
        self.tslits_dict['slitcen'] = self.slitcen
        self.tslits_dict['nspec'] = self.mstrace.shape[0]
        self.tslits_dict['nspat'] = self.mstrace.shape[1]
        self.tslits_dict['nslits'] = self.slit_left.shape[1]
        self.tslits_dict['pad'] = self.par['pad']
        binspectral, binspatial = parse.parse_binning(self.binning)
        self.tslits_dict['binspectral'] = binspectral
        self.tslits_dict['binspatial'] = binspatial
        self.tslits_dict['spectrograph'] = self.spectrograph.spectrograph
        slit_spat_pos = trace_slits.slit_spat_pos(self.tslits_dict)
        spec_min_max = self.spectrograph.slit_minmax(slit_spat_pos, binspectral = binspectral)
        self.tslits_dict['spec_min'], self.tslits_dict['spec_max'] = spec_min_max[0, :], spec_min_max[1, :]
        # Now extrapolate the traces JFH turning this off for now.
        #self.tslits_dict['slit_left'] = trace_slits.extrapolate_trace(self.tslits_dict['slit_left'], spec_min_max)
        #self.tslits_dict['slit_righ'] = trace_slits.extrapolate_trace(self.tslits_dict['slit_righ'], spec_min_max)

        return self.tslits_dict
Example #3
0
    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
Example #4
0
    def __init__(self,
                 msarc,
                 tslits_dict,
                 spectrograph,
                 par,
                 binspectral=None,
                 det=1,
                 master_key=None,
                 master_dir=None,
                 reuse_masters=False,
                 qa_path=None,
                 msbpm=None):

        # MasterFrame
        masterframe.MasterFrame.__init__(self,
                                         self.master_type,
                                         master_dir=master_dir,
                                         master_key=master_key,
                                         file_format='json',
                                         reuse_masters=reuse_masters)

        # Required parameters (but can be None)
        self.msarc = msarc
        self.tslits_dict = tslits_dict
        self.spectrograph = spectrograph
        self.par = par

        # Optional parameters
        self.bpm = msbpm
        self.binspectral = binspectral
        self.qa_path = qa_path
        self.det = det
        self.master_key = master_key

        # Attributes
        self.steps = []  # steps executed
        self.wv_calib = {}  # main output
        self.arccen = None  # central arc spectrum

        # --------------------------------------------------------------
        # TODO: Build another base class that does these things for both
        # WaveTilts and WaveCalib?

        # Get the non-linear count level
        self.nonlinear_counts = 1e10 if self.spectrograph is None \
                                    else self.spectrograph.nonlinear_counts(det=self.det)

        # Set the slitmask and slit boundary related attributes that the
        # code needs for execution. This also deals with arcimages that
        # have a different binning then the trace images used to defined
        # the slits
        if self.tslits_dict is not None and self.msarc is not None:
            self.slitmask_science = pixels.tslits2mask(self.tslits_dict)
            inmask = self.bpm == 0 if self.bpm is not None \
                                    else np.ones_like(self.slitmask_science, dtype=bool)
            self.shape_science = self.slitmask_science.shape
            self.shape_arc = self.msarc.shape
            self.nslits = self.tslits_dict['slit_left'].shape[1]
            self.slit_left = arc.resize_slits2arc(
                self.shape_arc, self.shape_science,
                self.tslits_dict['slit_left'])
            self.slit_righ = arc.resize_slits2arc(
                self.shape_arc, self.shape_science,
                self.tslits_dict['slit_righ'])
            self.slitcen = arc.resize_slits2arc(self.shape_arc,
                                                self.shape_science,
                                                self.tslits_dict['slitcen'])
            self.slitmask = arc.resize_mask2arc(self.shape_arc,
                                                self.slitmask_science)
            self.inmask = arc.resize_mask2arc(self.shape_arc, inmask)
            # TODO: Remove the following two lines if deemed ok
            if self.par['method'] != 'full_template':
                self.inmask &= self.msarc < self.nonlinear_counts
            self.slit_spat_pos = trace_slits.slit_spat_pos(self.tslits_dict)
        else:
            self.slitmask_science = None
            self.shape_science = None
            self.shape_arc = None
            self.nslits = 0
            self.slit_left = None
            self.slit_righ = None
            self.slitcen = None
            self.slitmask = None
            self.inmask = None
Example #5
0
    def local_skysub_extract(self,
                             waveimg,
                             global_sky,
                             sobjs,
                             spat_pix=None,
                             model_noise=True,
                             min_snr=2.0,
                             std=False,
                             fit_fwhm=False,
                             maskslits=None,
                             show_profile=False,
                             show_resids=False,
                             show_fwhm=False,
                             show=False):
        """
        Perform local sky subtraction, profile fitting, and optimal extraction slit by slit

        Wrapper to skysub.local_skysub_extract

        Parameters
        ----------
        sobjs: object
           Specobjs object containing Specobj objects containing information about objects found.
        waveimg: ndarray, shape (nspec, nspat)
           Wavelength map

        Optional Parameters
        -------------------

        Returns:
            global_sky: (numpy.ndarray) image of the the global sky model
        """

        self.waveimg = waveimg
        self.global_sky = global_sky

        # For echelle orders
        slit_spat_pos = trace_slits.slit_spat_pos(self.tslits_dict)
        order_vec = self.spectrograph.order_vec(slit_spat_pos)
        #
        plate_scale = self.spectrograph.order_platescale(order_vec,
                                                         binning=self.binning)
        self.skymodel, self.objmodel, self.ivarmodel, self.outmask, self.sobjs = skysub.ech_local_skysub_extract(
            self.sciImg.image,
            self.sciImg.ivar,
            self.sciImg.mask,
            self.tilts,
            self.waveimg,
            self.global_sky,
            self.sciImg.rn2img,
            self.tslits_dict,
            sobjs,
            order_vec,
            spat_pix=spat_pix,
            std=std,
            fit_fwhm=fit_fwhm,
            min_snr=min_snr,
            bsp=self.redux_par['bspline_spacing'],
            box_rad_order=self.redux_par['boxcar_radius'] / plate_scale,
            sigrej=self.redux_par['sky_sigrej'],
            sn_gauss=self.redux_par['sn_gauss'],
            model_full_slit=self.redux_par['model_full_slit'],
            model_noise=model_noise,
            show_profile=show_profile,
            show_resids=show_resids,
            show_fwhm=show_fwhm)

        # Step
        self.steps.append(inspect.stack()[0][3])

        if show:
            self.show('local',
                      sobjs=self.sobjs,
                      slits=True,
                      chname='ech_local')
            self.show('resid',
                      sobjs=self.sobjs,
                      slits=True,
                      chname='ech_resid')

        return self.skymodel, self.objmodel, self.ivarmodel, self.outmask, self.sobjs