MITgcm/xmitgcm

Error when trying to load only 'U' or 'V' from an llc dataset

Closed this issue · 4 comments

I've been trying to run the following code to extract 'U' or 'V' from the llc4320 dataset.

import xmitgcm.llcreader as llcreader

model = llcreader.ECCOPortalLLC4320Model()
ds_vel = model.get_dataset(varnames=['U'], type='latlon', iter_start=10368, iter_stop=10369)

If varnames is set to either ['U'] or ['V'] an error message is received. If it is set to ['U', 'V'] the function runs as expected. This isn't a problem if loading other variables. on their own such as 'Eta' or 'W'.

The error message is below:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-9a90c8e0ac18> in <module>
----> 1 ds_vel = model.get_dataset(varnames=['U'], type='latlon', iter_start=10368, iter_stop=10369)

~/anaconda3/envs/xmitgcm_env/lib/python3.8/site-packages/xmitgcm-0.4.1+20.g7c5305c-py3.8.egg/xmitgcm/llcreader/llcmodel.py in get_dataset(self, varnames, iter_start, iter_stop, iter_step, k_levels, k_chunksize, type, read_grid, grid_vars_to_coords)
    727 
    728         transformer = data_transformers[type]
--> 729         data = transformer(data_facets, _VAR_METADATA)
    730 
    731         # separate horizontal and vertical grid variables

~/anaconda3/envs/xmitgcm_env/lib/python3.8/site-packages/xmitgcm-0.4.1+20.g7c5305c-py3.8.egg/xmitgcm/llcreader/llcmodel.py in _all_facets_to_latlon(data_facets, meta)
    354             mate = meta[vname]['attrs']['mate']
    355             vector_pairs.append((vname, mate))
--> 356             vnames.remove(mate)
    357         except KeyError:
    358             pass

ValueError: list.remove(x): x not in list

There is also no problem if type is set to 'faces'

This is an interesting issue.

The challenge here is that U and V are actually tightly coupled together in the LLC4320 internal data storage format. When transforming to the latlon grid, we mix together U and V. So it's not possible to get one without the other.

I think the best path forward would be to add a quick check in get_dataset to ensure that all the metric vector pairs are present and raise an error if not. Would that satisfy you?

Ah I hadn't realised how U and V were coupled in that way. I think a check in get_dataset would be really useful in helping users identify what's going on!

The place to add this check would be be right after this:

all_vector_components = [inner for outer in (vector_pairs + metric_vector_pairs)
for inner in outer]

Would you feel comfortable implementing this yourself and making a pull request? That is certainly the fastest way to get the feature you desire! 😉

Yes, I'll have a crack at it somepoint this week 👍