OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
231 stars 113 forks source link

Issue reading in schism reader: 'Variable' object has no attribute 'ncattrs' #1242

Closed calquigs closed 4 months ago

calquigs commented 4 months ago

Hello! I am trying to run a simulation in a schism model, but I get an error when reading in the files with the native_schism_reader. from opendrift.readers import reader_schism_native, reader = reader_schism_native.Reader(path) throws:

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/<path>/opendrift/opendrift/readers/reader_schism_native.py", line 215, in __init__
    if 'positive' not in var.ncattrs() or \
                         ^^^^^^^^^^^
AttributeError: 'Variable' object has no attribute 'ncattrs'. Did you mean: '_attrs'?

Any idea where the issue might be? Happy to share an example model file.

knutfrode commented 4 months ago

I have never used this reader myself, but it seems it has been converted from originally using netCDF4.Dataset to using Xarray, but forgetting to update these few lines that are executed whenever there is a depth variable present.

Thus you can try to change 'positive' not in var.ncattrs() to 'positive' not in var.attrs and var.__dict__['positive'] == 'up' to var.attrs['positive'] == 'up' in the line below.

If it solves the problem, you are welcome to make a pull request, or I can update this directly on master.

calquigs commented 4 months ago

Problem fixed and pull request made. Thank you!