Comments (5)
Hi,
You could look here to see an example of use.
add_fields
will create a new dataset with the new field which must be filled.
Nevertheless several method like grid_stat accept field name or array with same size than dataset.
Antoine
from py-eddy-tracker.
Thanks,
But a2 = a.add_fields(("dx",))
throws the following error.
Exception Traceback (most recent call last)
in
----> 1 a2=a.add_fields(("dx",))
~/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pyEddyTracker-3.3.0+4.g40ce202.dirty-py3.8.egg/py_eddy_tracker/observations/observation.py in add_fields(self, fields, array_fields)
316 """
317 nb_obs = self.obs.shape[0]
--> 318 new = self.class(
319 size=nb_obs,
320 track_extra_variables=list(
~/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pyEddyTracker-3.3.0+4.g40ce202.dirty-py3.8.egg/py_eddy_tracker/observations/tracking.py in init(self, *args, **kwargs)
66
67 def init(self, *args, **kwargs):
---> 68 super().init(*args, **kwargs)
69 self.__first_index_of_track = None
70 self.__obs_by_track = None
~/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pyEddyTracker-3.3.0+4.g40ce202.dirty-py3.8.egg/py_eddy_tracker/observations/observation.py in init(self, size, track_extra_variables, track_array_variables, array_variables, only_variables, raw_data)
162 for elt in self.elements:
163 if elt not in VAR_DESCR:
--> 164 raise Exception("Unknown element : %s" % elt)
165 self.observations = zeros(size, dtype=self.dtype)
166 self.sign_type = None
Exception: Unknown element : dx
from py-eddy-tracker.
and (for the second suggestion)
extent = [27, 42, 40.5, 47]
bins = ((extent[0], extent[1], step), (extent[2], extent[3], step))
g = a.grid_stat(bins, dx)
also cause some troubles :
TypeError Traceback (most recent call last)
in
----> 1 g = a.grid_stat(bins, dx)
~/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pyEddyTracker-3.3.0+4.g40ce202.dirty-py3.8.egg/py_eddy_tracker/observations/observation.py in grid_stat(self, bins, varname, data)
2010 x0 = bins[0][0]
2011 x, y = (self.longitude - x0) % 360 + x0, self.latitude
-> 2012 data = self[varname] if data is None else data
2013 if hasattr(data, "mask"):
2014 m = ~data.mask
~/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pyEddyTracker-3.3.0+4.g40ce202.dirty-py3.8.egg/py_eddy_tracker/observations/observation.py in getitem(self, attr)
286 if attr in self.elements:
287 return self.obs[attr]
--> 288 elif attr in VAR_DESCR_inv:
289 return self.obs[VAR_DESCR_inv[attr]]
290 elif attr in ("lifetime", "age"):
TypeError: unhashable type: 'numpy.ndarray'
although i have
print(dx.shape)
print(a["radius_e"].shape)
print(type(dx))
print(type(a["radius_e"]))
(26853,)
(26853,)
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
from py-eddy-tracker.
Ok sorry i answered too quickly.
So for grid_stat method use data
option, in this case if you provide only varname the assumption is ouput grid name will be same than eddies dataset, if you use data
option you could choose a name different for output grid and dataset variable.
For your second problem (i didn't think about that yesterday) actually you could only add known variable to be able to convert in netcdf and other things, ...
Antoine
from py-eddy-tracker.
Solved. For those interested, here's how it was done :
extent = [27, 42, 40.5, 47]
step = 0.25
bins = ((extent[0], extent[1], step), (extent[2], extent[3], step))
def dx_to_next(s):
d = distance(
s.longitude[:-1],
s.latitude[:-1],
s.longitude[1:],
s.latitude[:-1],
)
d[s.longitude[1:]<s.longitude[:-1]] = - d[s.longitude[1:]<s.longitude[:-1]]
d[s.index_from_track[1:] - 1] = 0
d_ = np.empty(d.shape[0] + 1, dtype=d.dtype)
d_[:-1] = d/86400
d_[-1] = 0
return d_
def dy_to_next(s):
d = distance(
s.longitude[:-1],
s.latitude[:-1],
s.longitude[:-1],
s.latitude[1:],
)
d[s.latitude[1:]<s.latitude[:-1]] = - d[s.latitude[1:]<s.latitude[:-1]]
d[s.index_from_track[1:] - 1] = 0
d_ = np.empty(d.shape[0] + 1, dtype=d.dtype)
d_[:-1] = d/86400
d_[-1] = 0
return d_
a = TrackEddiesObservations.load_file("../out_"+set1+"/Tracks_Overlap/Anticyclonic.nc")
a.position_filter(median_half_window=1, loess_half_window=5)
dxa=dx_to_next(a)
dya=dy_to_next(a)
ga = a.grid_stat(bins, varname='dx', data=dxa)
gay = a.grid_stat(bins, varname='dy', data=dya)
ga.add_grid("dy", gay.vars['dy'])
X=np.arange(bins[0][0]+bins[0][2]/2,bins[0][1]-bins[0][2]/2,bins[0][2])
Y=np.arange(bins[1][0]+bins[1][2]/2,bins[1][1]-bins[1][2]/2,bins[1][2])
[X,Y]=np.meshgrid(X,Y)
f = plt.figure(figsize=(12,10))
ax = start_axes("Anticyclonic dx", fig=f, sp='221')
m = ga.display(ax,name='dx', **kwargs_q)
update_axes(ax, m)
ax = start_axes("Anticyclonic dy", fig=f, sp='222')
m = ga.display(ax,name='dy', **kwargs_q)
update_axes(ax, m, 'm/s')
ax = start_axes("Anticyclonic Quiver", fig=f, sp='212')
Q=ax.quiver(x=X, y=Y, u=ga.vars['dx'].T, v=ga.vars['dy'].T,transform=ccrs.PlateCarree())
ax.quiverkey(Q=Q, X=.8, Y=.8, U=0.05, label='0.05 m/s', labelpos='E', coordinates="axes")
from py-eddy-tracker.
Related Issues (20)
- Request for help HOT 3
- Bug with matplotlib 3.8
- py_eddy_tracker.dataset.grid issue HOT 6
- pixel position of grid HOT 4
- Lifetime average HOT 3
- The function in the library tried to use Numba to speed up the computation, but received an array of type numpy.ma.MaskedArray that is not supported by Numba. HOT 2
- error about eddy_identification function HOT 2
- Eddies detected on land HOT 6
- Eddy kinetic energy of different types of eddies and its calculation HOT 1
- about from py_eddy_tracker.dataset.grid import RegularGridDataset HOT 1
- Eddy detection issue HOT 3
- batch identification of eddies over multiple days from a single netCDF file HOT 14
- Request for help: No extrema found in contour of xxx pixels in level xxx HOT 6
- Issue reading NEMO UnRegularGrid HOT 2
- grid_count and grid_stat error HOT 2
- The boundary cannot be closed normally, and the longitude and latitude of some points are wrongγ HOT 6
- How to store the eddy tracking results HOT 4
- Data is Empty
- Data is Empty HOT 1
- Cartopy projection HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-eddy-tracker.