Skip to content
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

Compute u- / v- transect from area dataset #208

Open
tsemmler05 opened this issue Oct 23, 2024 · 2 comments
Open

Compute u- / v- transect from area dataset #208

tsemmler05 opened this issue Oct 23, 2024 · 2 comments

Comments

@tsemmler05
Copy link

I'm using Martina's pyfesom2 version on levante: /work/ba1264/a270210/fesom_plot_tools/pyfesom2/

Description

I would like to plot a cross section of u and v for the Greenland - Scotland ridge using 3D u- and v- fields on the DART mesh.
Because of memory issues, I can't directly compute an u- or v- transect from the complete 3D u- and v- fields. For this reason, I first use the accessor utility to select a small area that encompasses the transect.

What I did:

from pyfesom2.datasets import open_dataset
mesh_path = "/work/ba1264/a270210/model/input/fesom2/dart/"
data_pathu1 = "/work/ab0995/a270062/runtime/awicm3-v3.1_refactoring/TCO319L137-DART/ctl1950d/outdata/fesom/u.*"
fesom_u1ds = open_dataset(data_pathu1, mesh_path)
datautemp1=fesom_u1ds.pyfesom2.select(region=(-30, 56, -2, 71))
#Greenland - Scotland ridge
lon_start = -27
lat_start = 68.5
lon_end = -5
lat_end = 59
npoints = 50
lonlat = pf.transect_get_lonlat(lon_start, lat_start, lon_end, lat_end, npoints)
u_nodes1 = pf.tonodes3d(datautemp1, mesh_path)

The last command throws an error because datautemp1 doesn't seem to have the shape that is expected:


AttributeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 u_nodes1 = pf.tonodes3d(datautemp1, mesh_path)
2 v_nodes1 = pf.tonodes3d(datavtemp1, mesh_path)
3 u_nodes2 = pf.tonodes3d(datautemp2, mesh_path)

File /work/ba1264/a270210/fesom_plot_tools/pyfesom2/pyfesom2/regridding.py:706, in tonodes3d(component, mesh)
691 def tonodes3d(component, mesh):
692 """Interpolate 3D data from elements to nodes.
693
694 Parameters
(...)
704 2D data (nodes, levels) on nodes
705 """
--> 706 levels = component.shape[1]
707 out_data = np.zeros((mesh.n2d, levels))
708 for level in range(levels):

File /sw/spack-levante/mambaforge-22.9.0-2-Linux-x86_64-kptncg/lib/python3.10/site-packages/xarray/core/common.py:276, in AttrAccessMixin.getattr(self, name)
274 with suppress(KeyError):
275 return source[name]
--> 276 raise AttributeError(
277 f"{type(self).name!r} object has no attribute {name!r}"
278 )

AttributeError: 'Dataset' object has no attribute 'shape'

@koldunovn
Copy link
Member

Tido, did you consider trying to have a loop over time steps, and select data fro transects one by one?
The most efficient way to work with just several points is anyway first to load things into memory.

@tsemmler05
Copy link
Author

Originally, I had first computed an average value for both u and v for two different time periods:

startyear1=1990
endyear1=2010
startyear2=2080
endyear2=2100
datautemp1 = pf.get_data(datapath1, "u", [startyear1, endyear1], mesh, how="mean", compute="True")
datautemp2 = pf.get_data(datapath2, "u", [startyear2, endyear2], mesh, how="mean", compute="True")
datavtemp1 = pf.get_data(datapath1, "v", [startyear1, endyear1], mesh, how="mean", compute="True")
datavtemp2 = pf.get_data(datapath2, "v", [startyear2, endyear2], mesh, how="mean", compute="True")

and then transformed from elements to nodes for the average values:

u_nodes1 = pf.tonodes3d(datautemp1, mesh)
v_nodes1 = pf.tonodes3d(datavtemp1, mesh)
u_nodes2 = pf.tonodes3d(datautemp2, mesh)
v_nodes2 = pf.tonodes3d(datavtemp2, mesh)

For the CORE2 mesh, this works perfectly fine, but not for the DART mesh (that's why I thought to select a subregion first and then compute the transect for the average value for just the subregion). If I first compute an average value, it should be in terms of memory the same as if I would do it for a particular time step, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants