mibiscreen.data API reference
mibiscreen module for data handling.
check_data
Functions for data handling and standardization.
@author: Alraune Zech
check_columns(data_frame, standardize=False, reduce=False, verbose=True)
Function checking names of columns of data frame.
Function that looks at the column names and links it to standard names. Optionally, it renames identified column names to the standard names of the model.
data_frame: pd.DataFrame
dataframe with the measurements
standardize: Boolean, default False
Whether to standardize identified column names
reduce: Boolean, default False
Whether to reduce data to known quantities
verbose: Boolean, default True
verbosity flag
tuple: three list containing names of
list with identitied quantities in data (but not standardized names)
list with unknown quantities in data (not in list of standardized names)
list with standard names of identified quantities
Raises:
None (yet).
Example:
Todo’s: - complete list of potential contaminants, environmental factors - add name check for metabolites?
Source code in mibiscreen/data/check_data.py
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 | |
check_data_frame(data_frame, sample_name_to_index=False, inplace=False)
Checking data on correct format.
Tests if provided data is a pandas data frame and provides column names. Optionally it sets the sample name as index.
Input
data_frame: pd.DataFrame
quantities for data analysis given per sample
sample_name_to_index: Boolean, default False
Whether to set the sample name to the index of the DataFrame
inplace: Boolean, default False
Whether to modify the DataFrame rather than creating a new one.
Output
data: pd.DataFrame
copy of given dataframe with index set to sample name
cols: list
List of column names
Source code in mibiscreen/data/check_data.py
check_units(data, verbose=True)
Function to check the units of the measurements.
data: pandas.DataFrames
dataframe with the measurements where first row contains
the units or a dataframe with only the column names and units
verbose: Boolean
verbose statement (default True)
col_check_list: list
quantities whose units need checking/correction
col_not_checked: list
quantities not identified, thus not checked on units
None (yet).
Example:
To be added.
Source code in mibiscreen/data/check_data.py
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 | |
check_values(data_frame, dl_factor=None, to_replace_list=['-', '--', '', ' ', ' ', np.inf, -np.inf], to_replace_value=np.nan, inplace=False, verbose=True)
Function that checks on values and cleans DataFrame.
Cleaning includes
- fixing decimal commas
- converting strings to floats
- replacing empty strings with NaN
- replacing ‘inf’ (infinity) with NaN
- and optionally replacing detection limits.
data_frame: pandas.DataFrames
dataframe with the measurements
dl_factor: float or None, default None
if set, values with '<' are replaced by (value * dl_factor)
to_replace_list: list, default ["-",'--','',' ',' ']
list of strings to replace before cleaning
to_replace_value: float or np.nan, default: np.nan
value to replace strings to_replace_list with
inplace: Boolean, default False
if True modifies df in place, else returns a cleaned copy
verbose: Boolean
verbose statement (default True)
cleaned: pandas.DataFrame
Cleaned dataframe without units
Source code in mibiscreen/data/check_data.py
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 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
standard_names(name_list, standardize=True, reduce=False, verbose=False)
Function transforming list of names to standard names.
Function that looks at the names (of e.g. environmental variables, contaminants, metabolites, isotopes, etc) and provides the corresponding standard names.
name_list: string or list of strings
names of quantities to be transformed to standard
standardize: Boolean, default False
Whether to standardize identified column names
reduce: Boolean, default False
Whether to reduce data to known quantities
verbose: Boolean, default True
verbosity flag
tuple: three lists containing names of
list with identitied quantities in data (but not standardized names)
list with unknown quantities in data (not in list of standardized names)
list with standard names of identified quantities
+ one dictionary mapping identified quantities to their
standard values for fast name transformation
Raises:
None (yet).
Example:
Todo’s: - complete list of potential contaminants, environmental factors - add name check for metabolites?
Source code in mibiscreen/data/check_data.py
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 | |
standardize(data_frame, reduce=True, store_csv=False, verbose=True, **kwargs)
Function providing condensed data frame with standardized names.
Function is checking names of columns and renames columns, condenses data to identified column names, checks units and names sof data frame.
Function that looks at the column names and renames the columns to the standard names of the model.
data_frame: pandas.DataFrames
dataframe with the measurements
reduce: Boolean, default True
whether to reduce data to known quantities (default True),
otherwise full dataframe with renamed columns (for those identifyable) is returned
store_csv: Boolean, default False
whether to save dataframe in standard format to csv-file
verbose: Boolean, default True
verbose statement
**kwargs: Optional keyword arguments.
dl_factor (float, optional): scaling factor for value given at detection limit.
Default is None, so detection limit values are replaced by nan.
data_numeric, units: pandas.DataFrames
Tabular data with standardized column names, values in numerics etc
and table with units for standardized column names
Source code in mibiscreen/data/check_data.py
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 | |
example_data
mibiscreen module for example data.
example_data
Example data.
Measurements on quantities and parameters in groundwater samples used for biodegredation and bioremediation analysis.
@author: Alraune Zech
example_data(data_type='all', with_units=False)
Function provinging test data for mibiscreen data analysis.
data_type: string
Type of data to return:
-- "all": all types of data available
-- "set_env_cont": well setting, environmental and contaminants data
-- "setting": well setting data only
-- "environment": data on environmental
-- "contaminants": data on contaminants
-- "metabolites": data on metabolites
-- "isotopes": data on isotopes
-- "hydro": data on hydrogeolocial conditions
with_units: Boolean, default False
flag to provide first row with units
if False (no units), values in columns will be numerical
if True (with units), values in columns will be objects
pandas.DataFrame: Tabular data with standard column names
None
Example:
To be added!
Source code in mibiscreen/data/example_data/example_data.py
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 | |
load_data
Functions for data I/O handling.
@author: Alraune Zech
load_csv(file_path=None, verbose=False, store_provenance=False)
Function to load data from csv file.
file_path: str
Name of the path to the file
verbose: Boolean
verbose flag
store_provenance: Boolean
To add!
data: pd.DataFrame
Tabular data
units: pd.DataFrame
Tabular data on units
ValueError: If `file_path` is not a valid file location
Example:
This function can be called with the file path of the example data as argument using:
>>> from mibiscreen.data import load_excel
>>> load_excel(example_data.csv)
Source code in mibiscreen/data/load_data.py
load_excel(file_path=None, sheet_name=0, verbose=False, store_provenance=False, **kwargs)
Function to load data from excel file.
file_path: str
Name of the path to the file
sheet_name: int
Number of the sheet in the excel file to load
verbose: Boolean
verbose flag
store_provenance: Boolean
To add!
**kwargs: optional keyword arguments to pass to pandas' routine
read_excel(), e.g. sep = ',' or sep = ';'
data: pd.DataFrame
Tabular data
units: pd.DataFrame
Tabular data on units
ValueError: If `file_path` is not a valid file location
Example:
This function can be called with the file path of the example data as argument using:
>>> from mibiscreen.data import load_excel
>>> load_excel(example_data.xlsx)
Source code in mibiscreen/data/load_data.py
set_data
Functions for data extraction and merging in preparation of analysis and plotting.
@author: Alraune Zech
compare_lists(list1, list2, verbose=False)
Checking overlap of two given list.
Input
list1: list of strings
given extensive list (usually column names of a pd.DataFrame)
list2: list of strings
list of names to extract/check overlap with strings in list 'column'
verbose: Boolean, default True
verbosity flag
Output
(intersection, remainder_list1, reminder_list2): tuple of lists
* intersection: list of strings present in both lists 'list1' and 'list2'
* remainder_list1: list of strings only present in 'list1'
* remainder_list2: list of strings only present in 'list2'
Example:
list1 = [‘test1’,’test2’] list2 = [‘test1’,’test3’]
([‘test1’],[‘test2’]['test3']) = compare_lists(list1,list2)
Source code in mibiscreen/data/set_data.py
determine_quantities(cols, name_list='all', verbose=False)
Select a subset of column names (from DataFrame).
Input
cols: list
Names of quantities (column names) from pd.DataFrame
name_list: str or list of str, default is 'all'
quantities to extract from column names.
If a list of strings is provided, these will be selected from the list of column names (col)
If a string is provided, this is a short name for a specific group of quantities:
- 'all' (all quantities given in data frame except settings)
- short name for group of contaminants:
- 'BTEX' (for benzene, toluene, ethylbenzene, xylene)
- 'BTEXIIN' (for benzene, toluene, ethylbenzene, xylene,
indene, indane and naphthaline)
- 'all_cont' (for all contaminant in name list)
- short name for group of environmental parameters/geochemicals:
- 'environmental_conditions'
- 'geochemicals'
- 'ONS': non reduced electron acceptors (oxygen, nitrate, sulfate)
- 'ONSFe': selected electron acceptors (oxygen, nitrate, sulfate + iron II)
- 'all_ea': all potential electron acceptors (non reduced & reduced)
- 'NP': nutrients (nitrate, nitrite, phosphate)
See also file mibiscreen/data/name_data for lists of quantities
verbose: Boolean
verbose flag (default False)
Output
quantities: list
list of strings with names of selected quantities present in dataframe
remainder: list
list of strings with names of selected quantities not present in dataframe
Source code in mibiscreen/data/set_data.py
extract_data(data_frame, name_list, keep_setting_data=True, verbose=False)
Extracting data of specified variables from dataframe.
data_frame: pandas.DataFrames
dataframe with the measurements
name_list: list of strings
list of column names to extract from dataframe
keep_setting_data: bool, default True
Whether to keep setting data in the DataFrame.
verbose: Boolean
verbose flag (default False)
data: pd.DataFrame
dataframe with the measurements
Raises:
None (yet).
Example:
To be added.
Source code in mibiscreen/data/set_data.py
extract_settings(data_frame, verbose=False)
Extracting data of specified variables from dataframe.
data_frame: pandas.DataFrames
dataframe with the measurements
verbose: Boolean
verbose flag (default False)
data: pd.DataFrame
dataframe with settings
Raises:
None (yet).
Example:
To be added.
Source code in mibiscreen/data/set_data.py
merge_data(data_frames_list, how='outer', on=[names.name_sample], clean=True, **kwargs)
Merging dataframes along columns on similar sample name.
data_frames_list: list of pd.DataFrame
list of dataframes with the measurements
how: str, default 'outer'
Type of merge to be performed.
corresponds to keyword in pd.merge()
{‘left’, ‘right’, ‘outer’, ‘inner’, ‘cross’}, default ‘outer’
on: list, default "sample_nr"
Column name(s) to join on.
corresponds to keyword in pd.merge()
clean: Boolean, default True
Whether to drop columns which are in all provided data_frames
(on which not to merge, potentially other settings than sample_name)
**kwargs: dict
optional keyword arguments to be passed to pd.merge()
data: pd.DataFrame
dataframe with the measurements
Raises:
None (yet).
Example:
To be added.
Source code in mibiscreen/data/set_data.py
settings
mibiscreen module for settings of data.
contaminants
Specifications of petroleum hydrocarbon related contaminants.
List of (PAH) contamiants measured in groundwater samples useful for biodegredation and bioremediation analysis
@author: A. Zech
environment
Specifications of geochemicals.
List of geochemicals measured in groundwater samples useful for biodegredation and bioremediation analysis
@author: A. Zech
isotopes
Specifications of isotopes.
List of basic isotopes measured in groundwater samples useful for biodegredation and bioremediation analysis
@author: A. Zech
metabolites
Specifications of metabolies.
List of basic metabolites measured in groundwater samples useful for biodegredation and bioremediation analysis
@author: A. Zech
sample_settings
Specifications of sample settings.
List of all quantities and parameters characterizing sample specifics for measurements in groundwater samples useful for biodegredation and bioremediation analysis
@author: A. Zech
standard_names
Name specifications of data!
Listed are all standard names of quantities and parameters measured in groundwater samples useful for biodegredation and bioremediation analysis
@author: A. Zech
unit_settings
Unit specifications of data!
File containing unit specifications of quantities and parameters measured in groundwater samples useful for biodegredation and bioremediation analysis.
@author: Alraune Zech