Skip to content

Commit 943c0b4

Browse files
Copilotilaflott
andcommitted
fix: resolve omission tracking clash and propagate new varlist semantics to fremor varlist
Agent-Logs-Url: https://github.com/ilaflott/fremorizer/sessions/304fca42-4857-4273-b4a4-593c56eccc48 Co-authored-by: ilaflott <6273252+ilaflott@users.noreply.github.com>
1 parent 056329c commit 943c0b4

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

fremorizer/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def run(indir, varlist, table_config, exp_config, outdir, run_one, opt_var_name,
236236
stop = stop,
237237
calendar_type = calendar
238238
)
239-
if result != 0:
239+
if result < 0:
240240
raise click.ClickException(f'cmor_run_subtool returned non-zero status: {result}')
241241

242242

fremorizer/cmor_finder.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,19 @@ def make_simple_varlist( dir_targ: str,
184184
# Build a deduplicated dict of variable names extracted from all filenames across
185185
# all datetimes. Assigning to a dict naturally deduplicates while preserving
186186
# first-seen insertion order (Python 3.7+).
187+
# If a MIP table is provided, variables that match a MIP variable name get
188+
# self-mapped (key==value). Variables NOT in the MIP table get an empty string
189+
# as value, signaling they need manual mapping by the user.
187190
var_list: Dict[str, str] = {}
188191
for targetfile in all_nc_files:
189192
var_name=os.path.basename(targetfile).split('.')[-2]
190-
if mip_vars is not None and var_name not in mip_vars:
191-
continue
192-
var_list[var_name] = var_name
193+
if mip_vars is not None:
194+
if var_name in mip_vars:
195+
var_list[var_name] = var_name
196+
else:
197+
var_list[var_name] = ''
198+
else:
199+
var_list[var_name] = var_name
193200

194201
if not var_list:
195202
fre_logger.warning('WARNING: no variables in target mip table found, or no matching pattern,'

fremorizer/tests/test_cli.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_cli_fremor_run_case2(cli_sosv2_nc_file, tmp_path):
226226
"--grid_label", "gr",
227227
"--grid_desc", "FOO_BAR_PLACEHOLD",
228228
"--nom_res", "10000 km" ] )
229-
assert result.exit_code != 0
229+
assert result.exit_code == 0
230230

231231

232232
def test_cli_fremor_run_cmip7_case1(cli_sos_nc_file, tmp_path): # pylint: disable=redefined-outer-name
@@ -270,7 +270,7 @@ def test_cli_fremor_run_cmip7_case2(cli_sosv2_nc_file, tmp_path):
270270
"--grid_label", "g99",
271271
"--grid_desc", "FOO_BAR_PLACEHOLD",
272272
"--nom_res", "10000 km" ] )
273-
assert result.exit_code != 0
273+
assert result.exit_code == 0
274274

275275

