py_eddy_tracker.observations.network.NetworkObservations¶
- class py_eddy_tracker.observations.network.NetworkObservations(*args, **kwargs)[source]¶
Bases:
GroupEddiesObservations
Methods
add_fields
Add a new field.
add_rotation_type
align_on
Align the variable indices of two datasets.
Global function to analyse segments coherence, with network preprocessing. :param callable date_function: python function, takes as param int (julian day) and return data filename associated to the date :param dict uv_params: dict of parameters used by
from_netcdf_list()
:param int n_days: nuber of days for advection :param float step_mesh: step for particule mesh in degrees :param str output_name: path/name for the output (without extension) to store the clean network in .nc and the coherence results in .zarr. Works only for advection_mode = "both" :param bool dissociate_network: If True applydissociate_network()
:param int correct_close_events: Number of days incorrect_close_events()
:param int remove_dead_end: Number of days inremove_dead_end()
:return target_forward, target_bakward: 2D numpy.array with the eddy observation the particles ended in after advection :return target_forward, target_bakward: percentage of ending particles within the eddy observation with regards to the starting number.append
Merge.
basic_formula_ellipse_major_axis
Give major axis in km with a given latitude
bins_stat
- param str,array xname
variable to compute stats on
Extract birth events.
box_display
Return values evenly spaced with few numbers
build_var_list
circle_contour
Set contours as circles from radius and center data.
Get close network from another atlas.
coherence
Check coherence between two datasets.
compare_units
concatenate
Create dictionnary for each segment, gives the segments in interaction with
contains
Return index of contour containing (x,y)
copy
copy_data_to_zarr
Copy with buffer for zarr.
Transform event where segment A splits from segment B, then x days after segment B merges with A to segment A splits from segment B then x days after segment A merges with B (B will be longer) These events have to last less than nb_days_max to be changed.
cost_function
Return the cost function between two obs.
cost_function_common_area
How does it work on x bound ?
create_particles
Create particles inside contour (Default : speed contour).
create_variable
create_variable_zarr
Extract death events.
display
Plot the speed and effective (dashed) contour of the eddies
display_color
Plot colored contour of eddies
Plot the timeline of a network.
Extract death events.
Dissociate networks with no known interaction (splitting/merging)
distance
Use haversine distance for distance matrix between every self and other eddies.
empty_dataset
Add the merging and splitting events to a map
Mark events in plot
extract data with mask, but only with variables used for coherence, aka self.array_variables
extract_with_area
Extract geographically with a bounding box.
Extract a subset of observations.
Extract within a time period
field_table
Produce description table of the fields available in this object
fill_coherence
_summary_
filled
- param matplotlib.axes.Axes ax
matplotlib axe used to draw
filled_by_interpolation
Fill selected values by interpolation
Find all observations where obs i_observation could be in future or past.
Find all relative segments from obs linked with merging/splitting events at a specific order.
Check if first network is Trash
first_obs
Get first obs of each trajectory.
Function used after 'insert_virtual', to correct next_obs and previous obs.
fixed_ellipsoid_mask
format_label
from_array
from_netcdf
Build a NetworkObservations object with Group dataset and indices
from_zarr
Suspicious
Extract birth events.
get_color
Return colors as a cyclic list
get_filters_zarr
Get filters to store in zarr for known variable
get_infos
obtain mask within a time period
Find indices where observations are missing.
grid_box_stat
Get percentile of eddies in each bin
grid_count
Count the eddies in each bin (use all pixels in each contour)
grid_stat
Return the mean of the eddies' variable in each bin
hist
Build histograms.
Return couple of segment or network which are equal
index
Return obs from self at the index.
insert_observations
Insert other obs in self at the given index.
insert_virtual
Insert virtual observations on segments where observations are missing
inside
True for each point inside the effective contour of an eddy
intern
interp_grid
Interpolate a grid on a center or contour with mean, min or max method
is_convex
Get flag of the eddy's convexity
iter_on
Yield observation group for each bin.
keep_tracks_by_date
Find tracks that exist at date date and lasted at least nb_days after.
last_obs
Get Last obs of each trajectory.
load_file
Load the netcdf or the zarr file.
load_from_netcdf
Load data from netcdf.
load_from_zarr
Load data from zarr.
Select network on time duration
Transform data y with method method for each track.
mask_from_polygons
Return mask for all observations in one of polygons list
mask_function
Build a mask of close observation from event
match
Return index and score computed on the effective contour.
merge
Merge two datasets.
merge_filters
Compute an intersection between all filters after to evaluate each of them
merge_particle_result
Copy local result in merged result with global indexation
Return observation after a merging event.
needed_variable
netcdf_create_dimensions
Get number of segment by network
Return size for specified network
Return slice for one network
new_like
Normalize all longitudes
New numbering of network
New numbering of segment
obs_dimension
Raise a warning or error? if there are more than one network
parse_varname
particle_candidate_atlas
Select particles within eddies, advect them, return target observation and associated percentages
This function draws the path of each trajectory
post_process_link
propagate
Fill virtual obs (C).
re_reference_index
Shift index with ref
Extract the segments at a certain order from multiple observations.
Extract the segments at a certain order from multiple observations.
Remove short segments that don't connect several segments
remove_fields
Copy with fields listed remove
Remove the lonely eddies (only 1 obs in segment, associated network number is 0)
reset
This function scatters the path of each network, with the merging and splitting events
Must be called on only one network
Percentage of particules and their targets after backward advection from a specific eddy.
Percentage of particules and their targets after forward advection from a specific eddy.
Compute the relative order of each segment to the chosen segment
Return slice for one segment
set_global_attr_netcdf
set_global_attr_zarr
shifted_ellipsoid_degrees_mask
solve_conflict
solve_first
solve_function
solve_simultaneous
Deduce link from cost matrix.
Sort observations
Return observation before a splitting event.
For each segment, method give a new network id, and all segment are connected
time_sub_sample
Time sub sampling
to_netcdf
to_zarr
tracking
Track obs between self and other
Return id network and id segment for a unique id
write_file
Write a netcdf or zarr with eddy obs.
zarr_dimension
Attributes
COLORS
ELEMENTS
NB_COLORS
array_variables
dtype
Return dtype to build numpy array.
Return all the names of the variables.
fields
global_attr
nb_days
Return period in days covered by the dataset
Count and return number of network
Count and return number of segment in all network
obs
Return observations.
observations
only_variables
period
Give the time coverage.
period_
raw_data
Return a unique segment id when multiple networks are considered
shape
sign_legend
sign_type
track_array_variables
track_extra_variables
tracks
- NOGROUP = 0¶
- analysis_coherence(date_function, uv_params, advection_mode='both', n_days=14, step_mesh=0.02, output_name=None, dissociate_network=False, correct_close_events=0, remove_dead_end=0)[source]¶
Global function to analyse segments coherence, with network preprocessing. :param callable date_function: python function, takes as param int (julian day) and return
data filename associated to the date
- Parameters
uv_params (dict) – dict of parameters used by
from_netcdf_list()
n_days (int) – nuber of days for advection
step_mesh (float) – step for particule mesh in degrees
output_name (str) – path/name for the output (without extension) to store the clean network in .nc and the coherence results in .zarr. Works only for advection_mode = “both”
dissociate_network (bool) – If True apply
dissociate_network()
correct_close_events (int) – Number of days in
correct_close_events()
remove_dead_end (int) – Number of days in
remove_dead_end()
- Return target_forward, target_bakward
2D numpy.array with the eddy observation the particles ended in after advection
- Return target_forward, target_bakward
percentage of ending particles within the eddy observation with regards to the starting number
- close_network(other, nb_obs_min=10, **kwargs)[source]¶
Get close network from another atlas.
- Parameters
- Returns
return other atlas reduced to common tracks with self
Warning
It could be a costly operation for huge dataset
- connexions(multi_network=False)[source]¶
Create dictionnary for each segment, gives the segments in interaction with
- Parameters
multi_network (bool) – use segment_track_array instead of segment, defaults to False
- Return dict
Return dict of set, for each seg id we get set of segment which have event with him
- correct_close_events(nb_days_max=20)[source]¶
Transform event where segment A splits from segment B, then x days after segment B merges with A to segment A splits from segment B then x days after segment A merges with B (B will be longer) These events have to last less than nb_days_max to be changed.
——————- A
/ /
B ——————– to
–A–
/ B ———————————–
- Parameters
nb_days_max (float) – maximum time to search for splitting-merging event
- display_timeline(ax, event=True, field=None, method=None, factor=1, colors_mode='roll', **kwargs)[source]¶
Plot the timeline of a network. Must be called on only one network.
- Parameters
ax (matplotlib.axes.Axes) – matplotlib axe used to draw
event (bool) – if True, draw the splitting and merging events
field (str,array) – yaxis values, if None, segments are used
method (str) – if None, mean values are used
factor (float) – to multiply field
colors_mode (str) – color of lines. “roll” means looping through colors, “y” means color adapt the y values (for matching color plots)
- Returns
plot mappable
- dissipation_event()¶
Extract death events.
- property elements¶
Return all the names of the variables.
- event_timeline(ax, field=None, method=None, factor=1, colors_mode='roll')[source]¶
Mark events in plot
- extract_light_with_mask(mask, track_extra_variables=[])[source]¶
extract data with mask, but only with variables used for coherence, aka self.array_variables
- Parameters
mask (np.array(bool)) – mask used to extract
- Returns
new EddiesObservation with data wanted
- Return type
self
- extract_with_mask(mask)[source]¶
Extract a subset of observations.
- Parameters
mask (array(bool)) – mask to select observations
- Returns
same object with selected observations
- Return type
self
- extract_with_period(period)[source]¶
Extract within a time period
- find_link(i_observations, forward=True, backward=False)[source]¶
Find all observations where obs i_observation could be in future or past.
If forward=True, search all observations where water from obs “i_observation” could go
If backward=True, search all observation where water from obs i_observation could come from
- find_segments_relative(obs, stopped=None, order=1)[source]¶
Find all relative segments from obs linked with merging/splitting events at a specific order.
- Parameters
- Returns
all relative segments
- Return type
- first_is_trash()[source]¶
Check if first network is Trash
- Return bool
True if first network is trash
- fix_next_previous_obs()[source]¶
Function used after ‘insert_virtual’, to correct next_obs and previous obs.
- classmethod from_split_network(group_dataset, indexs, **kwargs)[source]¶
Build a NetworkObservations object with Group dataset and indices
- Parameters
group_dataset (TrackEddiesObservations) – Group dataset
indexs – result from split_network
- Returns
NetworkObservations
- generation_event()¶
Extract birth events.
- get_missing_indices(dt)[source]¶
Find indices where observations are missing.
- As network have all untracked observation in tracknumber self.NOGROUP,
we don’t compute them
- identify_in(other, size_min=1, segment=False)[source]¶
Return couple of segment or network which are equal
- property index_network¶
- property index_segment_track¶
- map_network(method, y, same=True, return_dict=False, **kw)[source]¶
Transform data y with method method for each track.
- Parameters
- Returns
array or dict of result from method for each network
- mask_obs_close_event(merging=True, spliting=True, dt=3)[source]¶
Build a mask of close observation from event
- merging_event(triplet=False, only_index=False)[source]¶
Return observation after a merging event.
If triplet=True return the eddy after a merging event, the eddy before the merging event, and the eddy stopped due to merging.
- property nb_network¶
Count and return number of network
- property nb_segment¶
Count and return number of segment in all network
- network_size(id_networks=None)[source]¶
Return size for specified network
- Parameters
id_networks (list,array, None) – ids to identify network
- network_slice(id_network)[source]¶
Return slice for one network
- Parameters
id_network (int) – id to identify network
- normalize_longitude()[source]¶
Normalize all longitudes
Normalize longitude field and in the same range : - longitude_max - contour_lon_e (how to do if in raw) - contour_lon_s (how to do if in raw)
- plot(ax, ref=None, color_cycle=None, **kwargs)[source]¶
This function draws the path of each trajectory
- Parameters
ax (matplotlib.axes.Axes) – ax to draw
ref (float,int) – if defined, all coordinates are wrapped with ref as western boundary
kwargs (dict) – keyword arguments for Axes.plot
- Returns
a list of matplotlib mappables
- property ref_index¶
- property ref_segment_track_index¶
- relative(obs, order=2)¶
Extract the segments at a certain order from multiple observations.
- Parameters
- Returns
all segments’ relatives
- Return type
- relatives(obs, order=2)[source]¶
Extract the segments at a certain order from multiple observations.
- Parameters
- Returns
all segments’ relatives
- Return type
- remove_dead_end(nobs=3, ndays=0, recursive=0, mask=None)[source]¶
Remove short segments that don’t connect several segments
- Parameters
Warning
It will remove short segment that splits from then merges with the same segment
- remove_trash()[source]¶
Remove the lonely eddies (only 1 obs in segment, associated network number is 0)
- scatter(ax, name='time', factor=1, ref=None, edgecolor_cycle=None, **kwargs)[source]¶
This function scatters the path of each network, with the merging and splitting events
- Parameters
ax (matplotlib.axes.Axes) – matplotlib axe used to draw
name (str,array,None) – variable used to fill the contours, if None all elements have the same color
ref (float,None) – if defined, ref is used as western boundary
factor (float) – multiply value by
edgecolor_cycle (list) – list of colors
kwargs (dict) – look at
matplotlib.axes.Axes.scatter()
- Returns
a dict of scattered mappables
- scatter_timeline(ax, name, factor=1, event=True, yfield=None, yfactor=1, method=None, **kwargs)[source]¶
Must be called on only one network
- segment_coherence_backward(date_function, uv_params, n_days=14, step_mesh=0.02, contour_start='speed', contour_end='speed')[source]¶
Percentage of particules and their targets after backward advection from a specific eddy.
- Parameters
date_function (callable) – python function, takes as param int (julian day) and return data filename associated to the date (see note)
uv_params (dict) – dict of parameters used by
from_netcdf_list()
n_days (int) – days for advection
step_mesh (float) – step for particule mesh in degrees
- Returns
observations matchs, and percents
Note
the param date_function should be something like :
def date2file(julian_day): date = datetime.timedelta(days=julian_day) + datetime.datetime( 1950, 1, 1 ) return f"/tmp/dt_global_{date.strftime('%Y%m%d')}.nc"
- segment_coherence_forward(date_function, uv_params, n_days=14, step_mesh=0.02, contour_start='speed', contour_end='speed', **kwargs)[source]¶
Percentage of particules and their targets after forward advection from a specific eddy.
- Parameters
date_function (callable) – python function, takes as param int (julian day) and return data filename associated to the date (see note)
uv_params (dict) – dict of parameters used by
from_netcdf_list()
n_days (int) – days for advection
step_mesh (float) – step for particule mesh in degrees
- Returns
observations matchs, and percents
Note
the param date_function should be something like :
def date2file(julian_day): date = datetime.timedelta(days=julian_day) + datetime.datetime( 1950, 1, 1 ) return f"/tmp/dt_global_{date.strftime('%Y%m%d')}.nc"
- segment_relative_order(seg_origine)[source]¶
Compute the relative order of each segment to the chosen segment
- property segment_track_array¶
Return a unique segment id when multiple networks are considered
- sort(order=('track', 'segment', 'time'))[source]¶
Sort observations
- Parameters
order (tuple) – order or sorting. Given to
numpy.argsort()
- splitting_event(triplet=False, only_index=False)[source]¶
Return observation before a splitting event.
If triplet=True return the eddy before a splitting event, the eddy after the splitting event, and the eddy starting due to splitting.