ecpet.ecutils module¶
EC-PeT Utility Functions¶
Core utility functions and constants for eddy-covariance data processing. Provides physical constants, variable definitions, string manipulation, atmospheric calculations, and progress reporting functionality.
- ecpet.ecutils.code_ap(i)¶
Convert apparatus code to descriptive string.
- ecpet.ecutils.progress_stage(stage)¶
Announce processing stage to GUI progress dialog.
- Parameters:
stage (str) – Processing stage identifier
- ecpet.ecutils.progress_reset()¶
Reset progress to zero percent.
- ecpet.ecutils.progress_percent(perc)¶
Set absolute progress percentage.
- Parameters:
perc (float) – Progress percentage (0-100)
- ecpet.ecutils.progress_pulse()¶
Send a pulse to indicate activity without specific progress.
- ecpet.ecutils.progress_increment(perc)¶
Increment progress by specified percentage.
- Parameters:
perc (float) – Percentage increment
- ecpet.ecutils.progress_info(txt)¶
Send informational message to progress dialog.
- Parameters:
txt (str) – Information text
- ecpet.ecutils.progress_done()¶
Mark current stage as completed.
- ecpet.ecutils.escape(string, chars=' ,')¶
Escape special characters in string.
- ecpet.ecutils.unescape(string, chars=' ,')¶
Remove escape characters from string.
- ecpet.ecutils.str_to_bool(string)¶
Convert string representation to boolean.
- ecpet.ecutils.bool_to_str(x)¶
Convert boolean to string representation.
- ecpet.ecutils.quote(string, always=False, required=False)¶
Conditionally quote string for safe output.
- Parameters:
- Returns:
Quoted or unquoted string
- Return type:
- Note:
By default, numbers are not quoted, non-numeric strings are quoted
- ecpet.ecutils.unquote(string)¶
Remove quotes around a string.
- ecpet.ecutils.uncomment(string)¶
Remove comments from string (everything after # or //).
- ecpet.ecutils.isglob(string)¶
Check if string contains glob pattern characters.
- ecpet.ecutils.sub_dict(somedict, somekeys, default=None)¶
Extract subset of dictionary with specified keys.
- ecpet.ecutils.deg2dms(deg)¶
Convert degrees to degrees, minutes, seconds.
- ecpet.ecutils.dms2deg(d, m, s)¶
Convert degrees, minutes, seconds to decimal degrees.
- ecpet.ecutils.getfields(line)¶
Split CSV (TOA5) line into fields.
- ecpet.ecutils.string_to_interval(string)¶
Convert string to time interval in seconds.
- Parameters:
string (str) – Time interval string (e.g., ‘30m’, ‘1h’, ‘86400’)
- Returns:
Time interval in seconds
- Return type:
- Raises:
ValueError – If string format is invalid
- Note:
Supported suffixes: s (seconds), m (minutes), h (hours), d (days), w (weeks)
- ecpet.ecutils.amount(x)¶
Calculate magnitude (length) of a vector.
- ecpet.ecutils.find_nearest(array, value)¶
Find nearest value in numpy array.
- Parameters:
array (numpy.ndarray) – Array to search
value (float) – Target value
- Returns:
Nearest value in array
- Return type:
- ecpet.ecutils.spechum(RhoV, T, P)¶
Calculate specific humidity of wet air.
- ecpet.ecutils.specco2(RhoCO2, RhoV, T, P)¶
Calculate specific CO2 concentration of wet air.
- ecpet.ecutils.rhodry(RhoV, T, P)¶
Calculate density of dry air component in wet air using Dalton’s law.
- Parameters:
- Returns:
Dry air density [kg/m³]
- Return type:
- Raises:
ValueError – If pressure or temperature units appear incorrect
- ecpet.ecutils.rhowet(RhoV, T, P)¶
Calculate density of humid air.
- ecpet.ecutils.lvt(T)¶
Calculate latent heat of vaporization as function of temperature.
- ecpet.ecutils.cpt(T)¶
Calculate specific heat of dry air as function of temperature.
- Parameters:
T (float) – Temperature [K]
- Returns:
Specific heat of dry air [J/(kg·K)]
- Return type:
- Note:
Uses [Garratt, 1992] equation A20
- ecpet.ecutils.fint(x)¶
Convert flag value to integer, handling NaN values.
- ecpet.ecutils.allnanok(fun, arg)¶
Suppress numpy warnings for all-NaN operations.
Suppresses RuntimeWarning “All-NaN axis encountered” when all values are NaN in numpy nan* function arguments.
- Parameters:
fun (function) – numpy nan function (nanmin, nanmax, nanmean, etc.)
arg (array-like) – Array-like argument for the function
- Returns:
Function result
- Return type:
- Note:
Returns np.nan silently for all-NaN arrays
- ecpet.ecutils.safe_len(arg)¶
Safely get length of DataFrame or array.
- Parameters:
arg (any) – Object to inspect
- Returns:
Length if object has len attribute, otherwise 0
- Return type: