-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MCA errors #31
Comments
The error is due to an unfortunate limitation of this package that the spatial coordinates have to be named Currently, your main spatial coordinates are called var = var.rename({'lat': 'lat_old', 'lon': 'lon_old'})
var = var.rename({'south_north': 'lat', 'west_east': 'lon'}) If you're still running into problems try to boil down your Note: In this package, |
Hi, |
I think you're right. The In any case, you can easily plot the modes yourselves, e.g.: from cartopy.crs import NearsidePerspective, PlateCarree
# ... your analysis
pcs = mca.pcs()
eofs = mca.eofs()
proj = NearsidePerspective(central_longitude=15, central_latitude=65)
mode = 1
fig = plt.figure(figsize=(14, 7))
ax_eof_left = fig.add_subplot(221, projection=proj)
ax_eof_right = fig.add_subplot(222, projection=proj)
ax_pc_left = fig.add_subplot(223)
ax_pc_right = fig.add_subplot(224)
eofs['left'].sel(mode=mode).plot(ax=ax_eof_left, transform=PlateCarree())
eofs['right'].sel(mode=mode).plot(ax=ax_eof_right, transform=PlateCarree())
pcs['left'].sel(mode=mode).plot(ax=ax_pc_left)
pcs['right'].sel(mode=mode).plot(ax=ax_pc_right) Let me know if it works. |
Hi Niclas, Thanks again for helping out. Here is the final script;
|
Looks valid to me, no? Perhaps you want to add coastlines to identify your region of interest: # analysis
fig = plt.figure(figsize=(14, 7))
# define axes ...
# add coastlines
ax_eof_left.coastlines()
ax_eof_right.coastlines()
# rest of plotting
# ...
eofs['left'].sel(mode=mode).plot(ax=ax_eof_left, ) Do you think your issue with plotting is solved by this? |
Hi Niclas, I think the plotting is correct for now now. Though I might work on the plotting further with the salem package, because it produces better maps with WRF grid (as shown in the first set of figures I had provided). Will update here if I can get salem to produce them. |
Thank you for your kind words! The convenience function
|
Wonderful @nicrie !!! This is what I was exactly looking for. Thanks alot. |
@nicrie Just to get it to your notice, The following is the error: A simple plot function does work, but again, it doesn't look quite clean. |
@GIRIJA-KALYANI this is probably not a bug but - as the error message implies - xarray does not know how to plot complex data. Since you set |
Thanks a ton for the suggestion @nicrie . I'm trying to plot complex EOFs, and only eofs['left'].real works. Using pca.spatial_amplitudes() or pca.spatial_phase() - doesn't seem to work at least me. Maybe I'm going wrong somewhere. When I try pca.plot(mode=1) - it works What could be the error? Also, when I try using varimax rotation Also, when I look into the data of complex EOFs, I see nan+nanj values, any insights on how the code handles nan values please? Thanks in advance |
I'm sorry you encounter these errors, let me go through them one by one:
pca.rotate(n_rot=10, power=1)
expvar_rot = pca.explained_variance()
....
Does that answer your questions? |
I'm sorry for responding late. Plus, sometimes I get SVD did not converge as runtime error, this mostly happens when I set complex to True initially, then change again to False , just to notice the differences I also want to see correlation maps (I have seen this from API that the module gives this option, how do I derive one and visualize?? Thanks a ton in advance |
If you want to rotate, just call pca.rotate(<your arguments here>) The following will not work pca = pca.rotate(<your arguments here>) In any case, the arguments are still needed! The plotting of homogeneous/heterogeneous and or correlation maps works exactly as for the spatial amplitudes. The objects are As a side note: please consider switching over to xeofs as it is starting to incorporate xmca. For now, you can do e.g. EOF, MCA and rotation with xeofs. You'll also find some examples how to do it, so getting started should be easy. |
@nicrie wow, many thanks for the link of xeof!!! |
How can I visualize spatial amplitudes & phases?
Plus, I could retrieve homogeneous and heterogeneous patterns as arrays,
but unable to visualize using basic plot command
…On Sat, 27 Aug 2022, 00:21 Niclas Rieger, ***@***.***> wrote:
If you want to rotate, just call
pca.rotate(<your arguments here>)
The following *will not* work
pca = pca.rotate(<your arguments here>)
In any case, the arguments are still needed!
The plotting of homogeneous/heterogeneous and or correlation maps works
exactly as for the spatial amplitudes. The objects are xr.DataArray. So
if you manage to plot the spatial amplitudes/phases just replace these with
the quantity you are interested in. Check the API
<https://pyxmca.readthedocs.io/en/latest/_autosummary/xmca.xarray.xMCA.html#xmca.xarray.xMCA>
which quantities you can retrieve.
------------------------------
As a side note: please consider switching over to xeofs
<https://github.com/nicrie/xeofs/> as it is starting to incorporate xmca.
For now, you can do e.g. EOF, MCA and rotation with xeofs. You'll also find
some examples
<https://xeofs.readthedocs.io/en/latest/auto_examples/index.html#> how to
do it, so getting started should be easy.
—
Reply to this email directly, view it on GitHub
<#31 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWDHEEI2V22VMEBF3F56ITV3EG4DANCNFSM52WGXKXA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Take the plotting example from above and replace the from cartopy.crs import NearsidePerspective, PlateCarree
# ... your analysis
hom_pats = mca.homogeneous_patterns()
het_pats = mca.heterogeneous_patterns()
proj = NearsidePerspective(central_longitude=15, central_latitude=65)
mode = 1
fig = plt.figure(figsize=(14, 7))
ax_eof_left = fig.add_subplot(221, projection=proj)
ax_eof_right = fig.add_subplot(222, projection=proj)
ax_pc_left = fig.add_subplot(223, projection=proj)
ax_pc_right = fig.add_subplot(224, projection=proj)
hom_pats['left'].sel(mode=mode).plot(ax=ax_eof_left, transform=PlateCarree())
hom_pats['right'].sel(mode=mode).plot(ax=ax_eof_right, transform=PlateCarree())
het_pats['left'].sel(mode=mode).plot(ax=ax_pc_left, transform=PlateCarree())
het_pats['right'].sel(mode=mode).plot(ax=ax_pc_right, transform=PlateCarree()) |
1 similar comment
Are you using |
I'm using xmca for now, just want to get this sorted and then move on to xeofs. |
I cannot say for sure since I do not know your data. But given that it is mode 1, the PCs of the left and right fields often have a very high correlation (if they share some common dynamics). Correlating the left field with the left PCs or the right PCs often won't make a great difference. This is why the homogeneous and heterogeneous fields may looks very similar. The similarity should decrease though for higher modes. |
Hello,
I am trying to run the MCA with two variables, which are a climate model, WRF's output.
I get this error right after the bit:
ValueError: coordinate lon has dimensions ('south_north', 'west_east'), but these are not a subset of the DataArray dimensions ['lat', 'lon', 'mode']
Would really appreciate any help with this error. Many thanks.
The text was updated successfully, but these errors were encountered: