Skip to content

Out of memory error during initialization of hash table - CREG12 curvilinear grid #2521

@noemieplanat

Description

@noemieplanat

Parcels version

main
python 3.11

Description

Parcels fails to evaluate U (any) field due to a memory error. Initial grid of the netcdf file is 75 (depth), 1580 (x) and 1801 (y). Initial xarray (ds_fields) has the same dimensions. Converted fset (ds_fset) has 1580 along x and x_center dimensions (idem for y) plus has a x variable that has (y,x) dimensions.

Fails on fset.U.eval(...)

Code sample

The data is stored in @VeckoTheGecko 's home folder on Lorenz. We can probably trim this example down even further using the instructions on sharing datasets (which would indicate that this is a dimension/metadata/data transformation problem and not a coordinates issue) but he is yet to pursue that.

from parcels import FieldSet, ParticleSet, Variable, convert, ParticleFile, StatusCode # type: ignore
import xarray as xr
from datetime import timedelta as delta
import numpy as np
import datetime
import warnings
import cftime as cf


listeU = ['data/CREG12.L75-REF12_y2001m02.1d_gridU.nc']
listeV = ['data/CREG12.L75-REF12_y2001m02.1d_gridV.nc']
listeW = ['data/CREG12.L75-REF12_y2001m02.1d_gridW.nc']
mesh_file_z = 'data/CREG12.L75-REF09_domain_mask_lat_lon_updated_z.nc'


ds_fields = xr.open_mfdataset(
    listeU +listeV+listeW,
    data_vars={"vozocrtx","vomecrty", "vovecrtz"},
    coords="minimal",
    compat="override",
)
ds_fields = ds_fields.drop({"depthu_bounds", \
                           "time_centered_bounds",\
                          "time_counter_bounds",\
                           "e3u","e3v", "sozotaux",\
                           "utau_atmoce", "utau_iceoce",\
                           "uwspd10", "ahtu_3d", "depthv_bounds",\
                           "sometauy", "vtau_atmoce",\
                           "vtau_iceoce","vwspd10",\
                           "ahtv_3d", "depthw_bounds",\
                           "votkeavt","e3w"}
                          )
ds_coords = xr.open_dataset(mesh_file_z, decode_times=False)
ds_fset = convert.nemo_to_sgrid(fields=dict(U=ds_fields["vozocrtx"], V=ds_fields["vomecrty"], W = ds_fields["vovecrtz"]), coords=ds_coords)

ds_fset = ds_fset.drop(['V','W']).isel(time=[0])
fset = FieldSet.from_sgrid_conventions(ds_fset, ds_coords)

fset.U.eval(np.array([0.]), np.array([50.]),np.array([89.]), np.array([120.]))

error

Traceback (most recent call last):
  File "/storage/home/hodgs004/parcels4-debug-naomi/min-example.py", line 44, in <module>
    fset.U.eval(np.array([0.]), np.array([50.]),np.array([89.]), np.array([120.]))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/field.py", line 220, in eval
    particle_positions, grid_positions = _get_positions(self, time, z, y, x, particles, _ei)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/field.py", line 469, in _get_positions
    grid_positions.update(field.grid.search(z, y, x, ei=_ei))
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/xgrid.py", line 313, in search
    yi, eta, xi, xsi = _search_indices_curvilinear_2d(self, y, x, yi, xi)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/index_search.py", line 192, in _search_indices_curvilinear_2d
    yi_q, xi_q, coords_q = grid.get_spatial_hash().query(y_check, x_check)
                           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/basegrid.py", line 210, in get_spatial_hash
    self._spatialhash = SpatialHash(self)
                        ^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/spatialhash.py", line 177, in __init__
    self._hash_table = self._initialize_hash_table()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/storage/home/hodgs004/parcels4-debug-naomi/.pixi/envs/default/lib/python3.11/site-packages/parcels/_core/spatialhash.py", line 224, in _initialize_hash_table
    morton_codes = np.zeros(total_hash_entries, dtype=np.uint32)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy._core._exceptions._ArrayMemoryError: Unable to allocate 791. GiB for an array with shape (212287160821,) and data type uint32

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions