Skip to content

Commit

Permalink
schism: do output merging only if files are present
Browse files Browse the repository at this point in the history
If we define nc_out = 0 in the param.nml there is no map output. This way we avoid waiting for the geometry reindexing.
  • Loading branch information
brey committed Sep 24, 2023
1 parent fe9835c commit 825372c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
47 changes: 28 additions & 19 deletions pyposeidon/schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,10 +1312,16 @@ def results(self, **kwargs):
path = get_value(self, kwargs, "rpath", "./schism/")

logger.info("get combined 2D netcdf files \n")
# check for new IO output
hfiles = glob.glob(os.path.join(path, "outputs/out2d_*.nc"))
hfiles.sort()
# check for old IO output
ofiles = glob.glob(os.path.join(path, "outputs/schout_*_*.nc"))

if hfiles:
if not (ofiles or hfiles):
logger.warning("no output netcdf files, moving on")

elif hfiles:
x2d = xr.open_mfdataset(hfiles, data_vars="minimal")

# set timestamp
Expand Down Expand Up @@ -1350,7 +1356,7 @@ def results(self, **kwargs):
# save 2D variables to file
x2d.to_netcdf(os.path.join(path, "outputs/schout_1.nc"))

else:
elif ofiles:
if len(self.misc) == 0:
logger.info("retrieving index references ... \n")
self.global2local(**kwargs)
Expand Down Expand Up @@ -1719,6 +1725,9 @@ def results(self, **kwargs):

xc.to_netcdf(os.path.join(path, f"outputs/schout_{val}.nc"))

else:
raise Exception("This should never happen")

logger.info("done with output netCDF files \n")

def set_obs(self, **kwargs):
Expand Down Expand Up @@ -1871,25 +1880,25 @@ def get_station_sim_data(self, **kwargs):
try:
# get the station flags
flags = pd.read_csv(os.path.join(path, "station.in"), header=None, nrows=1, delim_whitespace=True).T
flags.columns = ["flag"]
flags["variable"] = [
"elev",
"air_pressure",
"windx",
"windy",
"T",
"S",
"u",
"v",
"w",
]

vals = flags[flags.values == 1] # get the active ones
except OSError as e:
if e.errno == errno.EEXIST:
logger.error("no station.in file present")
except FileNotFoundError:
logger.error("no station.in file present")
return

flags.columns = ["flag"]
flags["variable"] = [
"elev",
"air_pressure",
"windx",
"windy",
"T",
"S",
"u",
"v",
"w",
]

vals = flags[flags.values == 1] # get the active ones

dstamp = kwargs.get("dstamp", self.rdate)

dfs = []
Expand Down
28 changes: 27 additions & 1 deletion tests/test_schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@
}


case4 = {
"solver_name": "schism",
"mesh_file": MESH_FILE,
"manning": 0.12,
"windrot": 0.00001,
"tag": "test",
"start_date": "2011-1-1 0:0:0",
"time_frame": "12H",
"meteo_source": [(DATA_DIR / "era5.grib").as_posix()], # meteo file
"dem_source": DEM_FILE,
"monitor": True,
"update": ["all"], # update only meteo, keep dem
"parameters": {
"dt": 400,
"rnday": 0.3,
"nhot": 0,
"ihot": 0,
"nspool": 9,
"ihfskip": 36,
"nhot_write": 108,
"nc_out": 0,
},
"scribes": 2,
}


def schism(tmpdir, dic):
# initialize a model
rpath = str(tmpdir) + "/"
Expand All @@ -105,7 +131,7 @@ def schism(tmpdir, dic):


@pytest.mark.schism
@pytest.mark.parametrize("case", [case1, case2, case3])
@pytest.mark.parametrize("case", [case1, case2, case3, case4])
def test_answer(tmpdir, case):
assert schism(tmpdir, case) == True

Expand Down

0 comments on commit 825372c

Please sign in to comment.