276276
def test_cli_fremor_run_case3(cli_mapped_nc_file, tmp_path):
@@ -501,9 +501,12 @@ def test_cli_fremor_varlist_no_table_filter(cli_sos_nc_file, cli_sosv2_nc_file,
501501
assert len(var_list) == 3
502502

503503

504-
def test_cli_fremor_varlist_cmip6_table_filter(cli_sos_nc_file, cli_sosv2_nc_file, tmp_path): # pylint: disable=redefined-outer-name
505-
"""fremor varlist — with CMIP6 Omon MIP table filter.
506-
Only sos should survive; sosV2 is not in the CMIP6 Omon table."""
504+
def test_cli_fremor_varlist_cmip6_table_filter(cli_sos_nc_file, cli_sosv2_nc_file, cli_mapped_nc_file, tmp_path):
505+
"""
506+
fremor varlist — with CMIP6 Omon MIP table filter.
507+
sos is a MIP variable and gets self-mapped; sosV2 and sea_sfc_salinity are
508+
not MIP variable names and get empty string values.
509+
"""
507510
output_varlist = tmp_path / 'test_varlist_cmip6_filter.json'
508511
assert Path(cli_sos_nc_file).parent == Path(cli_sosv2_nc_file).parent, 'something wrong with input nc files'
509512

@@ -520,13 +523,20 @@ def test_cli_fremor_varlist_cmip6_table_filter(cli_sos_nc_file, cli_sosv2_nc_fil
520523
with open(output_varlist, 'r', encoding='utf-8') as f:
521524
var_list = json.load(f)
522525

523-
assert 'sos' in var_list, 'sos should be in the CMIP6-filtered list'
524-
assert 'sosV2' not in var_list, 'sosV2 should NOT be in the CMIP6-filtered list'
526+
assert var_list.get('sos') == 'sos', 'sos should be self-mapped as a MIP variable'
527+
assert 'sosV2' in var_list, 'sosV2 should be included'
528+
assert var_list['sosV2'] == '', 'sosV2 should have empty string value (not a MIP variable name)'
529+
assert 'sea_sfc_salinity' in var_list, 'sea_sfc_salinity should be included'
530+
assert var_list['sea_sfc_salinity'] == '', 'sea_sfc_salinity should have empty string value'
525531

526532

527-
def test_cli_fremor_varlist_cmip7_table_filter(cli_sos_nc_file, cli_sosv2_nc_file, tmp_path): # pylint: disable=redefined-outer-name
528-
"""fremor varlist — with CMIP7 ocean MIP table filter.
529-
sos should survive (sos_tavg-u-hxy-sea splits to sos); sosV2 should not."""
533+
def test_cli_fremor_varlist_cmip7_table_filter(cli_sos_nc_file, cli_sosv2_nc_file, cli_mapped_nc_file, tmp_path):
534+
"""
535+
fremor varlist — with CMIP7 ocean MIP table filter.
536+
sos is a MIP variable (sos_tavg-u-hxy-sea splits to sos) and gets self-mapped;
537+
sosV2 and sea_sfc_salinity are not and get empty string values.
538+
"""
539+
530540
output_varlist = tmp_path / 'test_varlist_cmip7_filter.json'
531541
assert Path(cli_sos_nc_file).parent == Path(cli_sosv2_nc_file).parent, 'something wrong with input nc files'
532542

@@ -543,8 +553,11 @@ def test_cli_fremor_varlist_cmip7_table_filter(cli_sos_nc_file, cli_sosv2_nc_fil
543553
with open(output_varlist, 'r', encoding='utf-8') as f:
544554
var_list = json.load(f)
545555

546-
assert 'sos' in var_list, 'sos should be in the CMIP7-filtered list'
547-
assert 'sosV2' not in var_list, 'sosV2 should NOT be in the CMIP7-filtered list'
556+
assert var_list.get('sos') == 'sos', 'sos should be self-mapped as a MIP variable'
557+
assert 'sosV2' in var_list, 'sosV2 should be included'
558+
assert var_list['sosV2'] == '', 'sosV2 should have empty string value (not a MIP variable name)'
559+
assert 'sea_sfc_salinity' in var_list, 'sea_sfc_salinity should be included'
560+
assert var_list['sea_sfc_salinity'] == '', 'sea_sfc_salinity should have empty string value'
548561

549562

550563
# ── fremor init ───────────────────────────────────────────────────────────

fremorizer/tests/test_cmor_finder_make_simple_varlist.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ def test_make_simple_varlist_mip_table_filter(tmp_path):
178178
result = make_simple_varlist(str(tmp_path), None, json_mip_table=str(mip_table))
179179

180180
assert result is not None
181+
<<<<<<< HEAD
181182
assert 'sos' in result
182183
assert 'notinmip' not in result
184+
=======
185+
assert result.get("sos") == "sos", "MIP variable should be self-mapped"
186+
assert "notinmip" in result, "non-MIP variable should be included"
187+
assert result["notinmip"] == '', "non-MIP variable should have empty string value"
188+
>>>>>>> db3c60b (fix: resolve omission tracking clash and propagate new varlist semantics to fremor varlist)
183189

184190

185191
# ---- no files matching search pattern ----

0 commit comments

Comments
 (0)