Error about missing metrics in a derived variable
Closed this issue · 9 comments
- I have a dataset from an ocean model (ROMS).
- I use
resample
to compute daily-averaged values of two variables, do some basic operations to remove the monthly climatology and compute the covariance of the anomalies. - When I use
xroms.ddxi
to get the x-derivative of the covariance, I get an error message complaining about the absence of metrics.
I have uploaed a copy of the notebook (in html format) which shows the error message here (have omitted some initial cells to create the list of filenames, etc.)
The attached notebook shows the grid
attribute is present for the variable uT_atu
so I am not sure why I am getting that error message.
I converted the array into a dataset before repeating step 3 (refer previous message). Still get the same error. [Edit: I had to manually add a set of variables (xroms_vars
and zeta
) into the dataset to ensure the xroms.roms_dataset
step works.)
ds_derived = uT_atu.to_dataset(name='uT_atu')
for key in xroms_vars:
ds_derived[key] = ds0[key]
ds_derived['zeta']=ds0['zeta']
ds_derived,grid_derived = xroms.roms_dataset(ds_derived)
There are also a couple of other things that are a bit puzzling to me. The xroms.ddxi
command works (as it should) on a standard variable (u
) from the dataset.
- Unless I specify
scoord='s_rho'
, the result ofxroms.ddxi
applied tou
ends up with ans_w
vertical coordinate. Not sure why. - The output from
xroms.ddxi
ofu
ends up doubling the size of the original array when I would have thought they should be nearly the same size.
It looks like xroms.ddz(uT_atu,grid_derived)
works on the derived variable but both xroms.ddxi
and xroms.ddeta
fail with the error message described earlier.
@tlsw231 Thanks for bringing this over here from Pangeo's discourse, in particular because it helped me realize that I didn't have my notifications set up to watch this repo!
I haven't had a chance to try to reproduce this error and dig into it — I'm currently on maternity leave with inconsistent time at my computer! I intend to do so when I can though.
I think I figured out what was the problem, took some wading through.
- I was using
resample
(step 2 in my first post) which drops the time-varying coordinatez_rho_u
but retains the time-invariant coordinatez_rho_u0
. This was causing the following line inxroms/utilities.py
to outputz_rho_u0
:
z_coord_name = coords[[coord[:2] == "z_" for coord in coords].index(True)]
,
which was then triggering errors in the code downstream.
- The error vanishes and I get meaningful output if I use
resample
andreset_coords(drop=True)
in the same step. Thereset_coords
ends up dropping bothz_rho_u0
andz_rho_u
.
So, it looks like if there are no coordinates beginning with z_
the xroms.ddxi
step goes through. But if there is only one coordinate beginning with z_
and it happens to be z_rho_u0
then I face the issue outlined above. More generally, this problem might arise after any calculation that ends up dropping the time-varying z_
coordinates while retaining the time-invariant z_
coordinates.
While reset_coords
appears to fix the issue, I have to wonder how accurate the xroms.ddxi
calculation will be given it is taking place without any knowledge of the underlying vertical grid. Will it not be less accurate compared to the case where I apply it directly to a variable in the dataset, e.g., ds['u']
, which has both z_rho_u
and z_rho_u0
?
Even when both z_rho_u0
and z_rho_u
are present, this line will return the former if it appears earlier in the sequence of coordinates.
z_coord_name = coords[[coord[:2] == "z_" for coord in coords].index(True)]
Can this be changed to the following?
z_coord_name = coords[ ([coord[:2] == "z_" and "0" not in coord) for coord in coords].index(True)]
Hi @tlsw231! I'm setting up to work on xroms again over time. I think I'll start with improving some of the basics like packaging before diving back into the details, but I intend to get back to you on this soon. Thanks for the issue report.
Hi @tlsw231! I've recently put out a new version to PyPI (v0.2.4, still coming through on conda-forge). Please check to see if this issue is still present in the new version so that over time we can work to address these. Thanks!