Ejemplo n.º 1
0
    def _make_source_object(self, index):
        """Make one source object.

        Parameters
        ----------
        index : int
            Row index

        Returns
        -------
        source : `SourceCatalogObject`
            Source object
        """
        data = table_row_to_dict(self.table[index])
        data[SourceCatalogObject._row_index_key] = index

        if "Extended_Source_Name" in data:
            name_extended = data["Extended_Source_Name"].strip()
        elif "Source_Name" in data:
            name_extended = data["Source_Name"].strip()
        else:
            name_extended = None
        try:
            idx = self._lookup_extended_source_idx[name_extended]
            data_extended = table_row_to_dict(self.extended_sources_table[idx])
        except (KeyError, AttributeError):
            data_extended = None

        source = self.source_object_class(data, data_extended)
        return source
Ejemplo n.º 2
0
    def _make_source_object(self, index):
        """Make one source object.

        Parameters
        ----------
        index : int
            Row index

        Returns
        -------
        source : `SourceCatalogObject`
            Source object
        """
        data = table_row_to_dict(self.table[index])
        data[SourceCatalogObject._row_index_key] = index

        fp_energy_edges = getattr(self, "flux_points_energy_edges", None)

        if fp_energy_edges:
            data["fp_energy_edges"] = fp_energy_edges

        hist_table = getattr(self, "hist_table", None)
        hist2_table = getattr(self, "hist2_table", None)

        if hist_table:
            try:
                data["time_axis"] = TimeMapAxis.from_table(hist_table,
                                                           format="fermi-fgl")
            except KeyError:
                pass

        if hist2_table:
            try:
                data["time_axis_2"] = TimeMapAxis.from_table(
                    hist2_table, format="fermi-fgl")
            except KeyError:
                pass
        if "Extended_Source_Name" in data:
            name_extended = data["Extended_Source_Name"].strip()
        elif "Source_Name" in data:
            name_extended = data["Source_Name"].strip()
        else:
            name_extended = None
        try:
            idx = self._lookup_extended_source_idx[name_extended]
            data_extended = table_row_to_dict(self.extended_sources_table[idx])
        except (KeyError, AttributeError):
            data_extended = None

        source = self.source_object_class(data, data_extended)
        return source
Ejemplo n.º 3
0
    def obs(self, obs_id):
        """Access a given `~gammapy.data.Observation`.

        Parameters
        ----------
        obs_id : int
            Observation ID.

        Returns
        -------
        observation : `~gammapy.data.Observation`
            Observation container
        """
        if obs_id not in self.obs_table["OBS_ID"]:
            raise ValueError(f"OBS_ID = {obs_id} not in obs index table.")

        if obs_id not in self.hdu_table["OBS_ID"]:
            raise ValueError(f"OBS_ID = {obs_id} not in HDU index table.")

        row = self.obs_table.select_obs_id(obs_id=obs_id)[0]
        kwargs = {"obs_id": int(obs_id)}
        kwargs["obs_info"] = table_row_to_dict(row)

        hdu_list = ["events", "gti", "aeff", "edisp", "psf", "bkg"]
        for hdu in hdu_list:
            kwargs[hdu] = self.hdu_table.hdu_location(obs_id=obs_id,
                                                      hdu_type=hdu)

        return Observation(**kwargs)
Ejemplo n.º 4
0
    def estimate_time_bin_flux(self, datasets):
        """Estimate flux point for a single energy group.

        Parameters
        ----------
        datasets : `~gammapy.modeling.Datasets`
            the list of dataset object

        Returns
        -------
        result : dict
            Dict with results for the flux point.
        """
        if self.e_edges is None:
            e_mins, e_maxs = datasets.energy_ranges
            e_edges = e_mins.min(), e_maxs.max()
        else:
            e_edges = self.e_edges

        fe = FluxPointsEstimator(
            source=self.source,
            e_edges=e_edges,
            norm_min=self.norm_min,
            norm_max=self.norm_max,
            norm_n_values=self.norm_n_values,
            norm_values=self.norm_values,
            n_sigma=self.n_sigma,
            n_sigma_ul=self.n_sigma_ul,
            reoptimize=self.reoptimize,
            selection_optional=self.selection_optional,
        )
        result = fe.run(datasets)
        return table_row_to_dict(result.table[0])
