Conversions reference
Source code in c3s_event_attribution_tools/data/conversions.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
convert_bbox_to_0_360(bbox, eps=1e-09)
staticmethod
Convert a bounding box from [-180, 180] longitude to [0, 360] longitude.
If the converted box crosses 0°, return two wrapped bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
tuple
|
(min_lon, min_lat, max_lon, max_lat) with longitude in [-180, 180]. |
required |
eps
|
float
|
Small tolerance value. |
1e-09
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[tuple[float, float, float, float]]
|
List of bounding boxes in |
list[tuple[float, float, float, float]]
|
(min_lon_360, min_lat, max_lon_360, max_lat) format or shapely boxes. |
Source code in c3s_event_attribution_tools/data/conversions.py
convert_precipitation(array, from_unit, to_unit)
staticmethod
Convert precipitation values from one unit to another.
This method performs in-place precipitation conversion on the provided array or pandas Series and supports meters (m) and millimeters (mm).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray or Series
|
The input array or Series containing precipitation values to be converted. |
required |
from_unit
|
str
|
Source precipitation unit ('m' or 'mm'). Default is 'm'. |
required |
to_unit
|
str
|
Target precipitation unit ('m' or 'mm'). Default is 'mm'. |
required |
Returns: np.ndarray or pd.Series: The array or Series with precipitation values converted to the target unit.
Source code in c3s_event_attribution_tools/data/conversions.py
convert_temperature(array, from_unit, to_unit)
staticmethod
Convert temperature values from one unit to another.
This method performs in-place temperature conversion on the provided array or pandas Series and supports Kelvin (k), Celsius (c), and Fahrenheit (f).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray or Series
|
The input array or Series containing temperature values to be converted. |
required |
from_unit
|
str
|
Source temperature unit ('k', 'c', or 'f'). Default is 'k'. |
required |
to_unit
|
str
|
Target temperature unit ('k', 'c', or 'f'). Default is 'c'. |
required |
Returns:
| Type | Description |
|---|---|
T
|
np.ndarray or pd.Series: The array or Series with temperature values converted to the |
T
|
target unit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If from_unit is not one of 'k', 'c', or 'f'. |
TypeError
|
If the input array is neither a numpy ndarray nor a pandas Series. |
Notes
- If from_unit and to_unit are identical, no conversion is performed.
- Conversion modifies the input array or Series in place.
- Conversion formulas:
- Kelvin to Celsius: C = K - 273.15
- Kelvin to Fahrenheit: F = (K - 273.15) × 9/5 + 32
- Celsius to Kelvin: K = C + 273.15
- Celsius to Fahrenheit: F = C × 9/5 + 32
- Fahrenheit to Kelvin: K = (F - 32) × 5/9 + 273.15
- Fahrenheit to Celsius: C = (F - 32) × 5/9
Source code in c3s_event_attribution_tools/data/conversions.py
convert_unit(array, from_unit, to_unit)
staticmethod
Convert units of measurement for the provided array or pandas Series.
This method currently supports temperature conversions between Kelvin (k), Celsius (c), and Fahrenheit (f). Additional unit conversions can be added as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray or Series
|
The input array or Series containing values to be converted. |
required |
from_unit
|
str
|
Source unit of measurement (e.g., 'k', 'c', 'f', 'm'). |
required |
to_unit
|
str
|
Target unit of measurement (e.g., 'k', 'c', 'f', 'mm'). |
required |
Returns: np.ndarray or pd.Series: The array or Series with values converted to the target unit.
Source code in c3s_event_attribution_tools/data/conversions.py
variable_name_translation(variable_name)
staticmethod
Translate variable names between different conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
The variable name to translate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The translated variable name. |