wavy.utils

utility fcts for the verification

Module Contents

Classes

NoStdStreams

Suppress stdout.

Functions

grab_PID()

Retrieves PID and prints it

haversineP(lon1, lat1, lon2, lat2)

Calculate the great circle distance between two points

haversine_np(lon1, lat1, lon2, lat2)

Calculate the great circle distance between two points

haversineA(lon1, lat1, lon2, lat2)

Calculate the great circle distance between two points

runmean(→ tuple)

Computes the running mean with various configurations.

runmean_conv(→ numpy.ndarray)

running mean using convolution

bootstr(a, reps)

Conducts a simple naive bootstrap:

marginalize(a[, b])

Removes entries in both time series that are NaN.

hour_rounder(t)

Rounds to nearest hour by adding a timedelta hour if minute >= 30

sort_files(dirpath, filelst, product, sat)

mv files to sub-folders of year and month

sort_aviso_l2p(dirpath, filelst)

Sort AVISO files according to year and month.

sort_cmems_l3_nrt(dirpath, filelst, sat)

Sort L3 files according to year and month.

sort_cmems_l3_s6a(dirpath, filelst, sat)

Sort L3 s6a files according to year and month.

sort_cmems_l3_my(dirpath, filelst, sat)

Sort L3 files according to year and month.

sort_cci(dirpath, filelst)

Sort L2P and L3 files according to year and month.

sort_eumetsat_l2(dirpath, filelst)

Sort L2 files according to year and month.

get_size(obj[, seen])

Recursively finds size of objects

find_included_times_pd(→ list)

find_included_times(→ list)

Find index/indices of unfiltered time series that fall

collocate_times(→ list)

fct for collocating times within a given twin as tolerance

make_fc_dates(→ list)

fct to create forecast date vector

system_call(command)

make_subdict(strsublst[, class_object, class_object_dict])

get_pathtofile(pathlst, strsublst, subdict, date)

Finds and returns path of file given templates and keywords and date.

finditem(search_dict, field)

Takes a dict with nested lists and dicts,

make_pathtofile(tmppath, strsublst, subdict[, date])

Creates a path given templates and keywords and date.

find_direction_convention(filevarname, ncdict)

convert_meteorologic_oceanographic(alpha)

fct to convert angles from meteorological convention to

get_item_parent(ncdict, item, attr)

get_item_child(ncdict, item)

parse_date(indate)

dispersion_deep_water([T, k, l, cp, cg])

computes requested variable from dispersion relation in deep water

dispersion_shallow_water([l, h, T])

dispersion_intermediate_water([l, h, T])

calc_deep_water_T([l])

calc_shallow_water_T([l, h])

wave_length_mask_swim(ds[, llim, ulim])

remove all results for wavelengths below given llim

compute_quantiles(ts, lq)

fct to compute quantiles for given ts

get_obsdict(obstype)

find_tagged_obs(tags, obstype)

expand_nID_for_sensors(nID, obstype)

date_dispatcher(date[, date_incr])

date_next_hour(date)

date_next_day(date)

date_next_month(date)

date_next_year(date)

Attributes

flatten

wavy.utils.grab_PID()

Retrieves PID and prints it

wavy.utils.haversineP(lon1, lat1, lon2, lat2)

Calculate the great circle distance between two points on the earth (specified in decimal degrees)

wavy.utils.haversine_np(lon1, lat1, lon2, lat2)

Calculate the great circle distance between two points on the earth (specified in decimal degrees)

All args must be of equal length.

wavy.utils.haversineA(lon1, lat1, lon2, lat2)

Calculate the great circle distance between two points on the earth (specified in decimal degrees) Note: lon1,lat1,lon2, and lat2 can be lists

wavy.utils.runmean(vec, win, mode=None, weights=None) tuple

Computes the running mean with various configurations.

Args:

vec (numpy.ndarray | list): array of values to me smoothed win (int): window length mode (str): string: left, centered, right weights (numpy.ndarray | list): weights (same size as win)

Returns:
tuple (out (numpy.ndarray), std (numpy.ndarray)):

array of smoothed values and std deviation

wavy.utils.runmean_conv(x: numpy.ndarray, win: int, mode='flat') numpy.ndarray

running mean using convolution

Args:

x (numpy.ndarray): array of values to me smoothed win (int): window length mode (str): which type of smoothing window to pic

Notes:

https://scipy-cookbook.readthedocs.io/items/SignalSmooth.html

Returns:

out (numpy array): array of smoothed values

Raises:

ValueError: for wrong dimension of x and wrong windowsize

