API Reference
This page provides the technical documentation for the functions and classes within the Turban Toolbox.
Instruments
Generic instrument API (instruments/generic/api.py)
Dropsonde
Bases: Instrument
Source code in turban/instruments/generic/api.py
11 12 13 14 15 16 17 | |
to_shear_level1()
abstractmethod
Convert raw data to shear level 1
Source code in turban/instruments/generic/api.py
12 13 14 15 16 17 | |
Generic instrument configuration (instruments/generic/config.py)
MSS Configuration (instruments/mss/config.py)
MssDeviceConfig
Bases: BaseModel
Source code in turban/instruments/mss/config.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
from_mrd(filename, shear_sensitivities, offset=0)
classmethod
Create a MssDeviceConfig from an MRD file.
Parameters
filename : str or Path Path to the MRD file. shear_sensitivities : dict[str, float] Mapping of sensor name to sensitivity value for shear sensors. offset : int, optional 16-bit count offset, typically 0 or -32768 for older devices (default 0).
Returns
MssDeviceConfig Configuration object with sensors parsed from the MRD file header.
Source code in turban/instruments/mss/config.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
from_prb(filename, shear_sensitivities=[None, None], offset=0)
classmethod
Create a MssDeviceConfig from a PRB file.
Parameters
filename : str or Path Path to the PRB file. shear_sensitivities : list, optional Shear sensitivity values (default [None, None]). offset : int, optional 16-bit count offset (default 0).
Raises
NotImplementedError This method is not yet implemented.
Source code in turban/instruments/mss/config.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
MssSensorNTC
Bases: MssSensor
Steinhart/Hart NTC Polynomial
Source code in turban/instruments/mss/config.py
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 | |
__init__(*args, **kwargs)
Initialize and build Steinhart-Hart calibration polynomial.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, coefficients, channel, and optional unit.
The polynomial is built from all but the last coefficient.
Source code in turban/instruments/mss/config.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
raw_to_units(rawdata, offset)
Apply Steinhart-Hart NTC calibration to raw data.
Parameters
rawdata : array_like Raw resistance counts. offset : float Additive offset applied before taking the natural log.
Returns
ndarray Temperature in degrees Celsius.
Source code in turban/instruments/mss/config.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
MssSensorOptode
Bases: MssSensor
Convert oxygen optode rawdata to physical units
Source code in turban/instruments/mss/config.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
__init__(*args, **kwargs)
Initialize and build two-stage optode calibration polynomials.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, coefficients, channel, and optional unit.
Two polynomials are built: _p1 from coefficients[0:2] (raw-to-mV)
and _p2 from coefficients[-2:] (mV-to-O2, zero-point correction).
Source code in turban/instruments/mss/config.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
raw_to_units(rawdata, offset)
Apply two-stage oxygen optode calibration to raw data.
Parameters
rawdata : array_like Raw sensor counts. offset : float Additive offset applied in the first conversion stage.
Returns
ndarray Calibrated oxygen concentration in physical units.
Source code in turban/instruments/mss/config.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
MssSensorOptodeInternalTemp
Bases: MssSensor
Source code in turban/instruments/mss/config.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
__init__(*args, **kwargs)
Initialize and build calibration polynomial for optode internal temperature.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, coefficients, channel, and optional unit.
Source code in turban/instruments/mss/config.py
284 285 286 287 288 289 290 291 292 293 294 295 296 | |
raw_to_units(rawdata, offset=0)
Apply polynomial calibration to raw optode internal temperature data.
Parameters
rawdata : array_like Raw sensor counts. offset : float, optional Additive offset applied before evaluating the polynomial.
Returns
ndarray Calibrated temperature in physical units.
Source code in turban/instruments/mss/config.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
MssSensorPoly
Bases: MssSensor
Source code in turban/instruments/mss/config.py
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 | |
__init__(*args, **kwargs)
Initialize and build the calibration polynomial from coefficients.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, coefficients, channel, and optional unit.
Source code in turban/instruments/mss/config.py
35 36 37 38 39 40 41 42 43 44 45 46 47 | |
raw_to_units(rawdata, offset=0)
Apply polynomial calibration to raw data.
Parameters
rawdata : array_like Raw sensor counts. offset : float, optional Additive offset applied before evaluating the polynomial.
Returns
ndarray Calibrated data in physical units.
Source code in turban/instruments/mss/config.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
MssSensorPressure
Bases: MssSensor
Source code in turban/instruments/mss/config.py
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 | |
__init__(*args, **kwargs)
Initialize and build pressure calibration polynomial.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, coefficients, channel, and optional unit.
The polynomial is built from all but the last coefficient.
Source code in turban/instruments/mss/config.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
raw_to_units(rawdata, offset=0)
Apply pressure calibration to raw data.
Parameters
rawdata : array_like Raw sensor counts. offset : float, optional Additive offset applied before evaluating the polynomial.
Returns
ndarray Calibrated pressure; the last coefficient is subtracted as a zero-offset.
Source code in turban/instruments/mss/config.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
MssSensorTurb
Bases: MssSensor
Convert rawdata turbidity to NFC
Source code in turban/instruments/mss/config.py
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 | |
__init__(*args, **kwargs)
Initialize and build turbidity calibration polynomial.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, coefficients, channel, and optional unit.
The polynomial is built from all but the last coefficient.
Source code in turban/instruments/mss/config.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
raw_to_units(rawdata, offset)
Apply turbidity (NFC) calibration to raw data.
Parameters
rawdata : array_like Raw sensor counts. offset : float Additive offset applied before polynomial evaluation.
Returns
ndarray Calibrated turbidity in physical units.
Source code in turban/instruments/mss/config.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
MssShearSensor
Bases: MssSensor
Source code in turban/instruments/mss/config.py
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 | |
__init__(*args, **kwargs)
Initialize and compute calibration coefficients from sensitivity.
Parameters
args
Positional arguments passed to pydantic BaseModel.
*kwargs
Keyword arguments passed to pydantic BaseModel. Expected keys include
name, sensitivity, channel, and optional unit.
Coefficients are derived from sensitivity and stored in coefficients.
Source code in turban/instruments/mss/config.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
raw_to_units(rawdata, offset=0)
Apply shear sensor calibration to raw data.
Parameters
rawdata : array_like Raw sensor counts. offset : float, optional Subtractive offset (shear sensors use negative offset convention).
Returns
ndarray Calibrated shear in physical units.
Source code in turban/instruments/mss/config.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
MSS MRD file format (instruments/mss/mss_mrd.py)
parse_header(header)
Parse an ASCII MRD file header into a configuration dictionary.
Extracts metadata from the ASCII header of a Microstructure Raw Data (MRD) file, including ship, cruise, date, and channel calibration coefficients.
Parameters
header : str ASCII header text from the MRD file.
Returns
dict Configuration dictionary with keys 'ship', 'cruise', 'date_pc', and 'mss' (which contains a nested dict with channel information).
Source code in turban/instruments/mss/mss_mrd.py
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
read_mrd(filestream, header_only=False, pos_time_only=False)
Read a binaray SST MRD (Microstructure Raw Data) file
Parameters
filestream header_only pos_time_only
Source code in turban/instruments/mss/mss_mrd.py
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 | |
MSS HHL raw data format (instruments/mss/mss_hhl.py)
hhl
A processor for the HHL binary datastream from Sea & Sun Technology.
Source code in turban/instruments/mss/mss_hhl.py
8 9 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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
add_to_buffer(data)
Append data to the internal buffer.
Parameters
data : bytes Data to append to the buffer.
Source code in turban/instruments/mss/mss_hhl.py
17 18 19 20 21 22 23 24 25 | |
align_buffer()
Align buffer to channel 0.
Returns
None or bool None if alignment failed, True if buffer is valid and ready to process.
Source code in turban/instruments/mss/mss_hhl.py
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 | |
decode_HHL(hhldata)
Decode three bytes of HHL data into channel and value.
Parameters
hhldata : bytes HHL packet data, length >= 3.
Returns
list of (int, int) or None [channel, data] where channel is the channel number and data is the decoded 16-bit value. Returns None if the packet is invalid.
Source code in turban/instruments/mss/mss_hhl.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
process_buffer()
Process data in the buffer.
Returns
list of (ndarray, ndarray) or None [channel_cat, data_cat] where channel_cat is an ndarray of channel numbers and data_cat is an ndarray of shape (n_packets, 16) with decoded data values. Returns None if buffer cannot be aligned.
Source code in turban/instruments/mss/mss_hhl.py
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 | |
process_buffer_legacy()
Process data in the buffer (legacy version).
Returns
list of (ndarray, ndarray) or None [channel_cat, data_cat] where channel_cat is an ndarray of channel numbers and data_cat is an ndarray of shape (n_packets, 16) with decoded data values. Returns None if buffer cannot be aligned.
Source code in turban/instruments/mss/mss_hhl.py
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 234 235 236 237 238 239 240 241 | |
valid_packet(data)
Check if the data packet has a valid HHL pattern.
Parameters
data : bytes Data to validate.
Returns
bool True if the first three bytes have the HHL pattern, False otherwise.
Source code in turban/instruments/mss/mss_hhl.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
MicroRider common data classes (instruments/microrider/rsCommon.py)
MicroRider configuration parser (instruments/microrider/rsConfig_parser.py)
MicroRiderConfig
Class to handle MicroRider configuration from the raw setupstr read from the header information.
Parameters
str
string as found in the header of the data file, containing there configuration of the MicroRider.
The class provieds methods to query the configuration of a specific channel, as well as extracting the raw channel names, cruise and instrument information.
Example
cnf = MicroRiderConfig() cnf.parse(setupstring)
get the cruise information
cnf.get_config("cruise_info")
get the config of a given section...
cnf.get_config("channel08")
get the config of given channel name...
cnf.get_channel_config("sh1")
Source code in turban/instruments/microrider/rsConfig_parser.py
5 6 7 8 9 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 | |
get_channel_config(name)
Get the configuration of a channel
Parameters
name : str name of channel
Returns
dict[str, str | int | float | list[int]] | None a dictionary with configuration values or None if name is not found.
Source code in turban/instruments/microrider/rsConfig_parser.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
get_channel_name_map()
Get a mapping of channel sensor name -> channel section name
Returns
dict[str, str]
Source code in turban/instruments/microrider/rsConfig_parser.py
162 163 164 165 166 167 168 169 170 171 172 | |
get_config()
Retrieve the parsed configuration.
Returns
dict[str, dict[str, str | int | float | list[int]]] Nested dictionary of configuration
Source code in turban/instruments/microrider/rsConfig_parser.py
130 131 132 133 134 135 136 137 138 139 | |
get_section(section='root')
Retrieve a specific section of the configuration.
Parameters
section: str Section name (defaults to 'root')
Returns
dict[str, str | int | float | list[int]] Dictionary of key-value pairs in the section
Raises
KeyError If the section does not exist
Source code in turban/instruments/microrider/rsConfig_parser.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
parse(config_text)
Parse the configuration text into a nested dictionary.
Parameters
config_text: str Configuration file contents as a string
Source code in turban/instruments/microrider/rsConfig_parser.py
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 | |
MicroRider channel converters (instruments/microrider/rsConversions.py)
Adis
Bases: object
The ADIS16209 inclinometer outputs words that combine data with status flags. The data and status flags must be seperated before the data can be converted into physical units. This function extracts the data and converts it into valid 16bit, 2s-compliment words.
ADIS16209 words have the following format:
bit15 = new data present
bit14 = error flag
bit[13:0] = X and Y inclination data, 2s-compliment (X and Y channels) bit[11:0] = temperature data, unsigned (temperature channel)
Source code in turban/instruments/microrider/rsConversions.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
Aem1g_a
Bases: Converter
Specific converter method for Aem1g_a type channels
Source code in turban/instruments/microrider/rsConversions.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
Aem1g_d
Bases: Converter
Specific converter method for Aem1g_d type channels
Source code in turban/instruments/microrider/rsConversions.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
Converter
Bases: ABC
Base class for detailed converter classes
Parameters
config : ChannelConfig channel configuration dataclass
Source code in turban/instruments/microrider/rsConversions.py
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 | |
get_optional_parameter(p)
Looks up a parameter setting from the configuration
Parameters
p : string parameter name
Returns float value of parameter setting.
The method returs the value set in the configuration, or a default value when no value is configured. If also no default value is given None is returned.
Source code in turban/instruments/microrider/rsConversions.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
get_parameter(p)
Looks up a parameter setting from the configuration
Parameters
p : string parameter name
Returns float value of parameter setting.
The method returs the value set in the configuration, or a default value when no value is configured. If also no default value is given, a ValueError is raised.
Source code in turban/instruments/microrider/rsConversions.py
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 | |
Deconvolve
Bases: object
Description
Deconvolve a vector of pre-emphasized data (temperature, conductivity, or pressure) to yield high-resolution data. The pre-emphasized signal (x+gain*dx/dt) is low-pass filtered using appropriate initial conditions after the method described in Mudge and Lueck, 1994.
For pressure, you must pass both 'X' and 'X_dX' to this function. Both vectors are needed to make a good estimate of the initial conditions for filtering. Initial conditions are very important for pressure because the gain is usually $\SI{\sim20}{\s}$, and errors caused by a poor choice of initial conditions can last for several hundred seconds! In addition, the high-resolution pressure is linearly adjusted to match the low-resolution pressure so that the factory calibration coefficients can later be used to convert this signal into physical units.
The gains for all signal types are provided in the calibration report of your instrument.
Examples
C1_hres = deconvolve( 'C1_dC1', [], C1_dC1, fs_fast, setupfilestr )
Deconvolve the micro-conductivity channel using the diff_gain parameter from the 'C1_dC1' channel section found within the supplied configuration string. Because there is no channel without pre-emphasis, the argument is left empty.
T1_hres = deconvolve( '', T1, T1_dT1, fs_fast, 1.034 )
Deconvole the thermistor data using both channels with and without pre-emphasis. Using both channels improves the initial deconvolution accuracy and compensates for slight variations in the calibration coefficients between the two channels. Note the explicitly provided value for diff_gain. One typically provides the configuration string and channel name as shown in the previous example.
Mudge, T.D. and R.G. Lueck, 1994: Digital signal processing to enhance oceanographic observations, J. Atmos. Oceanogr. Techn., 11, 825-836.
@image @images/pressure_deconvolution1 @Deconvolution example. @The green curve is from the normal pressure channel, and the blue curve is derived from the pre-emphasized pressure channel. This data is from a profiler that has impacted the soft bottom of a lake. Both signals are shown with full bandwidth (0 - 32 Hz) without any smoothing. The full-scale range of the pressure transducer is 500 dBar.
@image @images/pressure_deconvolution2 @Deconvolution example two. @Same as previous figure but with zoom-in on only the high-resolution pressure. Again, full bandwidth without any smoothing.
@image @images/pressure_deconvolution3 @The rate of change of pressure derived from the normal pressure signal and the high-resolution pressure signals using the gradient function. @Full bandwidth signals of the rate of change of pressure. The normal pressure signal (green) produces a fall-rate that is useless without extensive smoothing because it is not even monotonic. The rate of change of the high-resolution pressure (blue) is smooth, always positive, and, therefore, the high-resolution pressure itself, can be used directly for plotting other variables as a function pressure (or depth). The high-resolution rate of change of pressure has been multiplied by 10 for visual clarity. The fall-rate is about $\SI{0.17}{\m\per\s}$.
Source code in turban/instruments/microrider/rsConversions.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
Gnd
Bases: Converter
Specific converter method for GND type channels
Does not do any conversion.
Source code in turban/instruments/microrider/rsConversions.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
Incl
Bases: Converter
Specific converter method common to attitude type channels
Source code in turban/instruments/microrider/rsConversions.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
InclT
Bases: Incl
Specific converter method for attitude's temperature type channels
Source code in turban/instruments/microrider/rsConversions.py
262 263 264 265 266 267 268 269 | |
InclXY
Bases: Incl
Specific converter method for attitude type channels
Source code in turban/instruments/microrider/rsConversions.py
254 255 256 257 258 259 | |
PassThrough
Bases: Converter
Pass through converter
Source code in turban/instruments/microrider/rsConversions.py
329 330 331 332 333 334 335 336 337 338 339 | |
Piezo
Bases: Converter
Specific converter method for Piezo type channels
Source code in turban/instruments/microrider/rsConversions.py
96 97 98 99 100 101 102 103 104 105 106 107 108 | |
Poly
Bases: Converter
Specific converter method for polynomial type channels
Source code in turban/instruments/microrider/rsConversions.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
Shear
Bases: Converter
Specific converter method for shear type channels
Source code in turban/instruments/microrider/rsConversions.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
Therm
Bases: Converter
Source code in turban/instruments/microrider/rsConversions.py
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 | |
__init__(config)
Specific converter method for thermistor type channels
Source code in turban/instruments/microrider/rsConversions.py
128 129 130 131 132 | |
Voltage
Bases: Converter
Specific converter method for voltage type channels
Source code in turban/instruments/microrider/rsConversions.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
get_converter(channel_config)
Converter factory
Parameters
channel_config : ChannelConfig channel configuration dataclass
Returns
Converter object, relevant for the requested channel type.
Note : this code uses the match/case structure and requires therefore python 3.10+
Source code in turban/instruments/microrider/rsConversions.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
MicroRider binary I/O (instruments/microrider/rsIO.py)
Channel
Bases: object
Channel object
Parameters
name : string name of channel config : ChannelConfig channel configuration object (from setupstr) deconvolved : bool (False) flag to indicate whether this is a deconvolved channel.
This class holds the data of each channel: when read : the raw data are in .data (._data is None) when converted: the converted data are in .data and the raw data in ._data.
The following methods are provided:
copy(): this returns a new channel, but keeps the same configuration, and sets the deconvolved flag. This method is used to create new channels for the high resolution parameters
correct_sign(): sign correction (u2 -> i2) if configuration dictates.
convert_to_units(): applies to associated conversion algortithm (determined from the config dictionary) to the raw data.
join(): joins even and odd channels. Warning not fully tested. This method can be called by through the + operator: ch = chE+chO
Source code in turban/instruments/microrider/rsIO.py
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 | |
convert_to_units()
Converts channel into unit bearing data
The attribute .data is copied to ._data (raw data) and converted using a conversion method associated with the type field of the configuration.
Sets the converted_into_units flag.
Source code in turban/instruments/microrider/rsIO.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
copy(new_name='', deconvolved=True)
Copies configuration into a new channel with optionally a new name
Parameters
new_name : string (None) gives this name to the new channel. If None, it keeps the original name.
Returns
Channel object Empty channel, with the configuration copied, and the deconvolved flag set.
Source code in turban/instruments/microrider/rsIO.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
correct_sign()
Corrects sign of data (if configuration dictates)
Some channels record in unsigned integers. If required they need to be signed, where the msb is used as sign.
Source code in turban/instruments/microrider/rsIO.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
join(even_channel, odd_channel)
Joins even and odd channel
Parameters
even_channel : Channel Channel with the even signal (16 bit integer) odd_channel : Channel Channel with the odd signal (16 bit integer)
Returns
Channel Channel with combined channel (32 bit)
Note: Not fully tested.
Source code in turban/instruments/microrider/rsIO.py
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 | |
ChannelMatrix
Bases: object
Data class to store the sensor matrix
Parameters
microrider_config : dict[str, str|int|float|list[int]] dictionary holding the MR configuration
Source code in turban/instruments/microrider/rsIO.py
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
HeaderParser
Source code in turban/instruments/microrider/rsIO.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
check_for_bad_blocks(fp)
Checks for bad blocks
Method to check for bad blocks. The method reads all headers, and requires that the number of data blocks read matches the number of data blocks as written in the header. If these do not match, this points to an error in the data file.
If something does not match, an exception is thrown.
Parameters
fp: io.BufferedReader file descriptor pointing to an open file
Returns
int: number of data blocks read.
Source code in turban/instruments/microrider/rsIO.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
parse(fd)
Parses header block of a data record. It is assumed that the block is HeaderEnum.HeaderSize large.
Parameters
fd : io.BufferedReader file descriptor pointing to an open file
Returns
ByteHeader: a dataclass with (byte) header information
Source code in turban/instruments/microrider/rsIO.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
read_setupstring(fd, byte_header)
Reads the setupstring from the binary file
Parameters
fd : file descriptor
ByteHeader
ByteHeader dataclass
Returns
str setupstring.
Source code in turban/instruments/microrider/rsIO.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
MicroRiderData
Bases: object
Data class to hold all data collected by the RSI MicroRider.
parameters
string
full path to .P file
config: system configuration, extracted from the setupfile string.
Source code in turban/instruments/microrider/rsIO.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | |
add_channel_data(data_snr)
Adds the channel data, from array with dtype i2/u2
Parameters
array
array with bytes converted to signed and unsigned 16 bit integers.
The method adds all the numeric data conveyed in this matrix to the specific channels. It uses the sensor matrix to determine which part goes to what channel.
this channel adds a keyword to the configuration: depending on the
number of values per record, it adds whether this is a fast or slow senor if the frequency is 512 or 64, respectively.
Source code in turban/instruments/microrider/rsIO.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
add_header_data(byte_header, n_records)
Adds specific parameters from the byteheader to the data structure
Parameters
byte_header : ByteHeader ByteHeader dataclass
Source code in turban/instruments/microrider/rsIO.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
combine_split_channels()
Combines even and odd channels into one
All channels that are labelled _E and _O are combined into one, using 32 bit ints.
This method has not thorougly been tested because the test data don't have any
split channels. It was tested modifying the data file, which has been reverted back again.
Source code in turban/instruments/microrider/rsIO.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
convert_channels()
Converts all channels
Converts all channels to data with physical units. If a channel needs to be deconvolved first, this is also done (and leads to a new channel).
Source code in turban/instruments/microrider/rsIO.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
deconvolve_and_convert_channel(ch)
Treats channels that need deconvolving separately
this method creates a new channel, with the name
based on the primary channel (e.g. T1) with "_hires" added.
Source code in turban/instruments/microrider/rsIO.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
get_file_timestamp(byte_header)
Gets time stamp of the file
Parameters
byte_header : ByteHeader ByteHeader dataclass with the header parameters
Returns
(float, str, str): timestamp, date string, time string
The methods return time stamp (seconds since 1970), date string and time string
Source code in turban/instruments/microrider/rsIO.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
read_p_file(filename, setupstring_filename='')
Function to read a single .p file.
Parameters
filename : str Name of .p file to read setupstring_filename : str (Optional : "") Name of external setup file to be used.
Returns
MicroRiderData object Raw data, converted into physical units.
Source code in turban/instruments/microrider/rsIO.py
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
Data Processing
Generic processing API (process/generic/api.py)
Defines high-level API to interact with TURBAN toolbox
AuxiliaryData
dataclass
Bases: TimeseriesLevel
Mix-in class to provide support for non-essential auxiliary data
Source code in turban/process/generic/api.py
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
__post_init__()
Initialise _aux_data to an empty dict if it was not provided.
Source code in turban/process/generic/api.py
157 158 159 160 | |
add_aux_data(data, name=None, agg_method='mean', name_out=None)
Adds auxiliary data to any level.
If data is a 1D numpy array, uses simplified API.
Must then supply name, agg_method and optionally name_out.
Otherwise, use the full API.
Source code in turban/process/generic/api.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
arrays_as_xr_dicts()
Separate array fields including auxiliary data into data-variable and coordinate dicts.
Returns
data_vars : dict
Fields (including auxiliary data) not listed in _coords.
coords : dict
Fields listed in _coords.
Source code in turban/process/generic/api.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
from_xarray(ds)
classmethod
Instantiate from an xarray Dataset, loading auxiliary variables.
Parameters
ds : xr.Dataset Dataset; variables not recognised as core fields are added as auxiliary data.
Returns
AuxiliaryData New instance with core and auxiliary data populated.
Source code in turban/process/generic/api.py
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 | |
HasLevelBelow
dataclass
Bases: TimeseriesLevel
Source code in turban/process/generic/api.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
from_level_below(data)
classmethod
Construct this level from the level-below data object.
Parameters
data : TimeseriesLevel or None Data from the level below.
Returns
HasLevelBelow
New instance initialised from data.
Source code in turban/process/generic/api.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
Level2
dataclass
Bases: HasLevelBelow, AuxiliaryData
Source code in turban/process/generic/api.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
Level3
dataclass
Bases: HasLevelBelow, AuxiliaryData
Source code in turban/process/generic/api.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
agg(data, data_len, chunk_length, chunk_overlap, section_number)
classmethod
Aggregates data from Level2. These are stored in in the form: {variable_name_fast: ([dims], ndarray, {agg_method: variable_new_slow}])}
Source code in turban/process/generic/api.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
Level4
dataclass
Bases: HasLevelBelow, AuxiliaryData
Source code in turban/process/generic/api.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
Processing
Bases: ABC
Propagates a given start level up to level 4.
Source code in turban/process/generic/api.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
cfg
property
Segment configuration from the top-level data object.
data_len_fast
property
Length of the fast time vector (levels 1 and 2)
level1
property
Level 1 data, or None if not available.
level2
property
Level 2 data, or None if not available.
level3
property
Level 3 data, or None if not available.
level4
property
Level 4 data (the topmost processed level).
__init__(data)
Propagate data up to level 4 using the level mapping.
Parameters
data : TimeseriesLevel Starting data object at any level.
Source code in turban/process/generic/api.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
from_xarray(data_tree)
classmethod
Instantiate pipeline from lowest available level
Source code in turban/process/generic/api.py
567 568 569 570 571 572 573 574 575 576 577 578 579 | |
to_xarray()
Export
Source code in turban/process/generic/api.py
556 557 558 559 560 561 562 563 564 565 | |
TimeseriesLevel
dataclass
Source code in turban/process/generic/api.py
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 | |
arrays_as_xr_dicts()
Separate array-typed fields into data-variable and coordinate dicts.
Returns
data_vars : dict
Fields not listed in _coords, in xarray (dims, data) format.
coords : dict
Fields listed in _coords, in xarray (dims, data) format.
Source code in turban/process/generic/api.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
from_xarray(ds)
classmethod
Instantiate this level from an xarray Dataset.
Parameters
ds : xr.Dataset Dataset containing array fields and config global attributes.
Returns
TimeseriesLevel New instance populated from the dataset.
Source code in turban/process/generic/api.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
get_attr(name)
Retrieve an attribute by name.
Parameters
name : str Name of the attribute to retrieve.
Returns
object Value of the attribute.
Source code in turban/process/generic/api.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
to_xarray()
Export this level to an xarray Dataset.
Returns
xr.Dataset Dataset containing all array fields as data variables and coordinates, with TURBAN standard attributes and config stored as global attributes.
Source code in turban/process/generic/api.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
get_type_hints_recursive(cls)
Collect all type definitions on a given class, also from parent classes.
:param obj: Any python object
Source code in turban/process/generic/api.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
Generic processing configuration (process/generic/config.py)
SegmentConfig
Bases: BaseModel
Configures segment-wise processing of timeseries.
Source code in turban/process/generic/config.py
7 8 9 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 | |
number_fft_windows_per_chunk
property
N_f in the ATOMIX paper
add_to_xarray(ds)
Write configuration fields as global attributes of an xarray Dataset.
Parameters
ds : xr.Dataset
Dataset whose attrs will be updated in-place.
Source code in turban/process/generic/config.py
67 68 69 70 71 72 73 74 75 | |
from_atomix_netcdf(fname)
classmethod
Create a SegmentConfig from an ATOMIX netCDF file.
Parameters
fname : str Path to the ATOMIX netCDF file.
Returns
SegmentConfig New instance with attributes read from the file.
Source code in turban/process/generic/config.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
from_xarray(ds)
classmethod
Create from xarray Dataset global attributes.
Parameters
ds : xr.Dataset
Dataset whose attrs contain the configuration fields.
Returns
SegmentConfig Validated instance constructed from the dataset attributes.
Source code in turban/process/generic/config.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
Shear processing API (process/shear/api.py)
NetcdfReader
Load any netcdf with variable mapping from turban standard name (see variables.py) to name in the netcdf. NB This class is still under construction.
TODO Load the variable mapping directly from variables.py.
Source code in turban/process/shear/api.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
ShearLevel1
dataclass
Bases: Level1
Source code in turban/process/shear/api.py
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 | |
from_atomix_netcdf(fname)
classmethod
Load ShearLevel1 from an ATOMIX netCDF file.
Parameters
fname : str Path to the ATOMIX netCDF file.
Returns
ShearLevel1 Level 1 instance populated from the file.
Source code in turban/process/shear/api.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
ShearLevel2
dataclass
Bases: Level2
Source code in turban/process/shear/api.py
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 | |
from_atomix_netcdf(fname)
classmethod
Load ShearLevel2 from an ATOMIX netCDF file.
Parameters
fname : str Path to the ATOMIX netCDF file.
Returns
ShearLevel2 Level 2 instance populated from the file (with Level1 attached below).
Source code in turban/process/shear/api.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
ShearLevel3
dataclass
Bases: Level3
Source code in turban/process/shear/api.py
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
data_length
property
l_\epsilon in ATOMIX paper
log_psi_var
property
sigma^2_{ln\Psi} in the ATOMIX paper
number_signals_vibration_removal
property
N_V in the ATOMIX paper
psi_k_sh_confidence_interval
property
95% confidence interval of power spectrum. Eq. 23 in the ATOMIX paper
ShearProcessing
Bases: Processing
Source code in turban/process/shear/api.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
from_atomix_netcdf(fname, level, data_aux=None)
classmethod
Create shear processing pipeline from ATOMIX netcdf file.
Supplying data_aux here triggers the full API (dictionary with aggregation instructions if level<=2). If one wishes to use the simplified data aggregation API, one should first create a ShearLevelN object, then use .add_aux_data().
Source code in turban/process/shear/api.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
Shear processing configuration (process/shear/config.py)
Microtemperature processing API (process/utemp/api.py)
UTempLevel2
dataclass
Bases: Level2
Source code in turban/process/utemp/api.py
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 | |
UTempLevel3
dataclass
Bases: Level3
Source code in turban/process/utemp/api.py
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 | |
Microtemperature processing configuration (process/utemp/config.py)
UTempConfig
Bases: SegmentConfig
Configures processing of timeseries using temperature gradient spectra.
Source code in turban/process/utemp/config.py
4 5 6 7 8 | |
Utilities
Utility functions (utils/util.py)
agg_fast_to_slow(x, section_number_or_data_len=None, chunk_length=None, chunk_overlap=None, agg_method='mean', reshape_index=None)
Aggregate any quantities from fast sampling rate (e.g., shear timeseries)
to slow sampling rate (e.g, spectra).
If reshape_index is supplied, section_number_or_data_len, chunk_length and
chunk_overlap are disregarded
Parameters
method: "take_first": use first value of every chunk "take_mid": use midpoint value of every chunk "take_last": use last value of every chunk any other: use numpy function (e.g., "mean", "max", ... )
agg_method can be anything that is an attribute of a numpy array, e.g. mean,
max, etc.
Source code in turban/utils/util.py
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 | |
atleast_nd_last(arr, targetshape)
Prepend size-1 axes until arr has the same number of dimensions as targetshape.
Parameters
arr : ndarray, shape (..., dim0) Input array to expand. targetshape : tuple of int Target shape whose number of dimensions is the goal.
Returns
ndarray Array with leading size-1 axes added as needed.
Source code in turban/utils/util.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
boolarr_to_sections(bools)
Partition boolean array into contiguous True-valued index ranges.
Parameters
bools : Bool[ndarray, "time"] Boolean array.
Returns
list[list[int]]
List of contiguous index ranges where bools is True.
Source code in turban/utils/util.py
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |
butterfilt(signal, cutoff_freq_Hz, sampfreq, axis=-1, **kwarg)
Apply first-order Butterworth filter.
Parameters
signal : array_like
Input signal.
cutoff_freq_Hz : float
Cutoff frequency in Hz.
sampfreq : float
Sampling frequency in Hz.
**kwarg
Additional keyword arguments passed to scipy.signal.butter.
Returns
ndarray Filtered signal.
Source code in turban/utils/util.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
define_sections(*data_and_bounds, segment_min_len=0, trim=0)
Identify contiguous sections where all data fall within specified bounds.
Parameters
data_and_bounds : tuple[Float[ndarray, "any"], float, float] Variable number of (data_array, lo, up) tuples specifying data arrays and their lower and upper bounds. Sections must satisfy all bounds. segment_min_len : int, optional Minimum segment length to retain. Default is 0. trim : int, optional Positive values shrink sections by this amount; negative values widen them. Default is 0.
Returns
Int[ndarray, "*any"] Section numbers (0 for invalid regions, positive integers for valid sections).
Source code in turban/utils/util.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
diss_chunk_wise_reshape_index(reshape_index)
Flatten last two dimensions while ensuring unique indices per diss_chunk.
Parameters
reshape_index : Int[ndarray, "diss_chunk fft_chunk segment_length"] 3D index array to flatten.
Returns
Int[ndarray, "diss_chunk chunk_length"] 2D index array with unique indices for each diss_chunk.
Source code in turban/utils/util.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
ensure_reshape_index(func)
Decorate func to accept alternative chunking parameters.
Enables func to accept section_number_or_data_len, segment_length,
segment_overlap, chunk_length, and chunk_overlap as alternatives to
reshape_index.
Parameters
func : callable Function to decorate.
Returns
callable Decorated function with reshape_index parameter resolution.
Source code in turban/utils/util.py
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 | |
fft_grad(signal, dt)
Compute gradient via FFT along last axis.
Parameters
signal : Float[ndarray, "... time"] Input signal. dt : float Time step in seconds.
Returns
Float[ndarray, "... freq"] Gradient computed via FFT.
Source code in turban/utils/util.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
get_chunking_index(section_number_or_data_len, *length_and_overlap)
Create index array for rechunking a dimension into overlapping segments.
Parameters
section_number_or_data_len : Int[ndarray, "time_fast"] or int Section markers (array of int) or data length (int). *length_and_overlap : tuple[int, int] Variable number of (length, overlap) tuples specifying chunk parameters to be applied successively.
Returns
Int[ndarray, "*any"] Index array for chunking.
Source code in turban/utils/util.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
get_vsink(pressure_raw, sampfreq=1024.0)
Estimate sinking velocity from raw pressure by low-pass filtering and differentiation.
Parameters
pressure_raw : array_like Raw pressure time series. sampfreq : float, optional Sampling frequency in Hz. Default is 1024.0.
Returns
vsink : ndarray Estimated sinking velocity (dP/dt of low-pass filtered pressure). pressure_lp : ndarray Low-pass filtered pressure time series.
Source code in turban/utils/util.py
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 | |
integrate(y, x, x_from, x_to)
Integrate y over x along last axis using trapezoidal rule.
Parameters
y : Float[ndarray, "... time frequency"] Integrand values. x : Float[ndarray, "... time frequency"] Corresponding x-axis values. x_from : Float[ndarray, "... time"] Lower integration limits. x_to : Float[ndarray, "... time"] Upper integration limits.
Returns
Float[ndarray, "... time"] Integral along last axis.
Source code in turban/utils/util.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
kolmogorov_length(eps, molvisc)
Compute the Kolmogorov length scale.
Parameters
eps : Float[ndarray, "any"] TKE dissipation rate in W/kg. molvisc : Float[ndarray, "any"] Kinematic viscosity in m^2/s.
Returns
Float[ndarray, "*any"] Kolmogorov length scale in m.
Source code in turban/utils/util.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
reshape_any_first(P, chunklen, chunkoverlap)
Reshape first dimension into overlapping segments.
Parameters
P : Float[ndarray, "samples ..."] Input array. chunklen : int Chunk length. chunkoverlap : int Chunk overlap length.
Returns
Float[ndarray, "segment inside ..."]
Reshaped array, or zero array if dimension is smaller than chunklen.
Source code in turban/utils/util.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
reshape_any_last(P, chunklen, chunkoverlap)
Reshape last dimension into overlapping segments.
Parameters
P : Float[ndarray, "... samples"] Input array. chunklen : int Chunk length. chunkoverlap : int Chunk overlap length.
Returns
Float[ndarray, "... segment inside"]
Reshaped array, or zero array if dimension is smaller than chunklen.
Source code in turban/utils/util.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
reshape_any_nextlast(P, chunklen, chunkoverlap)
Reshape next-to-last dimension into overlapping segments.
Parameters
P : Float[ndarray, "... samples _"] Input array. chunklen : int Chunk length. chunkoverlap : int Chunk overlap length.
Returns
Float[ndarray, "... segment inside _"]
Reshaped array, or zero array if dimension is smaller than chunklen.
Source code in turban/utils/util.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
reshape_halfoverlap_first(y, w)
Reshape first dimension into half-overlapping windows.
Parameters
y : Float[ndarray, "samples ..."] Input array. w : int Window length (even integer).
Returns
Float[ndarray, "segment inside ... "] Reshaped array with half-overlapping windows.
Source code in turban/utils/util.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
reshape_halfoverlap_last(y, w)
Reshape last dimension into half-overlapping windows.
Parameters
y : Float[ndarray, "... samples"] Input array. w : int Window length (even integer).
Returns
Float[ndarray, "... segment w"] Reshaped array with half-overlapping windows.
Source code in turban/utils/util.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
reshape_overlap_index(w, overlap, N)
Create index array for overlapping window segmentation.
Parameters
w : int
Window length (positive integer).
overlap : int
Overlap length (positive integer), must be less than w.
N : int
Dimension length to expand (positive integer).
Returns
Int[ndarray, "segment w"] Index array of shape (segment, w) for overlapping windows.
Source code in turban/utils/util.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
split_data(data, section_numbers)
Split array into segments based on section markers.
Parameters
data : Num[ndarray, "... time"] Data array to split. section_numbers : Int[ndarray, "... time"] Marker array specifying section membership. Zero markers are excluded.
Returns
dict[np.int_ | int, Num[ndarray, "... time"]] Dictionary mapping section marker to corresponding data segment. Marker 0 is not included.
Source code in turban/utils/util.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
unwrap_base2(q, maxq=None)
Decompose integers into base-2 bit flags.
Parameters
q : Int[ndarray, "*any"]
Integer array to decompose.
maxq : int, optional
Maximum value to determine bit depth. If None, uses nanmax(q).
Returns
dict[int, Bool[ndarray, "*any"]]
Dictionary mapping power-of-2 integers to boolean arrays indicating
which bits are set in corresponding q elements.
Source code in turban/utils/util.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
Logging (utils/logging.py)
LoggerConfig
Configuration class for loggers
Parameters
handler : logging.Handler | None A handler to process debug messages. If None, a default handler is used. formatter : logging.Formatter | None A formatter to format debug messages. If None, a default formatter is used.
Source code in turban/utils/logging.py
6 7 8 9 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 | |
handler
property
Returns the formatted handler
Returns
logging.Handler formatted handler object.
set_formatter(formatter)
Sets the formatter for debugging messages
Parameters
formatter: logging.Formatter A formatter object defining how to format debug messages
Source code in turban/utils/logging.py
29 30 31 32 33 34 35 36 37 | |
set_handler(handler)
Sets the handler
Parameters
handler: logging.Handler A handler object defining how to output debug messages
Source code in turban/utils/logging.py
39 40 41 42 43 44 45 46 47 | |
LoggerManager
Logger manager
A class to manage various loggers created by the application, as well as in imported modules. The class is implemented as a singleton, which means that multiple instantiations return in fact the same object.
For example:
lm = LoggerManager() LM = LoggerManager() lm is LM # -> True
The class LoggerManager can be called with a debug level (as a string), which sets the default level for all loggers. The behaviour of specific loggers can be modified by the method set_level(..., filter_pattern), using the filter_pattern (regular expression).
Parameters
default_level: str | None default debug level. This will override any default level set previously. If not specified, the singleton is return without modifying the default level.
Source code in turban/utils/logging.py
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 | |
get_logger(name, config=None)
Returns a logger created previously with given name, or, creates a new logger, if no such logger exists.
Parameters
name : str name of logger (for example name) config: LoggerConfig | None Configuration object that specifies the handlers and formatters. If None, a default LoggerConfig is used.
Returns
logging.Logger A logger object.
Source code in turban/utils/logging.py
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 | |
list_all_loggers()
Lists all loggers created in this session
Returns
list[str] list of names of all loggers known in this session
See also list_loggers() for listing all loggers managed by the LoggerManager.
Source code in turban/utils/logging.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
list_loggers()
Lists all loggers created under the auspicien of the LoggerManager
Returns
list[str] list of names of all loggers, under management of the LoggerManager
See also list_all_loggers() for listing all loggers known in this session.
Source code in turban/utils/logging.py
182 183 184 185 186 187 188 189 190 191 192 | |
set_level(level, filter_pattern=None)
Set the level for all or some loggers
Parameters
level: int | str debug level (for example logging.DEBUG or "debug") filter_pattern : str | None
A regular expression to limit the setting to matching
loggers. If None, all loggers' levels are set.
Source code in turban/utils/logging.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
get_logger(name)
Get or create a named logger with the configured stream handler.
If the logger has no handlers, the pre-configured handler with custom formatter is attached automatically.
Parameters
name : str The name of the logger to retrieve or create.
Returns
logging.Logger The logger instance with the configured handler attached if needed.
Source code in turban/utils/logging.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
set_turban_loglevel(level, pattern='turban')
Set the log level for all loggers matching a name pattern.
Parameters
level : int or str The log level to set. Can be a numeric level (e.g. logging.INFO or 20) or a string (e.g. "INFO"). pattern : str, optional Logger name prefix to match. Only loggers whose names start with this pattern will be affected. Default is "turban".
Source code in turban/utils/logging.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
Spectral estimation (utils/spectra.py)
apply_var_conserve(psi, dfreq, signal_reshape)
Apply variance conservation correction to power spectral density.
Scales psi in-place such that its integral along the frequency axis equals
the variance of the input signal.
Parameters
psi : ndarray, shape (*any, freq) Power spectral density. Modified in-place. dfreq : float Frequency resolution. signal_reshape : ndarray, shape (nshear, chunks, freq) Reshaped signal used for variance calculation.
Returns
ndarray, shape (*any,) Correction factors applied to psi.
Source code in turban/utils/spectra.py
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 | |
spectrum(x, sampfreq, segment_length=None, segment_overlap=None, chunk_length=None, chunk_overlap=None, section_number=None, reshape_index=None, y=None, **estimator_kwarg)
Compute power spectral density or cross spectral density from time series.
Parameters
x : ndarray, shape (... time_fast) Input time series. sampfreq : float Sampling frequency in Hz. segment_length : int, optional FFT segment length in samples. segment_overlap : int, optional FFT segment overlap in samples. chunk_length : int, optional Dissipation chunk length. chunk_overlap : int, optional Dissipation chunk overlap. section_number : ndarray of int, shape (time_fast,), optional Section markers. reshape_index : ndarray of int, shape (diss_chunk, fft_chunk, segment_length), optional Precomputed reshaping index. If not provided, is calculated from other parameters. y : ndarray, shape (... time_fast), optional If provided, compute cross spectral density instead of PSD. **estimator_kwarg Additional keyword arguments passed to welch or csd.
Returns
psi : ndarray, shape (... chunk freq) Power spectral density (PSD) or cross spectral density (CSD). freq : ndarray, shape (freq,) Frequency array.
Source code in turban/utils/spectra.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 | |
CTD utilities (utils/ctd.py)
calc_ctd(C, T, P, lon, lat)
Parameters
C : conductivity (mS/cm)
T : in situ temperature (deg C, ITS-90)
P : Pressure (dbar)
lon, lat: degrees East/North
Returns
sigma0 : potential density anomaly (kg/m3)
SA : Absolute salinity, g/kg
CT : conservative temperature (deg C)
Source code in turban/utils/ctd.py
8 9 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 | |
fofonoff_filt(x, tau)
Correct time series for lagged sensor response. For MSS temperature, an OK default value is 55 but this should be determined individually
Source code in turban/utils/ctd.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
File paths and data download (utils/filepaths.py)
FilePaths
FilePaths
A class for managing downloading data files for test purposes from a remote server.
Intended use:
filepaths = FilePaths() atomix_benchmark_baltic_fpath = filepaths.add("data/process/shear/MSS_Baltic.nc")
and more paths you want to speficy
filepaths.download_data_if_necessary()
Source code in turban/utils/filepaths.py
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 | |
add(path)
Adds given string or Path object to the registry.
Parameters
path : str or Path Name of a path to add to the registry
str
| Type | Description |
|---|---|
str
|
Path name as a string |
Source code in turban/utils/filepaths.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
auto_download_data_if_necessary()
Download files if one or more data are missing, if and only if, the environment variable TURBAN_AUTO_DOWNLOAD_TEST_FILES is set to 1.
Source code in turban/utils/filepaths.py
69 70 71 72 73 74 75 76 77 78 | |
download_as_zip(url, dest_dir, timeout=30)
Download URL and write as a zip file
Parameters
url : str url for remote site dest_dir : str | Path path where to download the zip file
Returns
str: name of zip file
Source code in turban/utils/filepaths.py
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 | |
download_data()
Downloads test and benchmark data files from external server
Source code in turban/utils/filepaths.py
107 108 109 110 111 112 113 114 115 116 117 | |
download_data_if_necessary()
Download if one or more data files are missing
This method checks if all required files are existing on the current system, and in case one or more are failing, the data files are retrieved from a central public data file server.
Data download, and extraction are done in a temporary directoy, before being moved to the expected location.
Source code in turban/utils/filepaths.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
safe_extract_zip(zip_path, target_dir)
Extract zip_path into target_dir while preventing path traversal attacks. (AI generated method)
Parameters
zip_path : str | Path path to zip file to be extracted target_dir : str | Path path to directory into which the zip file should be extracted.
Source code in turban/utils/filepaths.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
Plot generic helpers (utils/plot/generic.py)
plot_quality_metric(ax, time, q, q_codes=None, **kwarg)
Plot integer quality flags as a pseudocolor mesh with a flag axis.
Parameters
ax : mpl.axes.Axes
Matplotlib axes to plot on.
time : ndarray, shape (any, time)
Time coordinates for the x-axis.
q : ndarray of int, shape (any, time)
Quality flags as integers; each bit represents a flag condition.
q_codes : dict, optional
Mapping from bit-flag values (powers of 2) to human-readable names.
If None, flags are labeled by their numeric value.
**kwarg
Additional keyword arguments passed to unwrap_base2.
Source code in turban/utils/plot/generic.py
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 | |
plot_section_numbers(axs, time, section_num)
Plot contiguous non-zero sections as vertical spans on multiple axes.
Parameters
axs : Iterable[mpl.axes.Axes] Collection of matplotlib axes to draw on. time : ndarray, shape (n,) Time coordinates for the x-axis. section_num : ndarray of int, shape (n,) Section markers; non-zero values indicate sections to highlight.
Source code in turban/utils/plot/generic.py
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 | |
Plot shear processing (utils/plot/shear.py)
plot(*data, subset=None)
Make all possible plots from any number of supplied data.
Source code in turban/utils/plot/shear.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
plot_level1(*data, subset=None)
Plot Level 1 data with shear and senspeed panels.
Parameters
*data : Any
ShearLevel1, ShearProcessing, xr.Dataset, or xr.DataTree objects.
subset : list of tuple, optional
List of (variable, vmin, vmax) bounds for subsetting. If None, no
subsetting is applied.
Returns
tuple of (matplotlib.figure.Figure, ndarray of Axes) Figure with panels for shear (one line per sensor), senspeed, and any remaining data variables.
Source code in turban/utils/plot/shear.py
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
plot_level2(*data, subset=None)
Plot Level 2 data with cleaned shear and despike iteration counts.
Parameters
*data : Any
ShearLevel2 required; ShearLevel1 optional (for overlay comparison).
Also accepts ShearProcessing, xr.Dataset, or xr.DataTree objects.
subset : list of tuple, optional
List of (variable, vmin, vmax) bounds for subsetting. If None, no
subsetting is applied.
Returns
tuple of (matplotlib.figure.Figure, ndarray of Axes) Figure with 2×nshear panels: cleaned vs raw shear overlay per sensor, and despike iteration count per sensor.
Source code in turban/utils/plot/shear.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
plot_level3(*data, subset=None)
Plot shear spectra and time series with optional model spectrum overlay.
Parameters
*data : Any
ShearLevel3 required; ShearLevel4 optional (for model spectrum overlay).
Also accepts ShearProcessing, xr.Dataset, or xr.DataTree objects.
subset : list of tuple, optional
List of (variable, vmin, vmax) bounds for subsetting. If None, no
subsetting is applied.
Returns
tuple of (matplotlib.figure.Figure, list of Axes) Figure with shear spectra panels (one per sensor) and time series panels for senspeed and auxiliary variables. Model Nasmyth spectra are overlaid if Level 4 data is provided.
Source code in turban/utils/plot/shear.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
plot_level4(*data, subset=None)
Plot turbulent dissipation rate time series and quality metrics.
Parameters
*data : Any
ShearLevel4 required. Also accepts ShearProcessing, xr.Dataset, or
xr.DataTree objects.
subset : list of tuple, optional
List of (variable, vmin, vmax) bounds for subsetting. If None, no
subsetting is applied.
Returns
tuple of (matplotlib.figure.Figure, list of Axes) Figure with eps time series panel and quality metric panels for each sensor.
Source code in turban/utils/plot/shear.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
Variables
Standard variable names (variables.py)
Defines standard names of variables used in the code base. Code should deviate from these names only with good reason.
Dictionary `VARIABLES`` is a nested structure of the form: {turban_standard_name: {attribute_name: attribute_value}}.
To make alphabetic sorting easier, this is here coded as the simpler dictionary _vars: