Add .upsample() and .downsample() methods to MapAxis
@@ -710,6 +710,59 @@ class MapAxis:
groups.add_column(group_idx, name="group_idx", index=0)
return groups
+ def _up_down_sample(self, nbin):
+ if self.node_type == "edges":
+ nodes = self.edges
+ else:
+ nodes = self.center
+
+ lo_bnd, hi_bnd = nodes.min(), nodes.max()
+
+ return self.from_bounds(
+ lo_bnd=lo_bnd,
+ hi_bnd=hi_bnd,
+ nbin=nbin,
+ interp=self.interp,
+ node_type=self.node_type,
+ unit=self.unit
+ )
+
+ def upsample(self, factor):
+ """Upsample map axis by a given factor.
+
+ Parameters
+ ----------
+ factor : int
+ Upsampling factor.
+
+
+ Returns
+ -------
+ axis : `MapAxis`
+ Usampled map axis.
+
+ """
+ nbin = self.nbin * factor
+ return self._up_down_sample(nbin)
+
+ def downsample(self, factor):
+ """Downsample map axis by a given factor.
+
+ Parameters
+ ----------
+ factor : int
+ Downsampling factor.
+
+
+ Returns
+ -------
+ axis : `MapAxis`
+ Downsampled map axis.
+
+ """
+ nbin = int(self.nbin / factor)
+ return self._up_down_sample(nbin)
+
class MapCoord:
"""Represents a sequence of n-dimensional map coordinates.
