OpenDrift / opendrift

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

Bug found: KeyError: 'dynamicviscosity' #837

Closed FrancoisDuquesne closed 2 years ago

FrancoisDuquesne commented 2 years ago

I managed to replicate the same error I had when executing example/example_oil_budget.py

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/unit_conversion/unit_conversion.py", line 395, in convert
    Converter = Converters[unit_type]
KeyError: 'dynamicviscosity'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opendrift/examples/example_oil_budget.py", line 37, in <module>
    o.seed_elements(lon=4.8, lat=60.0, z=0, radius=3000, number=1000,
  File "/opendrift/opendrift/models/openoil/openoil.py", line 1539, in seed_elements
    self.set_oiltype(self.get_config('seed:oil_type'))
  File "/opendrift/opendrift/models/openoil/openoil.py", line 1403, in set_oiltype
    self.oiltype = adios.find_full_oil_from_name(self.oil_name)
  File "/opendrift/opendrift/models/openoil/adios/dirjs.py", line 72, in find_full_oil_from_name
    o = oils(query=name)
  File "/opendrift/opendrift/models/openoil/adios/dirjs.py", line 67, in oils
    return list(OpendriftOil(o) for o in itertools.islice(oils, limit))
  File "/opendrift/opendrift/models/openoil/adios/dirjs.py", line 67, in <genexpr>
    return list(OpendriftOil(o) for o in itertools.islice(oils, limit))
  File "/opendrift/opendrift/models/openoil/adios/oil.py", line 77, in __init__
    self.gnome_oil = gnome_oil.make_gnome_oil(self.oil)
  File "/opendrift/opendrift/models/openoil/adios/computation/gnome_oil.py", line 136, in make_gnome_oil
    viscosities = get_kinematic_viscosity_data(oil, units="m^2/s", temp_units="K")
  File "/opendrift/opendrift/models/openoil/adios/computation/physical_properties.py", line 254, in get_kinematic_viscosity_data
    dvisc = get_dynamic_viscosity_data(oil, units="Pa s", temp_units="K")
  File "/opendrift/opendrift/models/openoil/adios/computation/physical_properties.py", line 284, in get_dynamic_viscosity_data
    v = visc_point.viscosity.converted_to(units).value
  File "/opendrift/opendrift/models/openoil/adios/models/common/measurement.py", line 177, in converted_to
    new.convert_to(new_unit)
  File "/opendrift/opendrift/models/openoil/adios/models/common/measurement.py", line 162, in convert_to
    new_val = convert(self.unit_type, self.unit, new_unit, val)
  File "/usr/local/lib/python3.9/dist-packages/unit_conversion/unit_conversion.py", line 397, in convert
    raise InvalidUnitTypeError(unit_type)
unit_conversion.unit_conversion.InvalidUnitTypeError: The unit type: dynamicviscosity is not in the UnitConversion database
knutfrode commented 2 years ago

It seems that you have updated OpenDrift to 1.8.0, but not its dependencies (including NOAA oil library). Thus this problem should be solved if you update the dependencies with:

conda env update -f environment.yml
pip install -e .

https://opendrift.github.io/install.html

FrancoisDuquesne commented 2 years ago

Ok will try that thx! (realized I should probably have written this in a discussion instead of an issue... )