boutproject / xBOUT

Collects BOUT++ data from parallelized simulations into xarray.
https://xbout.readthedocs.io/en/latest/
Apache License 2.0
22 stars 10 forks source link

drop_variables argument to open_boutdataset #89

Closed johnomotani closed 4 years ago

johnomotani commented 4 years ago

Allow user to ignore model-specific variables that may not be consistent between files. Ideally the user should not have to do this by hand, so a model-specific function, e.g. open_stormdataset would handle the list of possibly-inconsistent variables for that model.

pep8speaks commented 4 years ago

Hello @johnomotani! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers:

Comment last updated at 2019-12-12 21:37:22 UTC
codecov-io commented 4 years ago

Codecov Report

Merging #89 into master will increase coverage by 0.09%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #89      +/-   ##
==========================================
+ Coverage   47.55%   47.65%   +0.09%     
==========================================
  Files          11       11              
  Lines        1062     1064       +2     
  Branches      212      213       +1     
==========================================
+ Hits          505      507       +2     
  Misses        496      496              
  Partials       61       61
Impacted Files Coverage Δ
xbout/load.py 75.31% <100%> (+0.2%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 36fb6e0...f65c52d. Read the comment docs.

johnomotani commented 4 years ago

How can you solve the problem of inconsistent variables between datasets without passing drop_variables to open_boutdataset?

Ah, I'd assumed it was possible in defining something like an open_stormdataset function, but not actually thought about how. Using a drop_variables argument of open_boutdataset is indeed probably the thing to do. I'll fix the comment.

TomNicholas commented 4 years ago

For anyone reading this in future - I actually don't think it's possible to do this at all without using the drop_variables argument, because otherwise xarray will never perform the merge. Instead do this

# replace 'storm' with whatever your physics model is
def open_stormdataset(datapath=...)
     inconsistent_storm_vars_to_drop = ['var1', 'var2', ...]
     ds =  open_boutdataset(datapath=..., drop_variables=inconsistent_storm_vars_to_drop)

     sd = add_storm_specific_coords(ds)
     return sd

(We should write a docs page about how to do this - and accessors - for your own BOUT++ physics model.)