0

I have two NetCDF files:

Data1.shape = (177, 180, 360) 
Data2.shape = (179, 180, 360))

Date1=  {list: 177}['2002-04', '2002-05', '2002-06', … ]
Date2 = {list: 179}['2002-04', '2002-05', '2002-08', … ]

I would like to filter/extract only those data that are match with Date1.

I should mention that the Date format of the two NetCDF files were different and I changed them to be consistent.

I tried different ways such as groupby, Timestamp, and reading the documents of a given index to the times. However, I found they are not working for 3D data (time, lon, lat).

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ehsan
  • 89
  • 9

1 Answers1

0

Solved:

data1 = xr.open_dataset('path\to\my\data\data_1.nc4')

<xarray.Dataset>
Dimensions:                (lat: 180, lon: 360, time: 212)
Coordinates:
  * time                   (time) datetime64[ns] 2002-04-01 ... 2019-11-01
  * lon                    (lon) float32 -179.5 -178.5 -177.5 ... 178.5 179.5
  * lat                    (lat) float32 89.5 88.5 87.5 ... -87.5 -88.5 -89.5

Data variables:
Evap_tavg              (time, lat, lon) float32 ...

read the second data.

data2 = xr.open_dataset('path\to\my\data\data_2.nc4')

 <xarray.Dataset>
    Dimensions:                (lat: 180, lon: 360, time: 212)
    Coordinates:
      * time                   (time) datetime64[ns] 2003-01-01 ... 2016-12-01
      * lon                    (lon) float32 -179.5 -178.5 -177.5 ... 178.5 179.5
      * lat                    (lat) float32 89.5 88.5 87.5 ... -87.5 -88.5 -89.5

    Data variables:
    Evap              (time, lat, lon) float32 ...

They have some data in common date/time, that we want to extract those data from the similar date/time.

my_new_data =  data1.where(data1['time'].isin(data2['time']),  drop=True)
Ehsan
  • 89
  • 9