-
Notifications
You must be signed in to change notification settings - Fork 32
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
fixing the cutoff-longitude, ckd-lost-in-NaN problem, enabling CS SN computation #235
Conversation
Hello @MaceKuailv! 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! 🍻 Comment last updated at 2022-07-06 08:25:29 UTC |
@MaceKuailv please fix the failing tests. Then @malmans2 please review. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #235 +/- ##
==========================================
- Coverage 96.75% 95.59% -1.16%
==========================================
Files 10 10
Lines 3570 3634 +64
Branches 775 773 -2
==========================================
+ Hits 3454 3474 +20
- Misses 67 109 +42
- Partials 49 51 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
the conf.py file need to "import oceanspy" which will require import utils which will then "from numba import njit". I have to try except import numba, and if that does not work I need to change njit to a function that reads function f and returns the exact same function f. |
oceanspy/utils.py
Outdated
# Jiang being a bit lazy | ||
import numpy as np | ||
|
||
try: | ||
from numba import njit | ||
except ImportError: # pragma: no cover | ||
|
||
def njit(f): | ||
return f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a bit cleaner to do something like this:
# Jiang being a bit lazy | |
import numpy as np | |
try: | |
from numba import njit | |
except ImportError: # pragma: no cover | |
def njit(f): | |
return f | |
import numpy as np | |
try: | |
import numba | |
has_numba = True | |
except ImportError: | |
has_numba = False | |
def conditional_njit(f): | |
if has_numba: | |
return numba.njit(f) | |
return f |
I imagine you are seeing quite a bit of improvement using numba. Fell free to use the decorator on other functions as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the comment! I assume I need to change all the @njit to @conditional_njit in the rest of the code. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct! also, I haven't tested the snippet above - hopefully it works fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. I am going to test it
oceanspy/_oceandataset.py
Outdated
x_stack = x.stack(points=x.dims).fillna(rid_value).values | ||
y_stack = y.stack(points=y.dims).fillna(rid_value).values | ||
z_stack = z.stack(points=z.dims).fillna(rid_value).values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work if you use .data
instead of .values
? That way dask arrays are not loaded into memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested that. But since the very next step is to feed the whole thing into scipy, I think laziness is not really necessary here. I believe it is also values in the original code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use .data
if it works. It wasn't available when we first started working on oceanspy and it is possible that SciPy is/will be able to use dask laziness
oceanspy/utils.py
Outdated
read the od grid things into numpy arrays | ||
stored in this module | ||
""" | ||
global Z, Zl, dZ, dZl, dXC, dYC, dXG, dYG, XC, XG, YC, YG, CS, SN, tree, ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to avoid global variables as much as possible (or it would be better to use python's cache decorators)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very true. This is actually a temporary solution. My plan is to put the functions you see here into the _oceandataset as methods, and those global variables in the util module will be in the class oceandataset. But oceandataset is very fundamental to a lot of the operations, so I want to be more careful when making changes to it.
…ata in create_tree(I will look at other functions at some later time)
@MaceKuailv the variables |
oceanspy/compute.py
Outdated
@@ -2833,6 +2834,43 @@ def salt_budget(od): | |||
return _ospy.OceanDataset(ds).dataset | |||
|
|||
|
|||
def find_cs_sn(thetaA, phiA, thetaB, phiB): | |||
""" | |||
theta is the angle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should improve the description of this function. What does it do? Input and outputs.
oceanspy/utils.py
Outdated
@@ -18,6 +18,31 @@ | |||
except ImportError: # pragma: no cover | |||
pass | |||
|
|||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do instead
import numpy as _np
this is consistent with the rest of oceanspy.
oceanspy/utils.py
Outdated
CS = np.array(od._ds.CS).astype("float32") | ||
SN = np.array(od._ds.SN).astype("float32") | ||
tree = od.create_tree(gridtype) | ||
if gridtype == "C": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can create confusion, since oceanspy is only compatible with c-grids. Instead of gridtype
, use something like gridloc
(as in location) or something. We don't want to suggest that these are different types of grids...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaceKuailv Please make these fixes and @asiddi24 will investigate the failing 3.10 build (also for #237).
Ready to be merged when the _xe problem is fixed |
See #238 |
If you trigger the CI should be all good now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Noice |
#215 : Now when you cut off from 179 to -179 you are cutting out 2 degree instead of 358. The test is also updated
#228 : Fillna in the create tree function, so that ckd tree works on llc-rearranged grid.
#234 : A new function in compute.py to calculate the grid orientation using spherical triangles.