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.

Parameters:

i (int) – Apparatus code number

Returns:

Descriptive string for the apparatus type

Return type:

str

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.

Parameters:
  • string (str) – String to escape

  • chars (str) – Characters to escape, defaults to ‘ ,’

Returns:

Escaped string

Return type:

str

ecpet.ecutils.unescape(string, chars=' ,')

Remove escape characters from string.

Parameters:
  • string (str) – String to unescape

  • chars (str) – Characters to unescape, defaults to ‘ ,’

Returns:

Unescaped string

Return type:

str

ecpet.ecutils.str_to_bool(string)

Convert string representation to boolean.

Parameters:

string (str) – String to convert

Returns:

Boolean value

Return type:

bool

ecpet.ecutils.bool_to_str(x)

Convert boolean to string representation.

Parameters:

x (bool) – Boolean value

Returns:

String representation (‘T’ or ‘F’)

Return type:

str

Raises:

TypeError – If x is not boolean

ecpet.ecutils.quote(string, always=False, required=False)

Conditionally quote string for safe output.

Parameters:
  • string (str) – String to quote

  • always (bool) – Always quote regardless of content, defaults to False

  • required (bool) – Only quote if necessary for protection, defaults to False

Returns:

Quoted or unquoted string

Return type:

str

Note:

By default, numbers are not quoted, non-numeric strings are quoted

ecpet.ecutils.unquote(string)

Remove quotes around a string.

Parameters:

string (str) – String to unquote

Returns:

String without surrounding quotes

Return type:

str

ecpet.ecutils.uncomment(string)

Remove comments from string (everything after # or //).

Parameters:

string (str) – String to process

Returns:

String without comments

Return type:

str

ecpet.ecutils.isglob(string)

Check if string contains glob pattern characters.

Parameters:

string (str) – String to check

Returns:

True if string contains glob patterns

Return type:

bool

ecpet.ecutils.sub_dict(somedict, somekeys, default=None)

Extract subset of dictionary with specified keys.

Parameters:
  • somedict (dict) – Source dictionary

  • somekeys (list) – Keys to extract

  • default (any) – Default value for missing keys, defaults to None

Returns:

Dictionary with specified keys

Return type:

dict

ecpet.ecutils.deg2dms(deg)

Convert degrees to degrees, minutes, seconds.

Parameters:

deg (float) – Decimal degrees

Returns:

Tuple of (degrees, minutes, seconds)

Return type:

tuple

ecpet.ecutils.dms2deg(d, m, s)

Convert degrees, minutes, seconds to decimal degrees.

Parameters:
Returns:

Decimal degrees

Return type:

float

ecpet.ecutils.getfields(line)

Split CSV (TOA5) line into fields.

Parameters:

line (str) – CSV line to split

Returns:

List of field values

Return type:

list

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:

float

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.

Parameters:

x (array-like) – 1-dimensional vector (list, tuple, np.array or DataFrame)

Returns:

Vector magnitude

Return type:

float

Raises:

TypeError – If argument doesn’t coerce to vector

ecpet.ecutils.find_nearest(array, value)

Find nearest value in numpy array.

Parameters:
Returns:

Nearest value in array

Return type:

float

ecpet.ecutils.spechum(RhoV, T, P)

Calculate specific humidity of wet air.

Parameters:
  • RhoV (float) – Water vapor density [kg/m³]

  • T (float) – Temperature [K]

  • P (float) – Pressure [Pa]

Returns:

Specific humidity [kg/kg]

Return type:

float

ecpet.ecutils.specco2(RhoCO2, RhoV, T, P)

Calculate specific CO2 concentration of wet air.

Parameters:
  • RhoCO2 (float) – CO2 density [kg/m³]

  • RhoV (float) – Water vapor density [kg/m³]

  • T (float) – Temperature [K]

  • P (float) – Pressure [Pa]

Returns:

Specific CO2 concentration [kg/kg]

Return type:

float

ecpet.ecutils.rhodry(RhoV, T, P)

Calculate density of dry air component in wet air using Dalton’s law.

Parameters:
  • RhoV (float) – Water vapor density [kg/m³]

  • T (float) – Temperature [K]

  • P (float) – Pressure [Pa]

Returns:

Dry air density [kg/m³]

Return type:

float

Raises:

ValueError – If pressure or temperature units appear incorrect

ecpet.ecutils.rhowet(RhoV, T, P)

Calculate density of humid air.

Parameters:
  • RhoV (float) – Water vapor density [kg/m³]

  • T (float) – Temperature [K]

  • P (float) – Pressure [Pa]

Returns:

Wet air density [kg/m³]

Return type:

float

ecpet.ecutils.lvt(T)

Calculate latent heat of vaporization as function of temperature.

Parameters:

T (float) – Temperature [K]

Returns:

Latent heat of vaporization [J/kg]

Return type:

float

Note:

Uses Henderson‐Sellers (1984) equation

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:

float

Note:

Uses [Garratt, 1992] equation A20

ecpet.ecutils.fint(x)

Convert flag value to integer, handling NaN values.

Parameters:

x (float) – Flag value as float

Returns:

Flag value as integer (-1 for NaN)

Return type:

int

Note:

np.nan is converted to -1

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:

float

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:

int

ecpet.ecutils.intersect_lists(list1: list, list2: list)

Find intersection of two lists preserving order from first list.

Parameters:
  • list1 (list) – First list

  • list2 (list) – Second list

Returns:

Elements present in both lists, ordered as in list1

Return type:

list