예제 #1
0
    def _update_queryable_if_get_cost(self, light_curve_data: LightCurve,
                                      telescope_names: list,
                                      telescope_sizes: list,
                                      spectroscopic_snr: int,
                                      **kwargs) -> LightCurve:
        """
        Updates time required to take a spectra calc_exp_time() method of
        LightCurve class

        Parameters
        ----------
        light_curve_data
            An instance of LightCurve class
        telescope_names
            Names of the telescopes under consideration for spectroscopy.
            Only used if "get_cost == True".
            Default is ["4m", "8m"].
        telescope_sizes
            Primary mirrors diameters of potential spectroscopic telescopes.
            Only used if "get_cost == True".
            Default is [4, 8].
        spectroscopic_snr
            SNR required for spectroscopic follow-up. Default is 10.
        kwargs
            Any input required by ExpTimeCalc.findexptime function.
        """
        for index in range(self._number_of_telescopes):
            light_curve_data.calc_exp_time(
                telescope_diam=telescope_sizes[index],
                telescope_name=telescope_names[index],
                SNR=spectroscopic_snr,
                **kwargs)

        return light_curve_data
예제 #2
0
    def _get_features_to_write(self, light_curve_data_day: LightCurve,
                               get_cost: bool, telescope_names: list) -> list:
        """
        Returns features list to write

        Parameters
        ----------
        light_curve_data_day
            fitted light curve data of current snid
        get_cost
           if cost of taking a spectra is computed
        telescope_names
            Names of the telescopes under consideration for spectroscopy.
            Only used if "get_cost == True".
            Default is ["4m", "8m"].
        """
        light_curve_data_day.sntype = PLASTICC_TARGET_TYPES[
            light_curve_data_day.sncode]
        light_curve_data_day.sample = 'pool'
        features_list = [
            light_curve_data_day.id, light_curve_data_day.redshift,
            light_curve_data_day.sntype, light_curve_data_day.sncode,
            light_curve_data_day.sample, light_curve_data_day.queryable,
            light_curve_data_day.last_mag
        ]

        if get_cost:
            for index in range(self._number_of_telescopes):
                features_list.append(
                    str(light_curve_data_day.exp_time[telescope_names[index]]))
        features_list.extend(light_curve_data_day.bazin_features)

        return features_list
예제 #3
0
    def _load_plasticc_data(self,
                            raw_data_dir: str,
                            volume: int,
                            snid: int,
                            sample='test') -> LightCurve:
        """
        Loads PLAsTiCC dataset files to LightCurve class
        
        Parameters
        ----------
        raw_data_dir
            Complete path to all PLAsTiCC zenodo files.
        snid: int
            Object id for the transient to be fitted.
        vol: int (optional)
            Index of the original PLAsTiCC zenodo light curve
            files where the photometry for this object is stored.
        sample: str (optional)
            Sample to load, 'train' or 'test'. Default is 'test'.
        """
        light_curve_data = LightCurve()

        if sample == 'test':
            file_name = os.path.join(raw_data_dir,
                                     self._file_list_dict['test'][volume - 1])

        else:
            file_name = os.path.join(raw_data_dir,
                                     self._file_list_dict['train'][0])
        light_curve_data.load_plasticc_lc(file_name, snid)

        return light_curve_data
예제 #4
0
    def get_lim_mjds(self, raw_data_dir: str) -> list:
        """
        Get minimum and maximum MJD for complete sample.

        This function is not necessary if you are working with
        SNPCC data. The values are hard coded in the class.

        Parameters
        ----------
        raw_data_dir: str
            Complete path to raw data directory.

        Returns
        -------
        limits: list
            List of extreme MJDs for entire sample: [min_MJD, max_MJD].
        """
        files_list = _get_files_list(raw_data_dir, 'DES_SN')
        # store MJDs
        min_day = []
        max_day = []

        for each_file in progressbar.progressbar(files_list):
            light_curve_data = LightCurve()
            light_curve_data.load_snpcc_lc(
                os.path.join(raw_data_dir, each_file))
            min_day.append(min(light_curve_data.photometry['mjd'].values))
            max_day.append(max(light_curve_data.photometry['mjd'].values))
            self.min_epoch = min(min_day)
            self.max_epoch = max(max_day)

        return [min(min_day), max(max_day)]
