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

faces_dataset_to_latlon function requires metric_vector_pairs to be present #158

Closed
rabernat opened this issue Jul 11, 2019 · 0 comments · Fixed by #197
Closed

faces_dataset_to_latlon function requires metric_vector_pairs to be present #158

rabernat opened this issue Jul 11, 2019 · 0 comments · Fixed by #197

Comments

@rabernat
Copy link
Member

The default value of metric_vector_pairs in faces_dataset_to_latlon is metric_vector_pairs=[('dxC', 'dyC'), ('dyG', 'dxG')]. The function errors if I call it on a dataset that doesn't have these variables present.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/Code/xarray/xarray/core/dataset.py in _construct_dataarray(self, name)
    975         try:
--> 976             variable = self._variables[name]
    977         except KeyError:

KeyError: 'dxC'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-11-dc713ebaf709> in <module>()
      1 ds = xr.merge([sst, u, v])
----> 2 ds = llcreader.llcmodel.faces_dataset_to_latlon(ds)#, metric_vector_pairs=[])
      3 ds

~/Code/xmitgcm/xmitgcm/llcreader/llcmodel.py in faces_dataset_to_latlon(ds, metric_vector_pairs)
    289         data_vars[vname_v] = xr.Variable(_drop_facedim(ds[vname_v].dims), data_v, ds[vname_v].attrs)
    290     for vname_u, vname_v in metric_vector_pairs:
--> 291         data_u, data_v = _faces_to_latlon_vector(ds[vname_u].data, ds[vname_v].data, metric=True)
    292         data_vars[vname_u] = xr.Variable(_drop_facedim(ds[vname_u].dims), data_u, ds[vname_u].attrs)
    293         data_vars[vname_v] = xr.Variable(_drop_facedim(ds[vname_v].dims), data_v, ds[vname_v].attrs)

~/Code/xarray/xarray/core/dataset.py in __getitem__(self, key)
   1056 
   1057         if hashable(key):
-> 1058             return self._construct_dataarray(key)
   1059         else:
   1060             return self._copy_listed(np.asarray(key))

~/Code/xarray/xarray/core/dataset.py in _construct_dataarray(self, name)
    977         except KeyError:
    978             _, name, variable = _get_virtual_variable(
--> 979                 self._variables, name, self._level_coords, self.dims)
    980 
    981         needed_dims = set(variable.dims)

~/Code/xarray/xarray/core/dataset.py in _get_virtual_variable(variables, key, level_vars, dim_sizes)
     80         ref_var = dim_var.to_index_variable().get_level_variable(ref_name)
     81     else:
---> 82         ref_var = variables[ref_name]
     83 
     84     if var_name is None:

KeyError: 'dxC'

Workaround for now is to just pass metric_vector_pairs=[], but this is obviously a bug.

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

Successfully merging a pull request may close this issue.

1 participant