AntSimi / py-eddy-tracker

Eddy identification and tracking
https://py-eddy-tracker.readthedocs.io/en/latest/
GNU General Public License v3.0
122 stars 50 forks source link

How to detect the eddy from the model SSH outputs without NC format #44

Closed liu-ran closed 3 years ago

liu-ran commented 3 years ago

Hi, I found this software seems to only support the SSH with NC format. So how to detect the eddy from the model SSH outputs without NC format through the software?

AntSimi commented 3 years ago

Hi, You could do identification only with numpy matrix if you want, but you need to control all step manually:

To create a GridDataset object with numpy array:

from py_eddy_trakce.dataset.grid import RegularGridDataset
regular_grid = RegularGridDataset.with_array(
    coordinates=(lon_name, lat_name),
    datas=dict(
        grid_name=z,
        lon_name=lon,
        lat_name=lat,
        ...
    )
)

And with this object you must do something similar to this example.

Antoine

liu-ran commented 3 years ago

@AntSimi Many thanks! But I found that the 'with_array' seems to return a wrong lat/lon dimensions. For example, I input the lon with shape (480,), but the 'with_array' return the lon with (481,) and then fail to pain. My code is as follow:

微信图片_20210107202044

微信图片_20210107202034

AntSimi commented 3 years ago

ok 2 things:

working test

import numpy as np
from py_eddy_tracker.dataset.grid import RegularGridDataset
from matplotlib import pyplot as plt
g = RegularGridDataset.with_array(('x','y'), dict(z=np.ones((30,60)),x=np.arange(30), y=np.arange(60)))
ax=plt.subplot(111)
g.display(ax, 'z')
plt.show()

test with same error than you

If i transpose matrix, so dimension order is like this : (y,x), i get same error, problem come from dimension order and not dimensions size.

import numpy as np
from py_eddy_tracker.dataset.grid import RegularGridDataset
from matplotlib import pyplot as plt
g = RegularGridDataset.with_array(('x','y'), dict(z=np.ones((30,60)).T,x=np.arange(30), y=np.arange(60)))
ax=plt.subplot(111)
g.display(ax, 'z')
plt.show()
liu-ran commented 3 years ago

@AntSimi You are right. That's great! I still have a question. How to make the z has an attribute 'mask'. If it doesn't have this attribute, the g.add_uv('z') would fail to run.

g = RegularGridDataset.with_array(('x','y'), dict(z=np.ones((30,60)).T,x=np.arange(30), y=np.arange(60)))

The error information about the 'mask' is as follow: 微信图片_20210108010033

AntSimi commented 3 years ago

In most of case you have land on grid and this land is masked with ma.array from numpy. In py eddy tracker software, we do the assumption that grid have a mask, when we load netCDF, software check this feature and add mask if needed. In your case you must do manually, something like that in case of grid which are only on ocean:

from numpy import ma, zeros
etacache = ma.array(etacache, mask=zeros(etacache.shape, dtype="bool"))

In case of nan use, replace nan by a mask.

liu-ran commented 3 years ago

@AntSimi Awesome! Thank you very much! I read the add_uv code and found that the x_c and y_c should be degrees. But my model grid is a rectangle grid with 2400km*1200km as the picture shows. I will try to input the geostrophic u and the v by myself and then see if the eddy identification can work. The py-eddy-traker sofaware is so great that I really want to apply it to detect the eddies in my model simulation. Thanks again for your help.

微信图片_20210108173644

AntSimi commented 3 years ago

Ok, your grid seems not to be a RegularGrid for my mind, your longitude and latitude are not degrees evenly spaced. So normaly you must use UnregularGridDataset like in issue #5 but i didn't test with_array method in this class. You need degrees coordinates in lot of function not only for speed. Maybe some more work are needed, like allow with_array method for UnregularGrid.

Antoine

liu-ran commented 3 years ago

@AntSimi Hi, I'm worried that my description is not accurate due to my poor English.

your grid seems not to be a RegularGrid for my mind, your longitude and latitude are not evenly spaced.

My grid is evenly spaced with 5km resolution. The X-axis is 2400km and reentrant. The Y-axis is 1200km.

You need degrees coordinates in lot of function not only for speed.

Does the eddyidentification also need degrees coordinates? I'm considering making degree coordinates approximately for my model domain according to the Coriolis parameter.

AntSimi commented 3 years ago

Hi,

Software current version need coordinates in degrees!

This software was in first place think to be apply on CMEMS altimetry product, which are regular grid in degrees. So most of features was thinking for that. In second time we add feature to use "unregular grid" not evenly spaced in degrees (you need a 2D array for each coordinates instead of an 1D array).

Antoine

liu-ran commented 3 years ago

@AntSimi All right. Now I understand. Thanks for your help~

AntSimi commented 3 years ago

I think your goals are achievable without too many changes to your data or code. Just keep in mind that the UnregularGridDataset class is poorer in functionality (especially for filtering) for eddy detection. After that it doesn't change anything for tracking.

Antoine