wavy.utils ========== .. py:module:: wavy.utils .. autoapi-nested-parse:: utility fcts for the verification Attributes ---------- .. autoapisummary:: wavy.utils.variable_def wavy.utils.flatten Classes ------- .. autoapisummary:: wavy.utils.NoStdStreams Functions --------- .. autoapisummary:: wavy.utils.grab_PID wavy.utils.haversineP wavy.utils.haversine_np wavy.utils.haversineA wavy.utils.runmean_old wavy.utils.runmean wavy.utils.runmean_conv wavy.utils.bootstr wavy.utils.marginalize wavy.utils.hour_rounder wavy.utils.hour_rounder_pd wavy.utils.sort_files wavy.utils.sort_aviso_l2p wavy.utils.sort_cmems_l3_nrt wavy.utils.sort_cmems_l3_s6a wavy.utils.sort_cmems_l3_my wavy.utils.sort_cci wavy.utils.sort_eumetsat_l2 wavy.utils.get_size wavy.utils.find_included_times_pd wavy.utils.find_included_times wavy.utils.collocate_times wavy.utils.make_fc_dates wavy.utils.system_call wavy.utils.make_subdict wavy.utils.get_pathtofile wavy.utils.finditem wavy.utils.make_pathtofile wavy.utils.find_direction_convention wavy.utils.convert_meteorologic_oceanographic wavy.utils.get_item_parent wavy.utils.get_item_child wavy.utils.parse_date wavy.utils.dispersion_deep_water wavy.utils.dispersion_shallow_water wavy.utils.dispersion_intermediate_water wavy.utils.calc_deep_water_T wavy.utils.calc_shallow_water_T wavy.utils.wave_length_mask_swim wavy.utils.compute_quantiles wavy.utils.get_obsdict wavy.utils.find_tagged_obs wavy.utils.expand_nID_for_sensors wavy.utils.date_dispatcher wavy.utils.date_next_hour wavy.utils.date_next_day wavy.utils.date_next_month wavy.utils.date_next_year wavy.utils.footprint_pulse_limited_radius wavy.utils.build_xr_ds wavy.utils.build_xr_ds_multivar Module Contents --------------- .. py:data:: variable_def .. py:function:: grab_PID() Retrieves PID and prints it .. py:function:: haversineP(lon1, lat1, lon2, lat2) Calculate the great circle distance between two points on the earth (specified in decimal degrees) .. py:function:: 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. .. py:function:: 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 .. py:function:: runmean_old(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 .. py:function:: 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 .. py:function:: 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 .. py:function:: 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 .. py:function:: marginalize(a, b=None) Removes entries in both time series that are NaN. input: np.arrays with np.nan for invalids .. py:function:: hour_rounder(t, method='nearest') Rounds to nearest hour adding a timedelta hour if minute >= 30 (default), or to the integer hour before (floor) or the integer hour after (ceil) the given time. .. py:function:: hour_rounder_pd(times) Rounds to nearest hour by adding a timedelta hour if minute >= 30 .. py:function:: sort_files(dirpath, filelst, product, sat) mv files to sub-folders of year and month .. py:function:: sort_aviso_l2p(dirpath: str, filelst: list) Sort AVISO files according to year and month. .. py:function:: sort_cmems_l3_nrt(dirpath: str, filelst: list, sat: str) Sort L3 files according to year and month. .. py:function:: sort_cmems_l3_s6a(dirpath: str, filelst: list, sat: str) Sort L3 s6a files according to year and month. .. py:function:: sort_cmems_l3_my(dirpath: str, filelst: list, sat: str) Sort L3 files according to year and month. .. py:function:: sort_cci(dirpath: str, filelst: list) Sort L2P and L3 files according to year and month. .. py:function:: sort_eumetsat_l2(dirpath: str, filelst: list) Sort L2 files according to year and month. .. py:function:: get_size(obj, seen=None) Recursively finds size of objects From: https://goshippo.com/blog/measure-real-size-any-python-object/ .. py:function:: find_included_times_pd(unfiltered_t: list, sdate: datetime.datetime, edate: datetime.datetime) -> list .. py:function:: 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 .. py:function:: 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 .. py:data:: flatten .. py:function:: make_fc_dates(sdate: datetime.datetime, edate: datetime.datetime, date_incr_unit: str, date_incr: int) -> list fct to create forecast date vector .. py:function:: system_call(command: str) .. py:function:: make_subdict(strsublst, class_object=None, class_object_dict=None) .. py:function:: get_pathtofile(pathlst, strsublst, subdict, date) Finds and returns path of file given templates and keywords and date. .. py:function:: finditem(search_dict, field) Takes a dict with nested lists and dicts, and searches all dicts for a key of the field provided. .. py:function:: make_pathtofile(tmppath, strsublst, subdict, date=None, **kwargs) .. py:function:: find_direction_convention(filevarname, ncdict) .. py:function:: convert_meteorologic_oceanographic(alpha) fct to convert angles from meteorological convention to oceanographic and vice versa. .. py:class:: NoStdStreams(stdout=None, stderr=None) Bases: :py:obj:`object` Suppress stdout. if argument is verbose stdout is shown, e.g.: with NoStdStreams(verbose) https://codereview.stackexchange.com/questions/25417/ is-there-a-better-way-to-make-a-function-silent-on-need .. py:attribute:: devnull .. py:attribute:: _stdout .. py:attribute:: _stderr .. py:method:: __enter__() .. py:method:: __exit__(exc_type, exc_value, traceback) .. py:function:: get_item_parent(ncdict, item, attr) .. py:function:: get_item_child(ncdict, item) .. py:function:: parse_date(indate) .. py:function:: dispersion_deep_water(T=None, k=None, l=None, cp=None, cg=None) computes requested variable from dispersion relation in deep water .. py:function:: dispersion_shallow_water(l=None, h=None, T=None) .. py:function:: dispersion_intermediate_water(l=None, h=None, T=None) .. py:function:: calc_deep_water_T(l=None) .. py:function:: calc_shallow_water_T(l=None, h=None) .. py:function:: wave_length_mask_swim(ds, llim=50, ulim=2000) remove all results for wavelengths below given llim .. py:function:: 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 .. py:function:: get_obsdict(obstype) .. py:function:: find_tagged_obs(tags, obstype) .. py:function:: expand_nID_for_sensors(nID, obstype) .. py:function:: date_dispatcher(date, date_incr='d', incr=1) .. py:function:: date_next_hour(date, incr) .. py:function:: date_next_day(date, incr) .. py:function:: date_next_month(date, incr) .. py:function:: date_next_year(date, incr) .. py:function:: footprint_pulse_limited_radius(Hs: float, h: float, tau: float) -> float Pulse limited footprint radius according to Chelton et al. 2001 as referenced in coastal altimtery book p. 458, EQ 17.1 Footprint size across track depends on: - significant wave height - satellite specs: - height over ground (h) - pulse duration (tau) .. py:function:: build_xr_ds(var: tuple, varnames: tuple) .. py:function:: build_xr_ds_multivar(var: tuple, varnames: tuple, varalias: list)