예제 #5
0
    def _update_light_curve_meta_data(self, light_curve_data_day: LightCurve,
                                      snid: int) -> Union[LightCurve, None]:
        """
        Loads light curve data of the given SNID

        Parameters
        ----------
        light_curve_data_day
            An instance of LightCurve class instance of the data
        snid
            Object id for the transient to be fitted.

        Returns
        -------
        light_curve_data_day
            LightCurve class data for the given SNID
        """
        if light_curve_data_day is not None:
            snid_mask = self.metadata['object_id'].values == snid
            if np.sum(snid_mask) > 0:
                light_curve_data_day.redshift = self.metadata['true_z'].values[
                    snid_mask][0]
                light_curve_data_day.sncode = (
                    self.metadata['true_target'].values[snid_mask][0])
                light_curve_data_day.id = snid

                return light_curve_data_day

        return None
예제 #6
0
    def _process_current_day(
            self, light_curve_data_day: LightCurve, queryable_criteria: int,
            days_since_last_observation: int, telescope_names: list,
            telescope_sizes: list, spectroscopic_snr: int,
            min_available_points: int = 4, **kwargs):
        """
        Processes data for current day

        Parameters
        ----------
        light_curve_data_day
            An instance of LightCurve class
        queryable_criteria
            Criteria to determine if an obj is queryable.
            1 -> r-band cut on last measured photometric point.
            2 -> last obs was further than a given limit,
                 use Bazin estimate of flux today. Otherwise, use
                 the last observed point.
        days_since_last_observation
            Day since last observation to consider for spectroscopic
            follow-up without the need to extrapolate light curve.
        telescope_names
            Names of the telescopes under consideration for spectroscopy.
            Only used if "get_cost == True".
        telescope_sizes
            Primary mirrors diameters of potential spectroscopic telescopes.
            Only used if "get_cost == True".
        spectroscopic_snr
            SNR required for spectroscopic follow-up.
        kwargs
            Any input required by ExpTimeCalc.findexptime function.
        min_available_points
            minimum number of survived points
        """
        photo_flag = (
                light_curve_data_day.photometry['mjd'].values <= self._today)

        if np.sum(photo_flag) > min_available_points:
            light_curve_data_day.photometry = light_curve_data_day.photometry[
                photo_flag]
            light_curve_data_day.fit_bazin_all()

            if (len(light_curve_data_day.bazin_features) > 0 and
                    'None' not in light_curve_data_day.bazin_features):

                light_curve_data_day.queryable = self._check_queryable(
                    light_curve_data_day, queryable_criteria,
                    days_since_last_observation)
                light_curve_data_day = self._update_queryable_if_get_cost(
                    light_curve_data_day, telescope_names, telescope_sizes,
                    spectroscopic_snr, **kwargs)
                light_curve_data_day.queryable = bool(sum(get_query_flags(
                    light_curve_data_day, telescope_names
                )))

                return light_curve_data_day

        return None
예제 #7
0
    def _process_each_light_curve(
            self,
            light_curve_data: LightCurve,
            queryable_criteria: int,
            days_since_last_observation: int,
            telescope_names: list,
            telescope_sizes: list,
            spectroscopic_snr: int,
            kwargs: dict,
            min_available_points: int = 5) -> Union[LightCurve, None]:
        """
        Processes each light curve files.

        Parameters
        ----------
        light_curve_data: resspect.LightCurve
            An instance of LightCurve class
        queryable_criteria: int
            Criteria to determine if an obj is queryable.
            1 -> r-band cut on last measured photometric point.
            2 -> last obs was further than a given limit,
                 use Bazin estimate of flux today. Otherwise, use
                 the last observed point.
        days_since_last_observation: int
            Day since last observation to consider for spectroscopic
            follow-up without the need to extrapolate light curve.
        telescope_names: list
            Names of the telescopes under consideration for spectroscopy.
            Only used if "get_cost == True".
        telescope_sizes: list
            Primary mirrors diameters of potential spectroscopic telescopes.
            Only used if "get_cost == True".
        spectroscopic_snr: int
            SNR required for spectroscopic follow-up.
        kwargs: dict (optional)
            Any input required by ExpTimeCalc.findexptime function.
        min_available_points: int (optional)
            minimum number of survived points. Default is 5.
        """
        photo_flag = light_curve_data.photometry['mjd'].values <= self._today
        if sum(photo_flag) >= min_available_points:
            light_curve_data.photometry = light_curve_data.photometry[
                photo_flag]
            light_curve_data.fit_bazin_all()

            if (len(light_curve_data.bazin_features) > 0
                    and 'None' not in light_curve_data.bazin_features):
                light_curve_data.queryable = self._check_queryable(
                    light_curve_data, queryable_criteria,
                    days_since_last_observation)
                light_curve_data = self._update_queryable_if_get_cost(
                    light_curve_data, telescope_names, telescope_sizes,
                    spectroscopic_snr, kwargs)
                light_curve_data.queryable = bool(
                    sum(get_query_flags(light_curve_data, telescope_names)))
                return light_curve_data
        return None
예제 #8
0
    def _check_queryable(self, light_curve_data: LightCurve,
                         queryable_criteria: int,
                         days_since_last_observation: int) -> bool:
        """
        Applies check_queryable method of LightCurve class

        Parameters
        ----------
        light_curve_data
            An instance of LightCurve class
        queryable_criteria: [1 or 2]
            Criteria to determine if an obj is queryable.
            1 -> r-band cut on last measured photometric point.
            2 -> last obs was further than a given limit,
                 use Bazin estimate of flux today. Otherwise, use
                 the last observed point.
            Default is 1.
        days_since_last_observation
            Day since last observation to consider for spectroscopic
            follow-up without the need to extrapolate light curve.
        """
        return light_curve_data.check_queryable(
            mjd=self._today,
            filter_lim=self.rmag_lim,
            criteria=queryable_criteria,
            days_since_last_obs=days_since_last_observation)
예제 #9
0
    def _update_light_curve_meta_data(self, light_curve_data_day: LightCurve,
                                      snid: int) -> Union[LightCurve, None]:
        """ Add docstring!!!
        """

        if light_curve_data_day is not None:
            snid_mask = self.metadata['object_id'].values == snid
            if np.sum(snid_mask) > 0:
                light_curve_data_day.redshift = self.metadata['true_z'].values[
                    snid_mask][0]
                light_curve_data_day.sncode = (
                    self.metadata['true_target'].values[snid_mask][0])
                light_curve_data_day.id = snid

                return light_curve_data_day

        return None
예제 #10
0
    def _get_current_sample_features(self, file_name: str, raw_data_dir: str,
                                     queryable_criteria: int,
                                     days_since_observation: int,
                                     telescope_names: list,
                                     telescope_sizes: list,
                                     spec_SNR: int) -> LightCurve:
        """
        Reads a SNPCC file and updates time domain features

        Parameters
        ----------
        file_name
            SNPCC file name
        raw_data_dir: str
            Complete path to raw data directory
        queryable_criteria: int [1 or 2] (optional)
            Criteria to determine if an obj is queryable.
            1 -> r-band cut on last measured photometric point.
            2 -> last obs was further than a given limit,
                 use Bazin estimate of flux today. Otherwise, use
                 the last observed point.
            Default is 1.
        days_since_observation: int (optional)
            Day since last observation to consider for spectroscopic
            follow-up without the need to extrapolate light curve.
            Only used if "queryable_criteria == 2". Default is 2.
        telescope_names: list (optional)
            Names of the telescopes under consideration for spectroscopy.
            Only used if "get_cost == True".
            Default is ["4m", "8m"].
        telescope_sizes: list (optional)
            Primary mirrors diameters of potential spectroscopic telescopes.
            Only used if "get_cost == True".
            Default is [4, 8].
        spec_SNR: float (optional)
            SNR required for spectroscopic follow-up. Default is 10.
        """
        light_curve_data = LightCurve()
        light_curve_data.load_snpcc_lc(os.path.join(raw_data_dir, file_name))
        light_curve_data = self._process_each_light_curve(
            light_curve_data, queryable_criteria, days_since_observation,
            telescope_names, telescope_sizes, spec_SNR, self._kwargs)
        return light_curve_data