OpenDrift / opendrift

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

Fix which allows having dtype byte for landmask in ROMS files #1121

Closed knutfrode closed 1 year ago

knutfrode commented 1 year ago

For å unngå dette problemet som Magne fikk for ROMS-filer der land_binary_mask var byte og ikkje double Ser fiksen akseptabel ut, @gauteh ?

  File "/home/knutfd/miniconda3/envs/opendrift/lib/python3.11/site-packages/numpy/ma/core.py", line 467, in _check_fill_value
    fill_value = np.array(fill_value, copy=False, dtype=ndtype)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot convert float NaN to integer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/knutfd/software/opendrift/opendrift/models/basemodel.py", line 1252, in get_environment
    reader.get_variables_interpolated(
  File "/home/knutfd/software/opendrift/opendrift/readers/basereader/variables.py", line 844, in get_variables_interpolated
    env, env_profiles = self.get_variables_interpolated_xy(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/knutfd/software/opendrift/opendrift/readers/basereader/variables.py", line 710, in get_variables_interpolated_xy
    env, env_profiles = self._get_variables_interpolated_(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/knutfd/software/opendrift/opendrift/readers/basereader/structured.py", line 247, in _get_variables_interpolated_
    ReaderBlock(reader_data_dict,
  File "/home/knutfd/software/opendrift/opendrift/readers/interpolation/structured.py", line 36, in __init__
    self.data_dict[var] = variables.Variables.__check_variable_array__(var, self.data_dict[var])
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/knutfd/software/opendrift/opendrift/readers/basereader/variables.py", line 569, in __check_variable_array__
    variable = variable.filled(np.nan)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/knutfd/miniconda3/envs/opendrift/lib/python3.11/site-packages/numpy/ma/core.py", line 3826, in filled
    fill_value = _check_fill_value(fill_value, self.dtype)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/knutfd/miniconda3/envs/opendrift/lib/python3.11/site-packages/numpy/ma/core.py", line 473, in _check_fill_value
    raise TypeError(err_msg % (fill_value, ndtype)) from e
TypeError: Cannot convert fill_value nan to dtype int8