Yefee/xMCA

xMCA(): Left and Right field must have same time coords.

nicrie opened this issue · 2 comments

Hey Yefee,
I just installed your package to perform a Maximum Covariance Analysis between two fields (precipitation and SSS). Both fields work fine with cdo and python packages xarray and Eof, though xMCA throws a dimension error:

ValueError: Left and Right field must have same time coords.

For analysis reasons, I did some adjustments on both fields as follows:

  1. Coarse gridding: reducing the resolution to 3.0ºx3.0º using
    cdo remapcon,r120x60 infile.nc outfile.nc

  2. Calculate field anomalies: I do this directly via xarray

  3. Drop depth dimension for SSS using
    sssa = sssa_ds.reset_index('depth',drop=True).drop('depth_bnds').squeeze()

These are basically all adjustments to the data fields yielding in

SSS
sssa.dims

Frozen(SortedKeysDict({'time': 60, 'bnds': 2, 'lon': 120, 'lat': 60}))

sssa.coords

Coordinates:

  • time (time) datetime64[ns] 1950-04-16 1951-04-16 ... 2009-04-16
  • lon (lon) float32 0.0 3.0 6.0 9.0 12.0 ... 348.0 351.0 354.0 357.0
  • lat (lat) float32 -88.5 -85.5 -82.5 -79.5 -76.5 ... 79.5 82.5 85.5 88.5

Precipitation
pa.dims

Frozen(SortedKeysDict({'time': 60, 'lon': 120, 'lat': 60}))

pa.coords

Coordinates:

  • time (time) datetime64[ns] 1950-07-16T12:00:00 ... 2009-07-16T12:00:00
  • lon (lon) float32 0.0 3.0 6.0 9.0 12.0 ... 348.0 351.0 354.0 357.0
  • lat (lat) float32 -88.5 -85.5 -82.5 -79.5 -76.5 ... 79.5 82.5 85.5 88.5

Since I could successfully perform EOF analysis using the Eof package (which serves as kind of a model as far as I understood), I'm a little bit surprised about this error. I assume that it has to two with the additional bnds: 2 in the SSS data set, but even dropping them does not help.

In which way do I have to modify the fields that they are eligible as input for xMCA()?

Yefee commented

@nicrie
Sorry for the late reply.

The problem here is that you have different time coords in SSS and Precipitation that is not allowed in the xMCA. An easy way to solve this is to assign same time coords for both variables.

Do this first, then use xMCA.

sssa['time'] = pa.time

Best,
Chengfei

Hey Chengfei,
Thanks a lot, that did the trick - don't know why I didn't see it ;)