11"""Auxiliary functions"""
22
33import logging as _logging
4- from typing import overload , Union
4+ from typing import overload
55import numpy as _np
66import pandas as _pd
77
@@ -26,7 +26,7 @@ def rad2arcsec(x: _np.ndarray) -> _np.ndarray:
2626 return _np .rad2deg (x ) * 3600
2727
2828
29- def wrap_radians (x : Union [ float , _np .ndarray ] ) -> Union [ float , _np .ndarray ] :
29+ def wrap_radians (x : float | _np .ndarray ) -> float | _np .ndarray :
3030 """Overwrite negative angles in radians with positive coterminal angles
3131
3232 :param float or _np.ndarray x: angles in radians
@@ -35,7 +35,7 @@ def wrap_radians(x: Union[float, _np.ndarray]) -> Union[float, _np.ndarray]:
3535 return x % (2 * _np .pi )
3636
3737
38- def wrap_degrees (x : Union [ float , _np .ndarray ] ) -> Union [ float , _np .ndarray ] :
38+ def wrap_degrees (x : float | _np .ndarray ) -> float | _np .ndarray :
3939 """Overwrite negative angles in decimal degrees with positive coterminal angles
4040
4141 :param float or _np.ndarray x: angles in decimal degrees
@@ -99,7 +99,7 @@ def unique_cols(df: _pd.DataFrame) -> _np.ndarray:
9999 return (a [:, 0 ][:, None ] == a ).all (1 )
100100
101101
102- def rm_duplicates_df (df : Union [ _pd .DataFrame , _pd .Series ] , rm_nan_level : Union [ int , str , None ] = None ):
102+ def rm_duplicates_df (df : _pd .DataFrame | _pd .Series , rm_nan_level : int | str | None = None ):
103103 """
104104 Takes in a clk/sp3/other dataframe and removes any duplicate indices.
105105 Optionally, removes level_values from the index which contain NaNs
@@ -134,7 +134,7 @@ def rm_duplicates_df(df: Union[_pd.DataFrame, _pd.Series], rm_nan_level: Union[i
134134 return df
135135
136136
137- def get_sampling (arr : _np .ndarray ) -> Union [ int , None ] :
137+ def get_sampling (arr : _np .ndarray ) -> int | None :
138138 """
139139 Simple function to compute sampling of the J2000 array
140140
@@ -170,10 +170,10 @@ def array_equal_unordered(a1: _np.ndarray, a2: _np.ndarray) -> bool:
170170
171171
172172def rms (
173- arr : Union [ _pd .DataFrame , _pd .Series ] ,
174- axis : Union [ None , int ] = 0 ,
175- level : Union [ None , int , str ] = None ,
176- ) -> Union [ _pd .Series , _pd .DataFrame ] :
173+ arr : _pd .DataFrame | _pd .Series ,
174+ axis : None | int = 0 ,
175+ level : None | int | str = None ,
176+ ) -> _pd .Series | _pd .DataFrame :
177177 """Trivial function to compute root mean square"""
178178 if level is not None :
179179 return (arr ** 2 ).groupby (axis = axis , level = level ).mean () ** 0.5
@@ -183,7 +183,7 @@ def rms(
183183
184184def get_std_bounds (
185185 a : _np .ndarray ,
186- axis : Union [ None , int , tuple [int , ...] ] = None ,
186+ axis : None | int | tuple [int , ...] = None ,
187187 sigma_coeff : int = 3 ,
188188):
189189 """
@@ -210,7 +210,7 @@ def get_std_bounds(
210210 return bounds if axis is None else _np .expand_dims (a = bounds , axis = axis )
211211
212212
213- def df_quick_select (df : _pd .DataFrame , ind_lvl : Union [ str , int ] , ind_keys , as_mask : bool = False ) -> _np .ndarray :
213+ def df_quick_select (df : _pd .DataFrame , ind_lvl : str | int , ind_keys , as_mask : bool = False ) -> _np .ndarray :
214214 """A faster alternative to do index selection over pandas dataframe, if multiple index levels are being used then better generate masks with this function and add them later into a single mask.
215215 df.loc(axis=0)[:,:,'IND_KEY',:] is the same as df_quick_select(df, 2, 'IND_KEY'),
216216 or, if used as mask: df[df_quick_select(df, 2, 'IND_NAME', as_mask=True)]"""
@@ -269,11 +269,11 @@ def degminsec2deg(a: list) -> _pd.Series: ...
269269def degminsec2deg (a : str ) -> float : ...
270270
271271
272- def degminsec2deg (a : Union [ _pd .Series , _pd .DataFrame , list , str ] ) -> Union [ _pd .Series , _pd .DataFrame , float ] :
272+ def degminsec2deg (a : _pd .Series | _pd .DataFrame | list | str ) -> _pd .Series | _pd .DataFrame | float :
273273 """Converts degrees/minutes/seconds to decimal degrees.
274274
275- :param _Union[_pd .Series, _pd.DataFrame, list, str] a: space-delimited string values of degrees/minutes/seconds
276- :return _Union[ _pd.Series, _pd.DataFrame, float] : Series, DataFrame or scalar float decimal degrees, depending on the input
275+ :param __pd .Series | _pd.DataFrame | list | str a: space-delimited string values of degrees/minutes/seconds
276+ :return _pd.Series | _pd.DataFrame | float: Series, DataFrame or scalar float decimal degrees, depending on the input
277277 """
278278 if isinstance (a , str ):
279279 a_single = _np .asarray (a .split (maxsplit = 2 )).astype (float )
@@ -315,7 +315,7 @@ def deg2degminsec(a: list) -> _np.ndarray: ...
315315def deg2degminsec (a : _np .ndarray ) -> _np .ndarray : ...
316316
317317
318- def deg2degminsec (a : Union [ _np .ndarray , list , float ] ) -> Union [ _np .ndarray , float ] :
318+ def deg2degminsec (a : _np .ndarray | list | float ) -> _np .ndarray | float :
319319 """Converts decimal degrees to string representation in the form of degrees minutes seconds
320320 as in the sinex SITE/ID block. Could be used with multiple columns at once (2D ndarray)
321321
@@ -363,7 +363,7 @@ def throw_if_nans(trace_bytes: bytes, nan_to_find=b"-nan", max_reported_nans: in
363363 raise ValueError (f"Found nan values (max_nans = { max_reported_nans } )\n { nans_bytes .decode ()} " )
364364
365365
366- def df_groupby_statistics (df : Union [ _pd .Series , _pd .DataFrame ] , lvl_name : Union [ list , str ] ):
366+ def df_groupby_statistics (df : _pd .Series | _pd .DataFrame , lvl_name : list | str ):
367367 """Generate AVG/STD/RMS statistics from a dataframe summarizing over levels
368368
369369 :param _pd.Series df: an input dataframe or series
@@ -404,14 +404,14 @@ def _get_trend(dataset, deg=1):
404404
405405def remove_outliers (
406406 dataframe : _pd .DataFrame ,
407- cutoff : Union [ int , float , None ] = None ,
408- coeff_std : Union [ int , float ] = 3 ,
407+ cutoff : int | float | None = None ,
408+ coeff_std : int | float = 3 ,
409409) -> _pd .DataFrame :
410410 """Filters a dataframe with linear data. Runs detrending of the data to normalize to zero and applies absolute cutoff and std-based filtering
411411
412412 :param _pd.DataFrame dataframe: a dataframe to filter the columns
413- :param _Union[int, float, None] cutoff: an absolute cutoff value to apply over detrended data, defaults to None
414- :param _Union[int, float] coeff_std: STD coefficient, defaults to 3
413+ :param _int | float | None cutoff: an absolute cutoff value to apply over detrended data, defaults to None
414+ :param _int | float coeff_std: STD coefficient, defaults to 3
415415 :return _pd.DataFrame: a filtered dataframe
416416 """
417417 detrend = dataframe - _get_trend (dataframe )
0 commit comments