nicrie / xmca

Maximum Covariance Analysis in Python
MIT License
53 stars 16 forks source link

Why are there different outputs of nicrie / xmca compared with outputs of Yefee's xMCA? #34

Open zhiweijt opened 1 year ago

zhiweijt commented 1 year ago

Hi, nicrie. Recently, I perform a svd analysis using nicrie / xmca code, the both shapes of left and right field matrixes were (time, lat, lon), and the value of time axis is (2000, 2001, ..., 2022). I can get outputs of mca.eofs and mca.pcs, but I wonder that outputs were opposite compared with outputs of mca.expansionCoefs() of Yefee's xMCA. Finally, I found that the same outputs can be obtained when time axis was reorded in inverse order, that is, (2022,2021,...,2000). I want to know, which one is right? Is it a bug in code? Thanks a lot. the outputs of mca.pcs() using nicrie / xmca code were showed as image

the outputs of mca.expansionCoefs() using Yefee's xMCA code were showed as image

nicrie commented 1 year ago

Hi zhiweijt - sorry for the late reply! Upon examining the figures, the results do appear to be consistent. The PCs/EOFs are only defined up to a sign, meaning that an equivalent solution can be obtained by flipping the y-axis of both the PC and the corresponding EOF.

However, it is indeed unexpected to see that the x-axis (time) is inverted in xmca for the same input. This discrepancy might be related to how the time coordinate in the input DataArray is defined. Have you considered sorting the time axis of the DataArray before proceeding with the analysis?

Please note that the order of the data doesn't impact the computation of the EOFs. Hence, if the observed difference is solely due to different ordering of the time steps, the EOFs should remain identical in both packages. Can you confirm whether this is the case for your data?