Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver writing NWM runs into overwrite issue #56

Open
SorooshMani-NOAA opened this issue Dec 23, 2022 · 0 comments
Open

Driver writing NWM runs into overwrite issue #56

SorooshMani-NOAA opened this issue Dec 23, 2022 · 0 comments

Comments

@SorooshMani-NOAA
Copy link
Contributor

Because NWM output should be the same directory as other SCHISM inputs, it already exists before ModelDriver gets to writing NWM. Since the driver passes the overwrite information to NWM, and NWM writer sees that the directory exists, it errors out.

In other words, one needs to always pass overwrite=True for the ModelDriver.write to work when NWM forcing is included.

To reproduce the issue:

import pathlib
from datetime import datetime, timedelta

from pyschism.mesh import Hgrid
from pyschism import dates
from pyschism.driver import ModelConfig
from pyschism.forcing.source_sink import NWM


test_output_directory = pathlib.Path("/tmp/test")
if test_output_directory.exists():
    shutil.rmtree(test_output_directory)

config = ModelConfig(
    Hgrid.open('mesh_w_bdry.grd', crs="epsg:4326"),
    source_sink=NWM(),
)

# create reference dates
nearest_cycle = dates.nearest_cycle()
spinup_time = timedelta(days=1)
coldstart = config.coldstart(
    start_date=nearest_cycle - spinup_time,
    end_date=nearest_cycle,
    timestep=300.0,
    dramp=spinup_time,
    dramp_ss=spinup_time,
    drampwind=spinup_time,
    nspool=timedelta(hours=1),
)

coldstart.write(test_output_directory / "coldstart", overwrite=False)

And the output:

output_directory=PosixPath('/tmp/test/coldstart') gr3=<pyschism.mesh.hgrid.Hgrid object at 0x7f428d5ced30> start_date=datetime.datetime(2022, 12, 22, 0, 0, tzinfo=<UTC>) end_date=1.0 overwrite=False nprocs=-1 product=None msource=True vsource=True vsink=True source_sink=True
Traceback (most recent call last):
  File "/home/smani/workarea/test/odssm/fail_ensemble_nwm/nwm_test.py", line 74, in <module>
    test_overwrite()
  File "/home/smani/workarea/test/odssm/fail_ensemble_nwm/nwm_test.py", line 69, in test_overwrite
    coldstart.write(test_output_directory / "coldstart", overwrite=False)
  File "/home/smani/workarea/sandbox/pyschism/pyschism/driver.py", line 548, in write
    self.config.forcings.write(
  File "/home/smani/workarea/sandbox/pyschism/pyschism/driver.py", line 81, in write
    self.source_sink.write(
  File "/home/smani/workarea/sandbox/pyschism/pyschism/forcing/source_sink/nwm.py", line 980, in write
    super().write(
  File "/home/smani/workarea/sandbox/pyschism/pyschism/forcing/source_sink/base.py", line 396, in write
    path.mkdir(exist_ok=overwrite, parents=True)
  File "/home/smani/miniconda3/envs/ensemble/lib/python3.9/pathlib.py", line 1323, in mkdir
    self._accessor.mkdir(self, mode)
FileExistsError: [Errno 17] File exists: '/tmp/test/coldstart'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant