Skip to content

Commit c16644c

Browse files
refine options
1 parent 185f585 commit c16644c

File tree

2 files changed

+82
-58
lines changed

2 files changed

+82
-58
lines changed

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/make_bcs_cube.py

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,29 @@
55
import os
66
from make_bcs_questionary import *
77
from make_bcs_shared import *
8-
import re
98
from datetime import datetime
109
import subprocess
1110

12-
def _resolve_versions(bcs_version: str):
13-
"""
14-
Returns (mom6_bathy_version, topo_version) as 'v1' or 'v2'
15-
Rule: v14+ -> v2; else -> v1. Non-numeric (NL3, ICA, GM4...) -> v1.
16-
"""
17-
v = (bcs_version or "").strip()
18-
m = re.match(r'[vV]?(\d+)', v)
19-
vnum = int(m.group(1)) if m else None
20-
use_v2 = vnum is not None and vnum >= 14
21-
return ("v2" if use_v2 else "v1", "v2" if use_v2 else "v1")
22-
23-
def _build_mom6_link_lines(inputdir: str, preferred_version: str) -> str:
24-
"""
25-
Build csh lines to symlink MOM6 datasets.
26-
Prefer `preferred_version` (v1 or v2) per size; if missing, fall back to the other version.
27-
Emits an echo note on fallback; warns if a size is missing in both.
28-
"""
29-
sizes = ["72x36", "540x458", "1440x1080"]
30-
other = "v1" if preferred_version == "v2" else "v2"
31-
32-
lines = ['if ( ! -d data/MOM6 ) mkdir -p data/MOM6']
33-
for size in sizes:
34-
src_pref = os.path.join(inputdir, "ocean", "MOM6", preferred_version, size)
35-
src_other = os.path.join(inputdir, "ocean", "MOM6", other, size)
36-
37-
if os.path.isdir(src_pref):
38-
src = src_pref
39-
note = ""
40-
elif os.path.isdir(src_other):
41-
src = src_other
42-
note = f'echo "NOTE: MOM6 {preferred_version}/{size} not found; using {other}/{size}"'
43-
else:
44-
lines.append(f'echo "WARNING: MOM6 {size} missing in both v1 and v2; skipping"')
45-
continue
46-
47-
lines.append(f'if ( -e data/MOM6/{size} ) /bin/rm -f data/MOM6/{size}')
48-
if note:
49-
lines.append(note)
50-
lines.append(f'ln -s {src} data/MOM6/{size}')
51-
return "\n".join(lines)
52-
5311
cube_template = """
5412
5513
ln -s {MAKE_BCS_INPUT_DIR}/ocean/MOM5/360x200 data/MOM5/360x200
5614
ln -s {MAKE_BCS_INPUT_DIR}/ocean/MOM5/720x410 data/MOM5/720x410
5715
ln -s {MAKE_BCS_INPUT_DIR}/ocean/MOM5/1440x1080 data/MOM5/1440x1080
58-
{MOM6_LINK_LINES}
16+
if ( {TRIPOL_OCEAN} == True ) then
17+
set mom6v = {mom6_bathy_version}
18+
set mom6root = {MAKE_BCS_INPUT_DIR}/ocean/MOM6/$mom6v
19+
set req = {imo}x{jmo}
20+
21+
if ( ! -d $mom6root/$req ) then
22+
echo "ERROR: MOM6/$mom6v/$req missing under {MAKE_BCS_INPUT_DIR}/ocean/MOM6"
23+
echo " Selected via questionnaire '{lbcsv}' -> MOM6_BATHY_VERSION=$mom6v"
24+
exit 10
25+
endif
26+
27+
if ( ! -d data/MOM6 ) mkdir -p data/MOM6
28+
if ( -e data/MOM6/$req ) /bin/rm -f data/MOM6/$req
29+
ln -s $mom6root/$req data/MOM6/$req
30+
endif
5931
6032
6133
if( -e CF{NC}x6C{SGNAME}_{DATENAME}{IMO}x{POLENAME}{JMO}.stdout ) /bin/rm -f CF{NC}x6C{SGNAME}_{DATENAME}{IMO}x{POLENAME}{JMO}.stdout
@@ -180,8 +152,30 @@ def make_bcs_cube(config):
180152
if not os.path.exists(log_dir):
181153
os.makedirs(log_dir)
182154

183-
MOM6_BATHY_VERSION, TOPO_VERSION = _resolve_versions(config['lbcsv'])
184-
MOM6_LINK_LINES = _build_mom6_link_lines(config['inputdir'], MOM6_BATHY_VERSION)
155+
TOPO_VERSION = topo_version_for_bcs(config['lbcsv'])
156+
MOM6_BATHY_VERSION = mom6_bathy_version_for_bcs(config['lbcsv'])
157+
158+
# ---------- INPUT CHECKS (abort before sbatch) ----------
159+
# 1) TOPO must exist for this grid
160+
topo_dir = f"CF{NC}x6C{SGNAME}" # CF0090x6C or CF0540x6C-SG001
161+
topo_src = os.path.join(config['inputdir'], "atmosphere", "TOPO", TOPO_VERSION, topo_dir)
162+
if not os.path.isdir(topo_src):
163+
print(f"ABORT: Missing TOPO: {topo_src} "
164+
f"(LBCSV={config['lbcsv']} TOPO_VERSION={TOPO_VERSION})")
165+
return
166+
167+
# 2) MOM6 bathymetry: strict, check ONLY the size used by this run
168+
if config["TRIPOL_OCEAN"]:
169+
req = f"{config['imo']}x{config['jmo']}" # 540x458 or 1440x1080
170+
mom6_src = os.path.join(config['inputdir'], "ocean", "MOM6", MOM6_BATHY_VERSION, req)
171+
if not os.path.isdir(mom6_src):
172+
print(f"ABORT: Missing MOM6 bathymetry: {mom6_src} "
173+
f"(LBCSV={config['lbcsv']} MOM6={MOM6_BATHY_VERSION})")
174+
return
175+
176+
print(f"[make_bcs_cube] LBCSV={config['lbcsv']} TOPO={TOPO_VERSION} "
177+
f"MOM6={MOM6_BATHY_VERSION} REQ={'{imo}x{jmo}'.format(**config)} GRID={GRIDNAME}")
178+
# -------------------------------------------------------------------
185179

186180
script_template = get_script_head() + cube_template + get_script_mv(config['grid_type'])
187181

@@ -223,7 +217,6 @@ def make_bcs_cube(config):
223217
SGPARAM = SGPARAM, \
224218
TOPO_VERSION = TOPO_VERSION,
225219
mom6_bathy_version = MOM6_BATHY_VERSION,
226-
MOM6_LINK_LINES = MOM6_LINK_LINES,
227220
IS_STRETCHED = IS_STRETCHED, \
228221
NCPUS = config['NCPUS'])
229222

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/makebcs/make_bcs_shared.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,50 @@
66
import glob
77
import re
88

9+
# --- BEGIN VERSION MATRIX ---
10+
11+
# Independent version mapping per questionnaire 'lbcsv'
12+
_VERSION_MATRIX = {
13+
"NL3": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
14+
"NL4": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
15+
"NL5": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
16+
"ICA": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
17+
"GM4": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
18+
"F25": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
19+
"v06": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
20+
"v07": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
21+
"v08": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
22+
"v09": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
23+
"v10": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
24+
"v11": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
25+
"v12": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
26+
"v13": {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"},
27+
"v14": {"TOPO_VERSION": "v2", "MOM6_BATHY_VERSION": "v2"},
28+
}
29+
30+
_DEFAULTS = {"TOPO_VERSION": "v1", "MOM6_BATHY_VERSION": "v1"}
31+
32+
def _normalize_lbcsv(label: str) -> str:
33+
v = (label or "").strip()
34+
import re
35+
m = re.match(r'[vV]?\d+|[A-Za-z0-9]+', v) # accepts v14 / 14 / NL3 / etc.
36+
if not m:
37+
return v
38+
key = m.group(0)
39+
# normalize numeric like '14' -> 'v14'
40+
if key.isdigit():
41+
key = 'v' + key
42+
return key
43+
44+
def resolve_bcs_matrix(bcs_version: str):
45+
key = _normalize_lbcsv(bcs_version)
46+
return {**_DEFAULTS, **_VERSION_MATRIX.get(key, {})}
47+
948
def topo_version_for_bcs(bcs_version: str) -> str:
10-
"""
11-
Decide which TOPO set to use based on BCS version chosen in the questionnaire.
12-
- v14 and later → TOPO v2
13-
- v13 and earlier (and NL*/ICA/GM4/F25) → TOPO v1
14-
"""
15-
v = (bcs_version or "").strip()
16-
## m = re.fullmatch(r"[vV](\d+)", v)
17-
m = re.match(r"[vV]?(\d+)", v) # relaxed tolerance if we change names
18-
if m:
19-
return "v2" if int(m.group(1)) >= 14 else "v1"
20-
# NL3, NL4, NL5, ICA, GM4, F25, etc.
21-
return "v1"
49+
return resolve_bcs_matrix(bcs_version)["TOPO_VERSION"]
50+
51+
def mom6_bathy_version_for_bcs(bcs_version: str) -> str:
52+
return resolve_bcs_matrix(bcs_version)["MOM6_BATHY_VERSION"]
2253

2354
def get_script_head() :
2455

0 commit comments

Comments
 (0)