adi
Attributes#
adi_qc_atts
module-attribute
#
adi_qc_atts = {
"bit_1_description": "QC_BAD: Transformation could not finish, value set to missing_value.",
"bit_1_assessment": "Bad",
"bit_2_description": "QC_INDETERMINATE: Some, or all, of the input values used to create this output value had a QC assessment of Indeterminate.",
"bit_2_assessment": "Indeterminate",
"bit_3_description": "QC_INTERPOLATE: Indicates a non-standard interpolation using points other than the two that bracket the target index was applied.",
"bit_3_assessment": "Indeterminate",
"bit_4_description": "QC_EXTRAPOLATE: Indicates extrapolation is performed out from two points on the same side of the target index.",
"bit_4_assessment": "Indeterminate",
"bit_5_description": "QC_NOT_USING_CLOSEST: Nearest good point is not the nearest actual point.",
"bit_5_assessment": "Indeterminate",
"bit_6_description": "QC_SOME_BAD_INPUTS: Some, but not all, of the inputs in the averaging window were flagged as bad and excluded from the transform.",
"bit_6_assessment": "Indeterminate",
"bit_7_description": "QC_ZERO_WEIGHT: The weights for all the input points to be averaged for this output bin were set to zero.",
"bit_7_assessment": "Indeterminate",
"bit_8_description": "QC_OUTSIDE_RANGE: No input samples exist in the transformation region, value set to missing_value.",
"bit_8_assessment": "Bad",
"bit_9_description": "QC_ALL_BAD_INPUTS: All the input values in the transformation region are bad, value set to missing_value.",
"bit_9_assessment": "Bad",
"bit_10_description": "QC_BAD_STD: Standard deviation over averaging interval is greater than limit set by transform parameter std_bad_max.",
"bit_10_assessment": "Bad",
"bit_11_description": "QC_INDETERMINATE_STD: Standard deviation over averaging interval is greater than limit set by transform parameter std_ind_max.",
"bit_11_assessment": "Indeterminate",
"bit_12_description": "QC_BAD_GOODFRAC: Fraction of good and indeterminate points over averaging interval are less than limit set by transform parameter goodfrac_bad_min.",
"bit_12_assessment": "Bad",
"bit_13_description": "QC_INDETERMINATE_GOODFRAC: Fraction of good and indeterminate points over averaging interval is less than limit set by transform parameter goodfrac_ind_min.",
"bit_13_assessment": "Indeterminate",
}
Classes#
AdiTransformer #
Functions#
transform #
transform(
variable_name: str,
input_dataset: xr.Dataset,
output_dataset: xr.Dataset,
transform_parameters: Dict[str, Any],
)
This function will use ADI libraries to transform one data variable to the shape defined for the output. This function will also fill out the output qc_ variable with the appropriate qc status from the transform algorithm.
The output variable and output qc_ variables' data will be written in place. Any variable attribute values that were added by adi will be copied back to the output variables.
Caller does not need to call this transform method for any 1-d variables where TRANS_PASSTHROUGH would apply. However, if there are two dimensions (say time and height), and the user only wants to transform one dimension (for example, time data is mapped to the input, but height data needs to be averaged), then you would need to call this transform and use TRANS_PASSTHROUGH for all the mapped dimension and a different transformation algorithm for any non-mapped dimensions.
If all dimensions are mapped and caller does not call this method, then all input values and input qc values must be copied over to the output by the caller. Also in this case the caller should add a 'source' attribute on the variable to explain what datastream the value came from.
Parameters#
variable_name: str The name of the variable being transformed. It should have the same name in both the input and output datasets. input_dataset : xarray.Dataset An xarray dataset containing: 1) A data variable to be transformed 2) Zero or one qc_variable that contains qc flags for the data variable. The qc_ variable must have the exact same base name as the data variable. For example, if the data variable is named 'temperature', then the qc variable must be named qc_temperature. The qc_variable must not have any qc attributes set. They will all be set by the transformer to specific bits that cannot be changed. 3) One or more coordinate variables matching the coordinates on the data variable 4) Zero or more bounds variables, one for each coordinate variable. Bounds variables specify the front edge and back edge of the bins used to compute the input data values. If no bounds variables are provided, ADI will assume each data point is a single, instantaneous value. If bounds variables are not present in the input data files, if the user knows what the bin widths and alignments were for the input datastreams, they can specify these values via the width and alignment transformation parameters (note that these parameters are for the input datastreams, not coordinate system defaults).
Bounds values must be the same units as their corresponding coordinate variable. Exact values should
be used instead of offsets.
* Note that if range transform parameters were set on any datastreams, the xarray data must have at least
'range' amount of extra data retrieved before and after the day being processed (if it exists).
* Note that the input variables should have been renamed to use the name from the output dataset. So
we should rename input variables to match their output names BEFORE we pass them to this method.
* Note that variable dimensions should have been renamed to match their names in the output variable.
xarray.Dataset
An xarray dataset where the transformed data will go. The output dataset must contain: 1) One or more coordinate variables with the shape of the defined output 2) One empty data variable with the same shape as its coordinate variables. The transformed values will be filled in by ADI. 3) One empty qc variable with the same shape as its coordinate variables. The qc flags and bit metadata attributes will be filled in by this function 4) One or more bounds variables, one for each coordinate variable. The bounds variables will contain the front edge and back edge of each bin for each output coord data point. The bounds variable values can computed from the coordinate data points and the width and alignment transformation parameters.
If the user does not specify bin width or alignment, then we use CENTER alignment by default and we
compute the bid width as the median of all the deltas between coordinate points.
transform_parameters : Dict
A compressed set of transformation parameters that apply just to the specific data variable being
transformed. The following is the minimal set used for our initial release (more ADI parameters can be
added later, as they will be supported by the back end).
transform_parameters = {
# Transformation_type defines the algorithm to use. This parameter should be defined by the converter.
# Valid values are:
# TRANS_AUTO (This will average if there are more input points than output points, otherwise, interpolate)
# TRANS_INTERPOLATE
# TRANS_SUBSAMPLE (i.e., nearest neighbor)
# TRANS_BIN_AVERAGE
# TRANS_PASSTHROUGH (all values passed directly through from the input, no transform takes place)
"transformation_type": {
"time": "TRANS_AUTO"
},
# Range specifies how far the transformer should look for the next good value when performing
# subsample or interpolate transforms.
# Range is always in same units as coord (e.g., seconds in this case).
# * Note that if range transform parameters are set for any datastreams, the xarray data must have at
# least 'range' amount of extra data retrieved before and after the day being processed (if it exists)!
"range": {
"time": 1800
},
# Width applies only when using bin averaging, and it specifies the width of the bin that was used to
# determine a specific point. Width is always in same units as coord.
# Only use width if user wants to make the bin width different than the delta between points (e.g., for
# smoothing data)
# NOTE: You do not have to set width if you provide bounds variables on the output dataset!
"width": {
"time": 600
}
# Alignment applies only when using bin averaging, and it specifies where in the bin the data point is
# located. Valid values are:
# LEFT
# CENTER
# RIGHT
# Default is CENTER
"alignment": {
"time": LEFT
}
}
Returns#
Void - transforms are done in-place on output_dataset#
Source code in tsdat/transform/adi.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 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 |
|
BadTransformationSettingsError #
Bases: ValueError
Exception class used when bad combinations of parameters are passed to transformation code.
TransformParameterConverter #
Attributes#
transform_param_type
class-attribute
instance-attribute
#
transform_param_type = {
"transformation_type": COORDINATE_SYSTEM,
"width": COORDINATE_SYSTEM,
"alignment": COORDINATE_SYSTEM,
"input_datastream_alignment": INPUT_DATASTREAM,
"input_datastream_width": INPUT_DATASTREAM,
"range": INPUT_DATASTREAM,
"qc_mask": INPUT_DATASTREAM,
"missing_value": INPUT_DATASTREAM,
"qc_bad": INPUT_DATASTREAM,
"std_ind_max": COORDINATE_SYSTEM,
"std_bad_max": COORDINATE_SYSTEM,
"goodfrac_ind_min": COORDINATE_SYSTEM,
"goodfrac_bad_min": COORDINATE_SYSTEM,
}