Skip to content

Commit d13ac61

Browse files
committed
Take axis values from master CDF as fallback if not provided by the main CDF
This fixes Speasy issue #223 Signed-off-by: Alexis Jeandet <[email protected]>
1 parent f8afce5 commit d13ac61

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

pyistp/_impl.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ def _get_attributes(master_cdf: Driver, cdf: Driver, var: str):
3434

3535

3636
def _get_axis(master_cdf: Driver, cdf: Driver, axis_var: str, data_var: str):
37-
if cdf.has_variable(axis_var):
38-
if cdf.is_char(axis_var):
37+
src_cdf = cdf if cdf.has_variable(axis_var) else master_cdf if master_cdf.has_variable(axis_var) else None
38+
if src_cdf is not None:
39+
if src_cdf.is_char(axis_var):
3940
if 'sig_digits' in master_cdf.variable_attributes(axis_var): # cluster CSA trick :/
40-
return SupportDataVariable(name=axis_var, values=np.asarray(cdf.values(axis_var), dtype=float),
41-
attributes=_get_attributes(master_cdf, cdf, axis_var),
42-
is_nrv=cdf.is_nrv(axis_var),
43-
cdf_type=cdf.cdf_type(axis_var)
41+
return SupportDataVariable(name=axis_var, values=np.asarray(src_cdf.values(axis_var), dtype=float),
42+
attributes=_get_attributes(master_cdf, src_cdf, axis_var),
43+
is_nrv=src_cdf.is_nrv(axis_var),
44+
cdf_type=src_cdf.cdf_type(axis_var)
4445
)
45-
return SupportDataVariable(name=axis_var, values=cdf.values(axis_var),
46-
attributes=_get_attributes(master_cdf, cdf, axis_var),
47-
is_nrv=cdf.is_nrv(axis_var),
48-
cdf_type=cdf.cdf_type(axis_var)
46+
return SupportDataVariable(name=axis_var, values=src_cdf.values(axis_var),
47+
attributes=_get_attributes(master_cdf, src_cdf, axis_var),
48+
is_nrv=src_cdf.is_nrv(axis_var),
49+
cdf_type=src_cdf.cdf_type(axis_var)
4950
)
5051
else:
5152
log.warning(
33.5 KB
Binary file not shown.
210 KB
Binary file not shown.

tests/test_pyistp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,15 @@ def test_get_data_variable_type(self):
117117

118118
def test_get_support_variable_type(self):
119119
istp_file = pyistp.load(file=f"{current_path}/resources/solo_l3_rpw-bia-density-10-seconds_00000000_v01.cdf")
120-
self.assertEqual(istp_file.data_variable('DENSITY').axes[0].cdf_type, 'CDF_TIME_TT2000')
120+
self.assertEqual(istp_file.data_variable('DENSITY').axes[0].cdf_type, 'CDF_TIME_TT2000')
121121

122122
def test_is_nrv(self):
123123
istp_file = pyistp.load(file=f"{current_path}/resources/solo_l3_rpw-bia-density-10-seconds_00000000_v01.cdf")
124124
self.assertFalse(istp_file.data_variable('DENSITY').axes[0].is_nrv)
125+
126+
def test_get_axis_values_from_master_as_fallback(self):
127+
# https://github.com/SciQLop/speasy/issues/223
128+
istp_file = pyistp.load(file=f"{current_path}/resources/sta_l1_het_20240103_v01.cdf",
129+
master_file=f"{current_path}/resources/sta_l1_het_00000000_v01.cdf")
130+
self.assertIsNotNone(istp_file)
131+
self.assertIsNotNone(istp_file.data_variable('Proton_Flux'))

0 commit comments

Comments
 (0)