dubfi.fluxes.segments_insitu

Split data for MPI worker processes, for in-situ observations.

Changed in version 0.1.2: (renamed module)

Added in version 0.1.0: (initial release)

Functions

matrix_blocks(matrix)

Given a symmetric matrix of boolean entries, return indices of independent blocks.

indep_blocks(lon, lat, time, hscale, tscale)

Given coordinates and separating scales, identify independent blocks.

min_combination_cost(sizes, ngroups)

Distribute n elements to m groups and return the group indices.

split_times(times, buffer, nseg)

Split array of times into buffered segments.

prep_segments(lon, lat, time, hscale, tscale, number)

Prepare segments for in-situ observations.

plot_segments(segments, lon, lat, height, time, ...)

Plot segments created by prep_segments(), intended for debugging purposes.

Module Contents

dubfi.fluxes.segments_insitu.matrix_blocks(matrix)

Given a symmetric matrix of boolean entries, return indices of independent blocks.

Parameters:

matrix (numpy.ndarray)

Return type:

list[numpy.ndarray]

dubfi.fluxes.segments_insitu.indep_blocks(lon, lat, time, hscale, tscale)

Given coordinates and separating scales, identify independent blocks.

Input arrays are aligned along a common dimension “ssh” (station and sampling height). See dubfi.fluxes.readobs.coordinates_from_config() for generating the input coordinates.

Parameters:
  • lon (np.ndarray) – longitude coordiantes per ssh (degrees)

  • lat (np.ndarray) – latitude coordiantes per ssh (degrees)

  • time (list[np.ndarray]) – time coordinates for each ssh (must be of data type np.datetime64)

  • hscale (float) – horizontal cutoff scale of correlations (meters)

  • tscale (np.timedelta64) – temporal cutoff scale of correlations

Returns:

list of blocks. Each block is a dictionary mapping the ssh index to a slice or an array of indices that shall be applied to the time coordinate of the station.

Return type:

list[dict]

dubfi.fluxes.segments_insitu.min_combination_cost(sizes, ngroups)

Distribute n elements to m groups and return the group indices.

Given are n elements of different sizes. These shall be distributed to m groups such that each group has approximately the same size. The size of a group is the sum of the sizes of its elements.

Parameters:
  • sizes (list[int] | np.ndarray) – array of sizes of elements that shall be distributed

  • ngroups (int) – number of groups

Returns:

  • groups (np.ndarray) – group index for each input element

  • .. versionadded:: 0.1.1

Return type:

numpy.ndarray

dubfi.fluxes.segments_insitu.split_times(times, buffer, nseg)

Split array of times into buffered segments.

Given an (unsorted) array of times, find split times that define segments such that the maximum size of the balanced segments is minimized. A buffered segment contains all times of the segment plus all times in a buffer zone before and after the segment.

Parameters:
  • times (np.ndarray) – unsorted array of times (usually observation times)

  • buffer (np.timedelta64) – time interval defining the buffer size

  • nseg (int) – number of segments that shall be created

Returns:

  • split_start (np.ndarray) – times at which segments start (inclusive)

  • split_end (np.ndarray) – times at which segments end (inclusive)

  • .. versionadded:: 0.1.1

Return type:

tuple[numpy.ndarray, numpy.ndarray]

dubfi.fluxes.segments_insitu.prep_segments(lon, lat, time, hscale, tscale, number, buffer_pref=1.25)

Prepare segments for in-situ observations.

This heuristic algorithm is not guaranteed to work in all cases! It can fail with an assertion error if the target number of segments is matched exactly.

Parameters:
  • lon (np.ndarray) – longitude coordiantes per ssh (degrees)

  • lat (np.ndarray) – latitude coordiantes per ssh (degrees)

  • time (list[np.ndarray]) – time coordinates for each ssh (must be of data type np.datetime64)

  • hscale (float) – horizontal cutoff scale of correlations (meters)

  • tscale (np.timedelta64) – temporal cutoff scale of correlations

  • number (int) – number of segments

  • buffer_pref (float, default=1.25) – prefactor applied to tscale in buffering

Returns:

collection of segments

Return type:

Segments

dubfi.fluxes.segments_insitu.plot_segments(segments, lon, lat, height, time, hscale, vscale, tscale)

Plot segments created by prep_segments(), intended for debugging purposes.

Return type:

None