pswamp.utils.misc

Attributes

convert_datetime_to_seconds

Functions

recursively_default_dict()

Dict which allows assigning fields that don't exist. Source:

lookup_strings(a, b[, return_mask])

convert_time_stamp_to_seconds(time_stamp)

Convert time stamp (datetime) to seconds (float)

convert_seconds_to_datetime(time_seconds)

Convert seconds (float) to datetime object

flatten_array_insert_nan(x, y)

Flatten arrays and insert nan values, useful for fast plotting

flatten_list_insert_nan(listlist)

Module Contents

pswamp.utils.misc.recursively_default_dict()

Dict which allows assigning fields that don’t exist. Source: https://stackoverflow.com/questions/13151276/automatically-add-key-to-python-dict

Returns:

Empty dict

Return type:

dict

pswamp.utils.misc.lookup_strings(a, b, return_mask=False)
pswamp.utils.misc.convert_time_stamp_to_seconds(time_stamp)

Convert time stamp (datetime) to seconds (float)

Parameters:

time_stamp (datetime.datetime) – Input datetime object.

Returns:

Number of seconds.

Return type:

float

pswamp.utils.misc.convert_datetime_to_seconds
pswamp.utils.misc.convert_seconds_to_datetime(time_seconds)

Convert seconds (float) to datetime object

Parameters:

time_seconds (float) – Number of seconds

Returns:

Datetime object

Return type:

datetime.datetime

pswamp.utils.misc.flatten_array_insert_nan(x, y)

Flatten arrays and insert nan values, useful for fast plotting

Allows multiple series (in y) to be plotted with a single plot call. E.g. instead of plt.plot(x, y), plt.plot(*flatten_array_insert_nan(x, y)). Since the latter produces a single plot handle, it is much faster when there are many time series in y. Depending on plotting library, formatting of individual lines might not be possible.

Output arrays both have shape (n_series*(n_samples+1),).

Parameters:
  • x (np.ndarray) – x-values, with shape (n_series, n_samples) or (n_series,)

  • y (np.ndarray) – y-values, with shape (n_series, n_samples)

Raises:

Exception – If dimensions of x and y are not compatible.

Returns:

x-values, with shape (n_series*(n_samples+1),) y_data: y-values, with shape (n_series*(n_samples+1),)

Return type:

x_data

pswamp.utils.misc.flatten_list_insert_nan(listlist)