wavy.utils.bootstr(a, reps)

Conducts a simple naive bootstrap:

input: - a is time series of length n
  • reps (number of repetitions)

output: - an array of dim n x m where

m is the number of repetitions

  • indices of draws

wavy.utils.marginalize(a, b=None)

Removes entries in both time series that are NaN.

input: np.arrays with np.nan for invalids

wavy.utils.hour_rounder(t)

Rounds to nearest hour by adding a timedelta hour if minute >= 30

wavy.utils.sort_files(dirpath, filelst, product, sat)

mv files to sub-folders of year and month

wavy.utils.sort_aviso_l2p(dirpath: str, filelst: list)

Sort AVISO files according to year and month.

wavy.utils.sort_cmems_l3_nrt(dirpath: str, filelst: list, sat: str)

Sort L3 files according to year and month.

wavy.utils.sort_cmems_l3_s6a(dirpath: str, filelst: list, sat: str)

Sort L3 s6a files according to year and month.

wavy.utils.sort_cmems_l3_my(dirpath: str, filelst: list, sat: str)

Sort L3 files according to year and month.

wavy.utils.sort_cci(dirpath: str, filelst: list)

Sort L2P and L3 files according to year and month.

wavy.utils.sort_eumetsat_l2(dirpath: str, filelst: list)

Sort L2 files according to year and month.

wavy.utils.get_size(obj, seen=None)

Recursively finds size of objects

From: https://goshippo.com/blog/measure-real-size-any-python-object/

wavy.utils.find_included_times_pd(unfiltered_t: list, sdate: datetime.datetime, edate: datetime.datetime) list
wavy.utils.find_included_times(unfiltered_t: list, target_t=None, sdate=None, edate=None, twin=0) list

Find index/indices of unfiltered time series that fall within a tolerance time window around the target time or within a time window specified by sdate and edate

wavy.utils.collocate_times(unfiltered_t: list, target_t=None, sdate=None, edate=None, twin=None) list

fct for collocating times within a given twin as tolerance target_t and unfiltered_t need to be lists of datetime objects twin is in minutes.

returns idx

wavy.utils.flatten
wavy.utils.make_fc_dates(sdate: datetime.datetime, edate: datetime.datetime, date_incr: int) list

fct to create forecast date vector

wavy.utils.system_call(command: str)
wavy.utils.make_subdict(strsublst, class_object=None, class_object_dict=None)
wavy.utils.get_pathtofile(pathlst, strsublst, subdict, date)

Finds and returns path of file given templates and keywords and date.

wavy.utils.finditem(search_dict, field)

Takes a dict with nested lists and dicts, and searches all dicts for a key of the field provided.

wavy.utils.make_pathtofile(tmppath, strsublst, subdict, date=None)

Creates a path given templates and keywords and date.

wavy.utils.find_direction_convention(filevarname, ncdict)
wavy.utils.convert_meteorologic_oceanographic(alpha)

fct to convert angles from meteorological convention to oceanographic and vice versa.

class wavy.utils.NoStdStreams(stdout=None, stderr=None)

Bases: object

Suppress stdout.

https://codereview.stackexchange.com/questions/25417/ is-there-a-better-way-to-make-a-function-silent-on-need

__enter__()
__exit__(exc_type, exc_value, traceback)
wavy.utils.get_item_parent(ncdict, item, attr)
wavy.utils.get_item_child(ncdict, item)
wavy.utils.parse_date(indate)
wavy.utils.dispersion_deep_water(T=None, k=None, l=None, cp=None, cg=None)

computes requested variable from dispersion relation in deep water

wavy.utils.dispersion_shallow_water(l=None, h=None, T=None)
wavy.utils.dispersion_intermediate_water(l=None, h=None, T=None)
wavy.utils.calc_deep_water_T(l=None)
wavy.utils.calc_shallow_water_T(l=None, h=None)
wavy.utils.wave_length_mask_swim(ds, llim=50, ulim=2000)

remove all results for wavelengths below given llim

wavy.utils.compute_quantiles(ts, lq)

fct to compute quantiles for given ts

param:

ts - iterable of ts lq - iterable of quantiles

return:

qA - numpy array of quantiles

wavy.utils.get_obsdict(obstype)
wavy.utils.find_tagged_obs(tags, obstype)
wavy.utils.expand_nID_for_sensors(nID, obstype)
wavy.utils.date_dispatcher(date, date_incr='d')
wavy.utils.date_next_hour(date)
wavy.utils.date_next_day(date)
wavy.utils.date_next_month(date)
wavy.utils.date_next_year(date)