Skip to content

Commit 1f3d403

Browse files
klapomtezzele
authored andcommitted
mrCOSTS I/O now allows specifying a file path.
1 parent 191e84a commit 1f3d403

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pydmd/mrcosts.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def from_netcdf(self, file_list):
560560
self._n_data_vars = n_data_vars
561561
self._n_time_steps = n_time_steps
562562

563-
def to_netcdf(self, filename):
563+
def to_netcdf(self, filename, filepath="."):
564564
"""
565565
Save the mrCoSTS fit to file in netcdf format.
566566
@@ -569,10 +569,14 @@ def to_netcdf(self, filename):
569569
570570
:param filename: Common name shared by each file.
571571
:type filename: str
572+
:param filepath: Path to save the results. Default is the current
573+
directory.
574+
:type filename: str
575+
572576
"""
573577
for c in self._costs_array:
574578
c.to_xarray().to_netcdf(
575-
".".join(
579+
filepath.join(
576580
(
577581
filename,
578582
f"window={c.window_length:}",

tests/test_mrcosts.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ def test_netcdf(tmp_path):
292292
netcdf format and back to mrCOSTS.
293293
"""
294294
# Move the I/O tests to the temporary test directory.
295-
os.chdir(tmp_path)
296-
mrc.to_netcdf("tests")
295+
mrc.to_netcdf("tests", filepath=tmp_path)
297296
file_list = glob.glob("*tests*.nc")
298297
mrc_from_file = mrCOSTS()
299298
mrc_from_file.from_netcdf(file_list)

0 commit comments

Comments
 (0)