Skip to content

Commit

Permalink
lightcurve class addition
Browse files Browse the repository at this point in the history
Signed-off-by: cgalelli <[email protected]>
  • Loading branch information
cgalelli committed Jan 17, 2024
1 parent 1ccca32 commit b61972d
Showing 1 changed file with 4 additions and 44 deletions.
48 changes: 4 additions & 44 deletions gammapy/maps/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2672,53 +2672,13 @@ def group_table(self, edges):
groups : `~astropy.table.Table`
Map axis group table.
"""
# TODO: try to simplify this code
if self.node_type != "edges":
raise ValueError("Only edge based map axis can be grouped")

edges_pix = self.coord_to_pix(edges)
edges_pix = np.clip(edges_pix, -0.5, self.nbin - 0.5)
edges_idx = np.round(edges_pix + 0.5) - 0.5
edges_idx = np.unique(edges_idx)
edges_ref = self.pix_to_coord(edges_idx)

groups = Table()
groups[f"{self.name}_min"] = edges_ref[:-1]
groups[f"{self.name}_max"] = edges_ref[1:]

groups["idx_min"] = (edges_idx[:-1] + 0.5).astype(int)
groups["idx_max"] = (edges_idx[1:] - 0.5).astype(int)

if len(groups) == 0:
raise ValueError("No overlap between reference and target edges.")

groups["bin_type"] = "normal "

edge_idx_start, edge_ref_start = edges_idx[0], edges_ref[0]
if edge_idx_start > 0:
underflow = {
"bin_type": "underflow",
"idx_min": 0,
"idx_max": edge_idx_start,
f"{self.name}_min": self.pix_to_coord(-0.5),
f"{self.name}_max": edge_ref_start,
}
groups.insert_row(0, vals=underflow)
edges = self.reference_time + edges

edge_idx_end, edge_ref_end = edges_idx[-1], edges_ref[-1]
gti = self.to_gti()

if edge_idx_end < (self.nbin - 0.5):
overflow = {
"bin_type": "overflow",
"idx_min": edge_idx_end + 1,
"idx_max": self.nbin - 1,
f"{self.name}_min": edge_ref_end,
f"{self.name}_max": self.pix_to_coord(self.nbin - 0.5),
}
groups.add_row(vals=overflow)
time_intervals = [(edges[i], edges[i + 1]) for i in range(len(edges) - 1)]
groups = gti.group_table(time_intervals)

group_idx = Column(np.arange(len(groups)))
groups.add_column(group_idx, name="group_idx", index=0)
return groups

def upsample(self):
Expand Down

0 comments on commit b61972d

Please sign in to comment.