BoldingBruggeman / pyncview

PyNcView is a cross-platform NetCDF viewer written in Python. It provides an easy-to-use graphical user interface to the creation of animations and publication-quality figures.
GNU General Public License v2.0
18 stars 1 forks source link

GETM level > depth #4

Open johansoderkvist opened 3 years ago

johansoderkvist commented 3 years ago

I am not able to display the actual depth values on y-axis when plotting GETM files that has "level" as vertical dimension. Both multiplot and pyncview display level-number on y-axis when plotting GETM nc-file variable[time,level,latc,lonc] Is there any way to change from level to depth on y-axis?

Best regards Johan

jornbr commented 3 years ago

Hi Johan,

PyNcView/multiplot/xmlplot pick coordinate variables based on the CF coordinates attribute. If that attribute is not present for the variable you are plotting, it will use a coordinate variable with the same name as the dimension itself (here: level), or if not present, a series of integers. So the "ultimate" solution would be to make sure the variable you are viewing has the coordinates attribute. If that is not an option, you can manually force PyNcView to use a specific coordinate variable for any given dimension, by right-clicking the filename in the tree on the left, and choosing "Reassign coordinates...". Multiplot takes a --reassign argument that should achieve the same.

Cheers,

Jorn

markusReinert commented 2 years ago

Hi,

have you already solved your problem, @johansoderkvist? There seemed to have been a discussion on a similar issue: https://groups.google.com/g/getm-users/c/R80Q8HHkhF0

This discussion, however, does not talk about the case of sigma coordinates. I realized that my GETM files created with flexible output are only shown correctly in pyncview if I use adaptive coordinates but not if I switch to sigma coordinates. In the latter case, the vertical coordinate is "sigma" and not converted to "depth", similar to @johansoderkvist's issue.

I found the explanation for this behavior in the file netcdf.py. The method testFile of NetCDFStore_GOTM explains the convention that is assumed for a GOTM/GETM dataset:

# Test for GETM convention for general, hybrid or adaptive vertical coordinates.
if 'level' in ncdims and 'bathymetry' in ncvars and ('h' in ncvars or 'hmean' in ncvars): match = True

# Test for GETM convention for sigma vertical coordinates.
if 'sigma' in ncdims and 'bathymetry' in ncvars and ('elev' in ncvars or 'elevmean' in ncvars): match = True

As we can see, the convention is different for adaptive and sigma coordinates. In the first case, pyncview requires the variables bathymetry and h (which is called hn by default in GETM flexible output), while in the latter, elev is needed instead of hn. This seems inconsistent to me, because the calculation of depth is also possible in sigma coordinates if bathymetry and h are given. For me, this caused the issue in pyncview, because I used to call sea surface elevation eta instead of elev.

I suggest that this behavior should be documented, as it is not obvious which fields are required for the conversion from level/sigma to depth in pyncview, and which names the variables should have. In addition, it might also be a good option to allow bathymetry and h for the case of sigma-coordinates.

Where should we document the convention of vertical coordinates for GETM in pyncview?

Cheers, Markus