pyoceans / python-oceans Goto Github PK
View Code? Open in Web Editor NEWMisc tools for oceanographers
Home Page: https://pyoceans.github.io/python-oceans
License: BSD 3-Clause "New" or "Revised" License
Misc tools for oceanographers
Home Page: https://pyoceans.github.io/python-oceans
License: BSD 3-Clause "New" or "Revised" License
(Trivial first aesthetic tweak: use a list comprehension or generator in the first line. But maybe all this would be handled in a decorator eventually anyway.)
In this case, the simplest change I would make is to leave the coefficient tables as lists of lists, or lists of tuples. Converting to ndarrays is not helping anything, and is actually adding a tiny bit of overhead.
The loops could use the more idiomatic form:
gamma = np.zeros_like(SP) for i, j, c in Fit: gamma += c * (SP**i * pt**j)Going farther, I would take all the Fit tables out of the functions, make them named module-level variables, and probably collect them in a dictionary. (Same for the polygons, which I would probably save as 2-D ndarrays--I think shapely can handle them efficiently.) Then I would use a single function to handle the loop, with the Fit table as a third argument. This would allow for future optimization of that single critical function, if desired; it would clarify the common logic; it would minimize repetition; and it would be slightly faster because all the table initialization would be done only once, at import time.
Additionally, I would look at the main function to see whether it is really necessary to calculate gamma for all the oceans; I suspect one could calculate weights first, and omit the gamma calculation for any region with zero weight.
Is some normalization of the input lat/lon range needed to make everything work with the region polygons? Are there potential problems with crossing the dateline, or the prime meridian?
XX = np.sin(45 * np.pi / 180) need to be squared
And verify whole formula:
Fofonoff 1983, page 28 (https://repository.oceanbestpractices.org/bitstream/handle/11329/109/059832eb.pdf?sequence=1&isAllowed=y)
GR = 9.780318 * (1.0 + (5.2788e-3 + 2.36e-5 * XX) * XX) + 1.092e-6 * D
P = D / GR
Hi @ocefpaf,
How should be the properly way to check the existence of nans inside any of arrays used to compute variables?
I have found match_args_return but this do not do the job; or at least I did not find the desired results.
from oceans.utilities import match_args_return
a = np.array([0, 1, np.nan, 2, 3, np.nan])
match_args_return(a)
returns an AttributeError
:
29 self.func = func
30 self.__doc__ = func.__doc__
---> 31 self.__name__ = func.__name__
32
33 def __call__(self, *args, **kw):
AttributeError: 'numpy.ndarray' object has no attribute '__name__'
This kind of masking (where each of the function input arrays are masked based on other input) should be defined inside python-oceans
or it's better let the users define it?
@arnaldorusso I am a little swamped by work right now and I cannot investigate what is happening with woa_subset
. It might be just a server issue, and restarting travis-ci would fix it, or some variable name might have changed... Anyways, I have plans to re-write woa_subset
completely using iris instead of the hackish function we have now.
If you want to:
Hi Filipe,
Are you aware about those errors?
sw_extras.py|777 col 1 error| E0602 undefined name 'swstate' [pyflakes]
sw_extras.py|782 col 1 error| E0602 undefined name 'swstate' [pyflakes]
sw_extras.py|783 col 1 error| E0602 undefined name 'swstate' [pyflakes]
sw_extras.py|784 col 1 error| E0602 undefined name 'adiabattempgrad' [pyflakes]
... with cartopy
def get_woa profile(lon, lat):
"""insert code here!"""
Check Weiss 1970 table
At least some basic module descriptions...
Need IOOS python 3 channel first
3/2 = 1 not 1.5
I'm thinking that the conversion from T to theta in spice
should be an optional feature. I imagine it is assumed for observational data that T is in situ T. However, a lot of model output comes out as theta (potential temperature).
Maybe it would be good to add theta=False
at the end, then for the following lines, wrap with if not theta:
python-oceans/oceans/sw_extras/sw_extras.py
Lines 546 to 547 in 591e85d
Also this must be referencing an old version of seawater
. sw.ptmp
doesn't exist now. I believe it's now temppot
.
I'm happy to implement all this if it makes sense and this package is still actively developed.
... Check Chris file too!
Hello,
I can't find the subroutine "seawater.py", which is essential to calculate several parameters from the routine sea_extras.py.
Thank you in advance
Hugo D
Convert into notebooks and add it to the Python course.
I need to write some basic vector calculations (u, v from speed, dir; rotations; etc) and I need them multiple places so it might be nice to officially have these somewhere. Additionally I would add metadata for new variables for DataArrays.
But that also begs the question โ could this package work for both incoming xarray Datasets and pandas DataFrames? That sounds useful.
What do you think @ocefpaf?
Make a lazy iris import
Hi Filipe,
Do you intend to improve this package and turn it more popular for academic usage?
If you think it could be nice, I can push myself a little to pump it out.
Cheers,
Arnaldo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.