MITgcm / xmitgcm

Read MITgcm mds binary files into xarray
http://xmitgcm.readthedocs.io
MIT License
56 stars 65 forks source link

Custom Grid Vars & Extra Variables for llcreader #308

Open timothyas opened 2 years ago

timothyas commented 2 years ago

This implements two things:

  1. Within the core mds_store: allow a user to add "on-the-fly" grid variables, or really any meta/data pair that does not have a 10 digit iteration number. For example, if we have a file smooth2Dnorm001.meta/data in our run_directory:
custom_grid_vars = {'smooth3Dnorm001': {
    'dims': ['k', 'j', 'i'], 
    'attrs': {
        'standard_name': 'normalization_factor',
        'long_name': 'WC01 normalization factor',
        }
    }
}
ds = open_mdsdataset(run_dir, grid_dir, ..., custom_grid_variables=custom_grid_vars)
  1. For llcreader, add this capability and #205 to add extra_variable meta information to an llcmodel, e.g.
fs = LocalFileSystem()
store = llcreader.BaseStore(fs, base_path=data_dir, grid_path=grid_dir)
model = llcreader.LLC90Model(store)
ds = model.get_dataset(varnames=['smooth3Dnorm001'], extra_variables=custom_grid_vars, ...)

@cspencerjones: Hopefully with this PR my comment to #307 makes more sense. You could use this to add your SSU/SSV variables on-the-fly as with the extra_variables capability for mds_store. The only issue is if those SSU/SSV files are on a different grid, things will get more complicated, but if they're on the global grid this should work no problem.

I'll keep this as a draft for now because I need to add tests.

timothyas commented 2 years ago

Tests currently fail due to the issue described in #312. They do pass when the pytest fixture scope is set to "function", as described in that issue.