Add energy equivalencey check
@@ -419,9 +419,8 @@ class MapAxis:
"""
energy_edges = u.Quantity(energy_edges, unit)
- if unit is None:
- unit = energy_edges.unit
- energy_edges = energy_edges.to(unit)
+ if not energy_edges.unit.is_equivalent("TeV"):
+ raise ValueError(f"Please provide a valid energy unit, got {energy_edges.unit} instead.")
if name is None:
name = "energy"
@@ -472,6 +471,9 @@ class MapAxis:
unit = energy_max.unit
energy_min = energy_min.to(unit)
+ if not energy_max.unit.is_equivalent("TeV"):
+ raise ValueError(f"Please provide a valid energy unit, got {energy_max.unit} instead.")
+
if per_decade:
nbin = np.ceil(np.log10(energy_max / energy_min).value * nbin)
