hainegroup / oceanspy

A Python package to facilitate ocean model data analysis and visualization.
https://oceanspy.readthedocs.io
MIT License
96 stars 32 forks source link

set_grid_coords from xgcm? #429

Closed jiand1219 closed 3 months ago

jiand1219 commented 3 months ago

Description

Hi, many thanks for developing oceanspy!!!

I am testing post-processing self-generated MITgcm output using oceanspy on my own environment. a silly question: is it possible to pass (xgcm) Grid object information to the oceanspy , so I could utilize built-in functions?

What I Did

I simply get grid info using xgcm, 
grid = Grid(mydata, metrics=metrics)
grid
<xgcm.Grid>
T Axis (periodic, boundary=None):
  * center   time
Z Axis (periodic, boundary=None):
  * center   Z --> left
  * outer    Zp1 --> center
  * right    Zu --> center
  * left     Zl --> center
X Axis (periodic, boundary=None):
  * center   XC --> left
  * left     XG --> center
Y Axis (periodic, boundary=None):
  * center   YC --> left
  * left     YG --> center

my understanding is I need to pass those information to ospy.OceanDataset(mydata), 
should I do something like this or is there a simpler way?

grid_coords = {
    "Y": {"Y": None, "Yp1": 0.5},
    "X": {"X": None, "Xp1": 0.5},
    "Z": {"Z": None, "Zp1": 0.5},
    "time": {"time": -0.5}
}
grid_coords = {"add_midp": True, "overwrite": True, "grid_coords": grid_coords}

od = od.set_grid_coords(**grid_coords)

thanks in advance! Dong

Mikejmnez commented 3 months ago

Hi @jiand1219, thanks for writing and sorry for the late reply! The answer is yes, you can, and that is the correct way to do just that. You can always check whether your grid object was built correctly by extracting it from the OceanDataset object either by assigning it to a variable, or simply by

od.grid