py_eddy_tracker.observations.network.NetworkObservations¶
- class py_eddy_tracker.observations.network.NetworkObservations(*args, **kwargs)[source]¶
Bases:
GroupEddiesObservationsMethods
add_fieldsAdd a new field.
add_rotation_typealign_onAlign 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.appendMerge.
basic_formula_ellipse_major_axisGive major axis in km with a given latitude
bins_stat- param str,array xname
variable to compute stats on
Extract birth events.
box_displayReturn values evenly spaced with few numbers
build_var_listcircle_contourSet contours as circles from radius and center data.
Get close network from another atlas.
coherenceCheck coherence between two datasets.
compare_unitsconcatenateCreate dictionnary for each segment, gives the segments in interaction with
containsReturn index of contour containing (x,y)
copycopy_data_to_zarrCopy 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_functionReturn the cost function between two obs.
cost_function_common_areaHow does it work on x bound ?
create_particlesCreate particles inside contour (Default : speed contour).
create_variablecreate_variable_zarrExtract death events.
displayPlot the speed and effective (dashed) contour of the eddies
display_colorPlot colored contour of eddies
Plot the timeline of a network.
Extract death events.
Dissociate networks with no known interaction (splitting/merging)
distanceUse haversine distance for distance matrix between every self and other eddies.
empty_datasetAdd 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_areaExtract geographically with a bounding box.
Extract a subset of observations.
Extract within a time period
field_tableProduce 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_interpolationFill 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_obsGet first obs of each trajectory.
Function used after 'insert_virtual', to correct next_obs and previous obs.
fixed_ellipsoid_maskformat_labelfrom_arrayfrom_netcdfBuild a NetworkObservations object with Group dataset and indices
from_zarrSuspicious
Extract birth events.
get_colorReturn colors as a cyclic list
get_filters_zarrGet filters to store in zarr for known variable
get_infosobtain mask within a time period
Find indices where observations are missing.
grid_box_statGet percentile of eddies in each bin
grid_countCount the eddies in each bin (use all pixels in each contour)
grid_statReturn the mean of the eddies' variable in each bin
histBuild histograms.
Return couple of segment or network which are equal
indexReturn obs from self at the index.
insert_observationsInsert other obs in self at the given index.
insert_virtualInsert virtual observations on segments where observations are missing
insideTrue for each point inside the effective contour of an eddy
interninterp_gridInterpolate a grid on a center or contour with mean, min or max method
is_convexGet flag of the eddy's convexity
iter_onYield observation group for each bin.
keep_tracks_by_dateFind tracks that exist at date date and lasted at least nb_days after.
last_obsGet Last obs of each trajectory.
load_fileLoad the netcdf or the zarr file.
load_from_netcdfLoad data from netcdf.
load_from_zarrLoad data from zarr.
Select network on time duration
Transform data y with method method for each track.
mask_from_polygonsReturn mask for all observations in one of polygons list
mask_functionBuild a mask of close observation from event
matchReturn index and score computed on the effective contour.
mergeMerge two datasets.
merge_filtersCompute an intersection between all filters after to evaluate each of them
merge_particle_resultCopy local result in merged result with global indexation
Return observation after a merging event.
needed_variablenetcdf_create_dimensionsGet number of segment by network
Return size for specified network
Return slice for one network
new_likeNormalize all longitudes
New numbering of network
New numbering of segment
obs_dimensionRaise a warning or error? if there are more than one network
parse_varnameparticle_candidate_atlasSelect particles within eddies, advect them, return target observation and associated percentages
This function draws the path of each trajectory
post_process_linkpropagateFill virtual obs (C).
re_reference_indexShift 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_fieldsCopy with fields listed remove
Remove the lonely eddies (only 1 obs in segment, associated network number is 0)
resetThis 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_netcdfset_global_attr_zarrshifted_ellipsoid_degrees_masksolve_conflictsolve_firstsolve_functionsolve_simultaneousDeduce 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_sampleTime sub sampling
to_netcdfto_zarrtrackingTrack obs between self and other
Return id network and id segment for a unique id
write_fileWrite a netcdf or zarr with eddy obs.
zarr_dimensionAttributes
COLORSELEMENTSNB_COLORSarray_variablesdtypeReturn dtype to build numpy array.
Return all the names of the variables.
fieldsglobal_attrnb_daysReturn period in days covered by the dataset
Count and return number of network
Count and return number of segment in all network
obsReturn observations.
observationsonly_variablesperiodGive the time coverage.
period_raw_dataReturn a unique segment id when multiple networks are considered
shapesign_legendsign_typetrack_array_variablestrack_extra_variablestracks- 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.