Skip to content

Commit 587bcef

Browse files
author
adelepoulle
committed
Move and suppression of unused code
1 parent 86a6df8 commit 587bcef

File tree

4 files changed

+46
-720
lines changed

4 files changed

+46
-720
lines changed

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
scripts=[
1919
'src/scripts/EddyIdentification',
2020
'src/scripts/EddyTracking',
21-
'src/scripts/EddyTrackingFull',
22-
'src/scripts/make_eddy_track_aviso.py',
23-
'src/scripts/make_eddy_track_CLS.py',
24-
'src/scripts/make_eddy_track_ROMS.py'],
21+
'src/scripts/EddyTrackingFull'
22+
],
2523
zip_safe=False,
2624
cmdclass={
2725
'build_ext': cython_build_ext,

src/py_eddy_tracker/property_functions.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,54 @@
3333
import numpy as np
3434
from datetime import datetime
3535
from pyproj import Proj
36-
from .tracking_objects import uniform_resample, nearest
36+
from .tracking_objects import nearest
3737
from .observations import EddiesObservations
3838
from .property_objects import Amplitude
3939
from .tools import distance, winding_number_poly, fit_circle_c, poly_contain_poly
4040
from matplotlib.path import Path as BasePath
4141
from scipy.interpolate import griddata
42+
from .tools import distance_vector
43+
from scipy.interpolate import Akima1DInterpolator
44+
45+
46+
def uniform_resample(x_val, y_val, method='interp1d', extrapolate=None,
47+
num_fac=2, fixed_size=None):
48+
"""
49+
Resample contours to have (nearly) equal spacing
50+
x_val, y_val : input contour coordinates
51+
num_fac : factor to increase lengths of output coordinates
52+
method : currently only 'interp1d' or 'Akima'
53+
(Akima is slightly slower, but may be more accurate)
54+
extrapolate : IS NOT RELIABLE (sometimes nans occur)
55+
"""
56+
# Get distances
57+
dist = np.empty_like(x_val)
58+
dist[0] = 0
59+
distance_vector(
60+
x_val[:-1], y_val[:-1], x_val[1:], y_val[1:], dist[1:])
61+
dist.cumsum(out=dist)
62+
# Get uniform distances
63+
if fixed_size is None:
64+
fixed_size = dist.size * num_fac
65+
d_uniform = np.linspace(0,
66+
dist[-1],
67+
num=fixed_size,
68+
endpoint=True)
69+
70+
# Do 1d interpolations
71+
if 'interp1d' == method:
72+
x_new = np.interp(d_uniform, dist, x_val)
73+
y_new = np.interp(d_uniform, dist, y_val)
74+
elif 'akima' == method:
75+
xfunc = Akima1DInterpolator(dist, x_val)
76+
yfunc = Akima1DInterpolator(dist, y_val)
77+
x_new = xfunc(d_uniform, extrapolate=extrapolate)
78+
y_new = yfunc(d_uniform, extrapolate=extrapolate)
79+
80+
else:
81+
raise Exception()
82+
83+
return x_new, y_new
4284

4385

4486
def datestr2datetime(datestr):

src/py_eddy_tracker/property_objects.py

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -33,124 +33,10 @@
3333
from scipy.ndimage import binary_erosion
3434
from scipy.ndimage import minimum_filter
3535
import numpy as np
36-
from netCDF4 import Dataset
3736
from .tools import index_from_nearest_path, distance_matrix
38-
from . import VAR_DESCR, VAR_DESCR_inv
39-
from .observations import EddiesObservations
4037
import logging
4138

4239

43-
class VirtualEddiesObservations(EddiesObservations):
44-
"""Class to work with virtual obs
45-
"""
46-
47-
@property
48-
def elements(self):
49-
elements = super(VirtualEddiesObservations, self).elements
50-
elements.extend(['track', 'segment_size', 'dlon', 'dlat'])
51-
return elements
52-
53-
54-
class TrackEddiesObservations(EddiesObservations):
55-
56-
def extract_longer_eddies(self, nb_min, nb_obs):
57-
m = nb_obs >= nb_min
58-
nb_obs_select = m.sum()
59-
logging.info('Selection of %d observations', nb_obs_select)
60-
eddies = TrackEddiesObservations(size=nb_obs_select)
61-
eddies.sign_type = self.sign_type
62-
for var, _ in eddies.obs.dtype.descr:
63-
eddies.obs[var] = self.obs[var][m]
64-
return eddies
65-
66-
@property
67-
def elements(self):
68-
elements = super(TrackEddiesObservations, self).elements
69-
elements.extend(['track', 'n', 'virtual'])
70-
return elements
71-
72-
def create_variable(self, handler_nc, kwargs_variable,
73-
attr_variable, data, scale_factor=None):
74-
var = handler_nc.createVariable(
75-
zlib=True,
76-
complevel=1,
77-
**kwargs_variable)
78-
for attr, attr_value in attr_variable.iteritems():
79-
var.setncattr(attr, attr_value)
80-
81-
var[:] = data
82-
83-
#~ var.set_auto_maskandscale(False)
84-
if scale_factor is not None:
85-
var.scale_factor = scale_factor
86-
87-
try:
88-
var.setncattr('min', var[:].min())
89-
var.setncattr('max', var[:].max())
90-
except ValueError:
91-
logging.warn('Data is empty')
92-
93-
def write_netcdf(self):
94-
"""Write a netcdf with eddy obs
95-
"""
96-
eddy_size = len(self.observations)
97-
sign_type = 'Cyclonic' if self.sign_type == -1 else 'Anticyclonic'
98-
filename = '%s.nc' % sign_type
99-
with Dataset(filename, 'w', format='NETCDF4') as h_nc:
100-
logging.info('Create file %s', filename)
101-
# Create dimensions
102-
logging.debug('Create Dimensions "Nobs" : %d', eddy_size)
103-
h_nc.createDimension('Nobs', eddy_size)
104-
# Iter on variables to create:
105-
for name, _ in self.observations.dtype.descr:
106-
logging.debug('Create Variable %s', VAR_DESCR[name]['nc_name'])
107-
self.create_variable(
108-
h_nc,
109-
dict(varname=VAR_DESCR[name]['nc_name'],
110-
datatype=VAR_DESCR[name]['nc_type'],
111-
dimensions=VAR_DESCR[name]['nc_dims']),
112-
VAR_DESCR[name]['nc_attr'],
113-
self.observations[name],
114-
scale_factor=None if 'scale_factor' not in VAR_DESCR[name] else VAR_DESCR[name]['scale_factor'])
115-
116-
# Add cyclonic information
117-
self.create_variable(
118-
h_nc,
119-
dict(varname=VAR_DESCR['type_cyc']['nc_name'],
120-
datatype=VAR_DESCR['type_cyc']['nc_type'],
121-
dimensions=VAR_DESCR['type_cyc']['nc_dims']),
122-
VAR_DESCR['type_cyc']['nc_attr'],
123-
self.sign_type)
124-
# Global attr
125-
self.set_global_attr_netcdf(h_nc)
126-
127-
def set_global_attr_netcdf(self, h_nc):
128-
h_nc.title = 'Cyclonic' if self.sign_type == -1 else 'Anticyclonic' + ' eddy tracks'
129-
#~ h_nc.grid_filename = self.grd.grid_filename
130-
#~ h_nc.grid_date = str(self.grd.grid_date)
131-
#~ h_nc.product = self.product
132-
133-
#~ h_nc.contour_parameter = self.contour_parameter
134-
#~ h_nc.shape_error = self.shape_error
135-
#~ h_nc.pixel_threshold = self.pixel_threshold
136-
137-
#~ if self.smoothing in locals():
138-
#~ h_nc.smoothing = self.smoothing
139-
#~ h_nc.SMOOTH_FAC = self.SMOOTH_FAC
140-
#~ else:
141-
#~ h_nc.smoothing = 'None'
142-
143-
#~ h_nc.evolve_amp_min = self.evolve_amp_min
144-
#~ h_nc.evolve_amp_max = self.evolve_amp_max
145-
#~ h_nc.evolve_area_min = self.evolve_area_min
146-
#~ h_nc.evolve_area_max = self.evolve_area_max
147-
#~
148-
#~ h_nc.llcrnrlon = self.grd.lonmin
149-
#~ h_nc.urcrnrlon = self.grd.lonmax
150-
#~ h_nc.llcrnrlat = self.grd.latmin
151-
#~ h_nc.urcrnrlat = self.grd.latmax
152-
153-
15440
class Amplitude (object):
15541
"""
15642
Class to calculate *amplitude* and counts of *local maxima/minima*

0 commit comments

Comments
 (0)