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

Leeway model fails with unknown environment attribute #1469

Open
valschmidt opened this issue Dec 30, 2024 · 3 comments
Open

Leeway model fails with unknown environment attribute #1469

valschmidt opened this issue Dec 30, 2024 · 3 comments

Comments

@valschmidt
Copy link

I'm attempting to try the Leeway model and it is failing with an unknown environment attribute error. Here's my script:

#!/usr/bin/env python3

from opendrift.models.leeway import Leeway
from opendrift.readers import reader_netCDF_CF_generic, reader_global_landmask, reader_ROMS_native

start_lat = 42.5
start_lon = -71.0

latmin = 43.1
latmax = 43.43
lonmin = -71.2
lonmax = -68.5

L = Leeway(loglevel=20)

reader_landmask = reader_global_landmask.Reader()
#reader_landmask = reader_global_landmask.Reader(extent=[lonmin,latmin,lonmax,latmax])

gomofs = reader_ROMS_native.Reader('gomofs.t00z.20241229.fields.f003.nc')

L.add_reader([reader_landmask,gomofs])

L.seed_elements(lon=start_lon, lat=start_lat, number=100, radius=0,
                time=gomofs.start_time)

L.run(end_time = gomofs.end_time, time_step=600,outfile='gomofs_test_output.nc')

print(L)

L.plot()

And here's the last few lines of output:

16:13:36 INFO opendrift.models.basemodel:931: Using existing reader for land_binary_mask 16:13:36 INFO opendrift.models.basemodel:944: Moving 100 out of 100 points from land to water Traceback (most recent call last): File "/Users/vschmidt/scratch/opendrift/./gomofs_testing.py", line 26, in <module> L.run(end_time = gomofs.end_time, time_step=600,outfile='gomofs_test_output.nc') File "/Users/vschmidt/gitsrc/opendrift/opendrift/models/basemodel/__init__.py", line 111, in inner r = func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/vschmidt/gitsrc/opendrift/opendrift/models/basemodel/__init__.py", line 2151, in run self.state_to_buffer() # Append final status to buffer ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/vschmidt/gitsrc/opendrift/opendrift/models/basemodel/__init__.py", line 2292, in state_to_buffer for i, var in enumerate(self.environment.dtype.names): ^^^^^^^^^^^^^^^^ AttributeError: 'Leeway' object has no attribute 'environment'. Did you mean: 'plot_environment'?

@knutfrode
Copy link
Collaborator

If you use loglevel=0 you will see some more detailed information about the cause of the problem.
The missing environment is simply a consequence of something else going wrong.

I suspect it might be that your GOMOFS forcing files covers only a single timestep (from the filename), and thus cannot be used for a simulation over a time period.
Though if you have several such single-timestep-files, you may make an aggregate, e.g.

gomofs = reader_ROMS_native.Reader('gomofs.t00z.20241229.fields.f*.nc')

@valschmidt
Copy link
Author

Looks like you're right!

'''
17:22:41 DEBUG opendrift.models.basemodel:1905: Finalizing environment and preparing readers for simulation coverage ([-71.0, 42.5, -71.0, 42.5]) and time (2024-12-29 03:00:00 to 2024-12-29 03:00:00)
'''
I'm new to this (and the model output) and I didn't expect the start_time and end_time fields to be the same in a single file. That's probably something I should check and catch.

If I might ask a follow-up question. The output of this model is on a THREDDS server here:
https://opendap.co-ops.nos.noaa.gov/thredds/catalog/NOAA/GOMOFS/MODELS/2025/01/02/catalog.html
but I've not been able to figure out THREDDS API model and have just been downloading a few files to test with manually. Is there a single URL that I can give such that the OpenDrift reader will pull the data it needs for the model parameters automatically?

@knutfrode
Copy link
Collaborator

Under the OpenDAP link of a dataset you will find a Data URL field, as e.g. in this example from HYCOM ocean model:
https://tds.hycom.org/thredds/dodsC/FMRC_ESPC-D-V02_uv3z/FMRC_ESPC-D-V02_uv3z_best.ncd.html

The Data URL in this case is
https://tds.hycom.org/thredds/dodsC/FMRC_ESPC-D-V02_uv3z/FMRC_ESPC-D-V02_uv3z_best.ncd

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

2 participants