Ejemplo n.º 5
0
    def obs(self, obs_id):
        """Access a given `~gammapy.data.Observation`.

        Parameters
        ----------
        obs_id : int
            Observation ID.

        Returns
        -------
        observation : `~gammapy.data.Observation`
            Observation container
        """
        if obs_id not in self.obs_table["OBS_ID"]:
            raise ValueError(f"OBS_ID = {obs_id} not in obs index table.")

        if obs_id not in self.hdu_table["OBS_ID"]:
            raise ValueError(f"OBS_ID = {obs_id} not in HDU index table.")

        row = self.obs_table.select_obs_id(obs_id=obs_id)[0]
        obs_info = table_row_to_dict(row)

        aeff_hdu = self.hdu_table.hdu_location(obs_id=obs_id, hdu_type="aeff")
        edisp_hdu = self.hdu_table.hdu_location(obs_id=obs_id,
                                                hdu_type="edisp")
        bkg_hdu = self.hdu_table.hdu_location(obs_id=obs_id, hdu_type="bkg")
        psf_hdu = self.hdu_table.hdu_location(obs_id=obs_id, hdu_type="psf")
        events_hdu = self.hdu_table.hdu_location(obs_id=obs_id,
                                                 hdu_type="events")
        gti_hdu = self.hdu_table.hdu_location(obs_id=obs_id, hdu_type="gti")

        return Observation(
            obs_id=int(obs_id),
            obs_info=obs_info,
            bkg=bkg_hdu,
            aeff=aeff_hdu,
            edisp=edisp_hdu,
            events=events_hdu,
            gti=gti_hdu,
            psf=psf_hdu,
        )
Ejemplo n.º 6
0
    def obs(self, obs_id):
        """Access a given `~gammapy.data.Observation`.

        Parameters
        ----------
        obs_id : int
            Observation ID.

        Returns
        -------
        observation : `~gammapy.data.Observation`
            Observation container
        """
        if obs_id not in self.obs_table["OBS_ID"]:
            raise ValueError(f"OBS_ID = {obs_id} not in obs index table.")

        if obs_id not in self.hdu_table["OBS_ID"]:
            raise ValueError(f"OBS_ID = {obs_id} not in HDU index table.")

        row = self.obs_table.select_obs_id(obs_id=obs_id)[0]
        kwargs = {"obs_id": int(obs_id)}

        # add info from table meta, e.g. the time references
        kwargs["obs_info"] = {
            k: v
            for k, v in self.obs_table.meta.items()
            if not k.startswith('HDU')  # Ignore GADF structure of index table
        }
        kwargs["obs_info"].update(table_row_to_dict(row))

        hdu_list = ["events", "gti", "aeff", "edisp", "psf", "bkg", "rad_max"]

        for hdu in hdu_list:
            kwargs[hdu] = self.hdu_table.hdu_location(obs_id=obs_id,
                                                      hdu_type=hdu)

        return Observation(**kwargs)
Ejemplo n.º 7
0
 def gaussian_component(self, row_idx):
     """Gaussian component (`SourceCatalogObjectHGPSComponent`)."""
     data = table_row_to_dict(self.table_components[row_idx])
     data[SourceCatalogObject._row_index_key] = row_idx
     return SourceCatalogObjectHGPSComponent(data=data)
Ejemplo n.º 8
0
 def _attach_identification_info(self, source):
     t = self._table_identifications
     idx = np.nonzero(source.name == t["Source_Name"])[0][0]
     source.identification_info = table_row_to_dict(t[idx])
Ejemplo n.º 9
0
 def obs_info(self):
     """Observation information (`~collections.OrderedDict`)."""
     row = self.data_store.obs_table.select_obs_id(obs_id=self.obs_id)[0]
     return table_row_to_dict(row)
Ejemplo n.º 10
0
def test_table_row_to_dict(table):
    actual = table_row_to_dict(table[1])
    expected = {"a": 2, "b": 2 * u.m, "c": "yy"}
    assert actual == expected
Ejemplo n.º 11
0
def test_table_row_to_dict(table):
    actual = table_row_to_dict(table[1])
    expected = OrderedDict([("a", 2), ("b", 2 * u.m), ("c", "yy")])
    assert actual == expected