Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed issues related to joining all the encounter data files
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 7, 2022
1 parent d06b7da commit 3145e09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,12 @@ def process_netcdf_input(ds, param):
ds : xarray dataset
"""

ds = ds.where(~np.isnan(ds.id) ,drop=True)
if param['OUT_TYPE'] == "NETCDF_DOUBLE":
ds = fix_types(ds,ftype=np.float64)
elif param['OUT_TYPE'] == "NETCDF_FLOAT":
ds = fix_types(ds,ftype=np.float32)
ds = ds.where(ds.id >=0 ,drop=True)

# Check if the name variable contains unique values. If so, make name the dimension instead of id
if "id" in ds.dims:
if len(np.unique(ds['name'])) == len(ds['name']):
Expand Down
14 changes: 8 additions & 6 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,14 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False,
self.simdir = Path(simdir)
if self.simdir.exists():
if not self.simdir.is_dir():
msg = f"Cannot create the {self.simdir} directory: File exists."
msg = f"Cannot create the {self.simdir.resolve()} directory: File exists."
msg += "\nDelete the file or change the location of param_file"
warnings.warn(msg,stacklevel=2)
raise NotADirectoryError(msg)
else:
self.simdir.mkdir(parents=True, exist_ok=False)

if read_old_output_file or read_param:
raise NotADirectoryError(f"Cannot find directory {self.simdir.resolve()} ")
else:
self.simdir.mkdir(parents=True, exist_ok=False)

# Set the location of the parameter input file, choosing the default if it isn't specified.
param_file = kwargs.pop("param_file",Path.cwd() / self.simdir / "param.in")
Expand Down Expand Up @@ -376,7 +378,7 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False,
if os.path.exists(binpath):
self.read_output_file()
else:
warnings.warn(f"BIN_OUT file {binpath} not found.",stacklevel=2)
raise FileNotFoundError(f"BIN_OUT file {binpath} not found.")
return

def _run_swiftest_driver(self):
Expand Down Expand Up @@ -2770,7 +2772,7 @@ def _preprocess(ds, param):
return io.process_netcdf_input(ds,param)
partial_func = partial(_preprocess, param=self.param)

self.enc = xr.open_mfdataset(enc_files,parallel=True,preprocess=partial_func,mask_and_scale=True)
self.enc = xr.open_mfdataset(enc_files,parallel=True,combine="nested",concat_dim="time",join="left",preprocess=partial_func,mask_and_scale=True)
self.enc = io.process_netcdf_input(self.enc, self.param)

return
Expand Down

0 comments on commit 3145e09

Please sign in to comment.