1

I have 1) an xarray Dataset with a TIME dimension and a DEPTH dimension, and various variables with values (called "adcp"), and 2) a DataArray with a TIME dimension and values that represent depths (called "mld_int")

I want to exclude any values from the Dataset variables with DEPTH coordinate values that are larger than the depth values (i.e. the data) in the DataArray.

Dataset:

adcp 
xarray.Dataset

    Dimensions:
        DEPTH: 59 LATITUDE: 6 LONGITUDE: 6 TIME: 2217
    Coordinates:
        TIME (TIME) datetime64[ns] 2011-07-07T12:00:00 ... 2017-07-31T12:00:00
        LATITUDE (LATITUDE) float64 22.67 22.67 22.67 22.77 22.77 22.79
        LONGITUDE (LONGITUDE) float64 -158.0 -158.0 ... -157.9 -157.9
        DEPTH (DEPTH) int64 4 6 8 10 12 ... 112 114 116 118 120
    Data variables:
        UCUR (TIME, DEPTH) float64...
        VCUR (TIME, DEPTH) float64...
    Attributes: (0)

DataArray:

mld_int
xarray.DataArray

    TIME: 1032 MLD: 1

    36.21 36.22 37.52 40.47 38.01 37.76 ... 26.62 31.92 40.49 40.86 38.83
    Coordinates:
        TIME (TIME) datetime64[ns] 2004-08-15 ... 2018-09-26
        MLD  (MLD) object 'MLD'
    Attributes: (0) 

I have tried to use this

adcp.where(adcp.DEPTH < mld_int)

but I get this error: The indexing operation you are attempting to perform is not valid on netCDF4.Variable object. Try loading your data into memory first by calling .load().

Any ideas...? :)

luciefer
  • 11
  • 1

0 Answers0