xgcm / xgcm-examples

Examples and tutorials for xgcm
MIT License
12 stars 12 forks source link

add inferring metrics notebook #7

Open miniufo opened 3 years ago

miniufo commented 3 years ago

Hi @jbusecke, I am now sending the inferring metrics notebook in this PR. If this is OK, I'll close xgcm/xgcm#196.

review-notebook-app[bot] commented 3 years ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

jbusecke commented 3 years ago

Thank you very much for migrating this. The tests are failing, because the data you are using is not stored in the repository itself anymore. I uploaded it to zenodo. You can simply copy the code to load it from there into the notebook:

# download the data
import urllib.request
import shutil

url = 'https://zenodo.org/record/4421428/files/'
file_name = 'mitgcm_example_dataset_v2.nc'
with urllib.request.urlopen(url + file_name) as response, open(file_name, 'wb') as out_file:
    shutil.copyfileobj(response, out_file)

# open the data
ds = xr.open_dataset(file_name)
ds

It should be pretty much the same as in 02_mitgcm.ipynb. Once the CI is fixed I will give it another good read, and then we can merge this. This will be a great addition!

miniufo commented 3 years ago

I think I am getting used to this work flow. After I change the file from zenodo, checks still failed. But this time it is on purpose so that one can see where the error was thrown if the metrics are not provided correctly. So how to resolve this? @jbusecke

jbusecke commented 3 years ago

I see. That is a very good question indeed.

Looping in @rabernat here. @miniufo has created this nice notebook, which illustrates some examples that produce failing cells (something that I also often do), but since these cells prevent the notebook to be executed in one go, binderbot is failing. Do you have a recommended workaround for this?

My only idea would be to wrap both the code and the error in Markdown and make them 'non-interactive' but maybe there is a better way?

miniufo commented 3 years ago

I guess we don't have any better way right now? So I'll wrap them in Markdown. If there is a better way, I may send another commit.

rabernat commented 3 years ago

Do you have a recommended workaround for this?

Yes! You use the expectexception package, as in this notebook:

https://github.com/xarray-contrib/xarray-tutorial/blob/master/scipy-tutorial/03_computation_with_xarray.ipynb

miniufo commented 3 years ago

I tried this package, installed it, and typed the example. But I cannot get any difference with or without the magic. image

jbusecke commented 3 years ago

Hi @miniufo thanks for persisting on this. From what I understand you shouldnt see any difference, except that you should be able to have a code cell underneath the failing one, and would still be able to run the full notebook. I think this magic basically just prevents the notebook execution from stopping when it hits an error.

Can you try to put %%expectexception ... in all the failing cells and those changes to the branch? We might have to add the package to the binder environment but lets try this first.

jbusecke commented 3 years ago

Ok as suspected we need to provide the module to the binder environment. Let me check how to do that... @rabernat quick question: This has so far been working with the pangeo-gallery/default-binder, but we need to add a custom package. Do you recommend to make a whole new repo for that (seems excessive), or is there a way to use the xgcm environments? Or provide the environment in this repo?

Just trying to figure out what the least messy way to do this is.