-
Notifications
You must be signed in to change notification settings - Fork 3
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
Auto Discovery of Calculable Values #30
Comments
Totally agree this would be awesome, and should be attempted (iirc it was one of our original goals). Initial thoughts:
|
I think that they are here 2 slightly different features:
|
When trying to implement this feature, we will have a problem: many inputs of the gsw functions don't have cf standard names (e.g. saturation_fraction, entropy, enthalpy, etc). I see 2 ways to handle this:
|
I am on my way to implement this |
About the API, the way I see it would be: I guess we can also add an extra argument: Question: if one user has |
Here is my WIP notebook, with the algo I developed. It is not perfect, but is works well! (it is for now based on names in ds, not on standard names) https://gist.github.com/rcaneill/0aa8b9e72112d079c4919e462a4bb378 |
I tried the other option, i.e. starting from the variable we want, and going backward through the graph, but in the end it was not working (easy to get trapped in cycles), and has around 10 times more lines of code. So I thing that it is better to do it the way I do in the notebook. |
|
That looks neat. I'll need to play with it a bit to understand the graph, but looks like a good starting place. Some thoughts in no particular order:
Mock example attempt: from gsw_xarray import accessors # or whatever it needed to register the xarray accessor under the gsw namespace
ds = xr.load_dataset("some_dataset.nc")
# now we use the accessor to get GSW properties, things that need intermediate calculations should just call the accessor itself
SA = ds.gsw["SA"] # uses PSAL or whatever it needs
rho = ds.gsw["rho"] # internally calls ds.gsw["SA"], and ds.gsw["CT"] |
Do you have any precise idea for this?
My guess is that step would be quite strait forward as soon as the function behind is written (I never wrote a xarray accessor before so indeed it will not be so easy) |
While working on this I realized that I need to write the option to work with dataset before (e.g. You can answer this in PR #53 |
I was thinking of a feature that would be nice to have (in a short / long term future): being able to give a dataset
ds
to the gsw wrapped functions, and gsw-xarray would then get fromds
the necessary dataarrays, based on their standard_name. So one could use:gsw.sigma0(ds)
. This can lead to many problems (e.g. how to deal with datasets containing more than 1 array for 1 standard_name), but we can keep the discussion on how to solve these problems for later, if we decide to implement this feature.Originally posted by @rcaneill in #1 (comment)
The text was updated successfully, but these errors were encountered: