ecmwf / earthkit-data

A format-agnostic Python interface for geospatial data
Apache License 2.0
47 stars 9 forks source link

Add option to subset field values in to_numpy() method #406

Open sandorkertesz opened 1 week ago

sandorkertesz commented 1 week ago

Is your feature request related to a problem? Please describe.

If we have a fieldlist to_numpy() gives back a 2D numpy array containing all the field values per field. We can slice this array according to the second (per field axis) like that:

ds = from_source("file", "my.grib")
v = ds.to_numpy(flatten=True)[:, :4]

This could be done in a more memory efficient way if we performed the slicing on the field level and to_numpy() returned the already sliced 2D array. This could be done e.g. by implementing the following interface:

ds = from_source("file", "my.grib")
v = ds.to_numpy(flatten=True, index=slice(None, 4))

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Organisation

ECMWF