Skip to content

Commit f3e117d

Browse files
author
Thomas Morris
committed
check map units on instantiation
1 parent 9800e77 commit f3e117d

4 files changed

Lines changed: 13 additions & 22 deletions

File tree

maria/map/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def __init__(
6565
dtype: type = np.float32,
6666
):
6767
# check that map units are valid
68-
parse_units(units)
68+
u = parse_units(units)
69+
70+
if u["physical_quantity"] not in MAP_DIMENSIONS:
71+
raise ValueError(
72+
f"Units '{units}' (with associated physical quantity '{u['physical_quantity']}') are not valid map units"
73+
)
6974

7075
self.units = units
7176
self.data = da.asarray(data).astype(dtype)
@@ -264,7 +269,7 @@ def to(self, units: str, **calibration_kwargs: Mapping):
264269

265270
if u["physical_quantity"] not in MAP_DIMENSIONS:
266271
raise ValueError(
267-
f"Units '{units}' (with associated quantity '{u['physical_quantity']}') are not valid map units"
272+
f"Units '{units}' (with associated physical quantity '{u['physical_quantity']}') are not valid map units"
268273
)
269274

270275
package = self.package().copy()

maria/tests/map/test_map_units.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"map_path",
1717
all_maps,
1818
) # noqa
19-
def test_map_io_units(map_path):
19+
def test_map_units(map_path):
2020
m = maria.map.load(fetch(map_path))
2121
if "nu" not in m.dims:
2222
m = m.unsqueeze("nu", 150e9)
@@ -36,18 +36,3 @@ def test_map_io_units(map_path):
3636
assert np.allclose(new_m_fits.resolution.arcsec, m.resolution.arcsec)
3737

3838
m.plot()
39-
40-
41-
def test_map_extend():
42-
map_filename = fetch("maps/cluster1.fits")
43-
44-
m1 = maria.map.load(filename=map_filename, nu=90e9)
45-
m2 = maria.map.load(filename=map_filename, nu=150e9)
46-
m3 = maria.map.load(filename=map_filename, nu=220e9)
47-
48-
m4 = m1.extend([m2, m3], dim="nu").unsqueeze("stokes")
49-
m5, m6 = m4.copy(), m4.copy()
50-
m5.stokes = "Q"
51-
m6.stokes = "U"
52-
53-
m4.extend([m5, m6], dim="stokes")

maria/units/physical_quantities/base.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ temperature:
121121
beam:
122122
long_name: beam
123123
short_name: beam
124-
math_name: beam
124+
math_name: \text{beam}
125125
base_unit: beam
126126
base_unit_prefix: ""
127127
vector:
@@ -132,14 +132,14 @@ beam:
132132
aliases:
133133
- BEAM
134134
long_name: beam
135-
math_name: beam
135+
math_name: \text{beam}
136136
min_prefix_power: 0
137137
max_prefix_power: 0
138138

139139
pixel:
140140
long_name: pixel
141141
short_name: pixel
142-
math_name: pixel
142+
math_name: \text{pixel}
143143
base_unit: pixel
144144
base_unit_prefix: ""
145145
vector:
@@ -150,7 +150,7 @@ pixel:
150150
aliases:
151151
- PIXEL
152152
long_name: pixel
153-
math_name: pixel
153+
math_name: \text{pixel}
154154
min_prefix_power: 0
155155
max_prefix_power: 0
156156

maria/units/quantity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def repr_power(thing: str, power: float, math: bool = False):
6767
return ""
6868
if power == 1:
6969
return thing
70+
7071
return f"{thing}^{exp_string}"
7172

7273

0 commit comments

Comments
 (0)