cems_mod
NAME: cems_mod.py PGRMMER: Alice Crawford ORG: ARL This code written at the NOAA air resources laboratory Python 3
CEMS
Class for data from continuous emission monitoring systems (CEMS). Data from power plants can be downloaded from ftp://newftp.epa.gov/DMDNLoad/emissions/
Attributes:
| Name | Type | Description |
|---|---|---|
efile |
type string
|
Description of attribute |
Methods:
| Name | Description |
|---|---|
__init__ |
add_data(self, rdate, states=['md'], download=False, verbose=True): load(self, efile, verbose=True): retrieve(self, rdate, state, download=True): match_column(self, varname): get_var(self, varname, loc=None, daterange=None, unitid=-99, verbose=True): retrieve(self, rdate, state, download=True): create_location_dictionary(self): rename(self, ccc, newname, rcolumn, verbose): |
Source code in monetio/obs/cems_mod.py
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 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 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 | |
add_data(rdate, states=['md'], download=False, verbose=True)
gets the ftp url from the retrieve method and then loads the data from the ftp site using the load method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rdate
|
single datetime object of list of datetime objects
|
The first datetime object indicates the month and year of the first file to retrieve. The second datetime object indicates the month and year of the last file to retrieve. |
required |
states
|
list of strings
|
list of two letter state identifications. |
['md']
|
download
|
boolean
|
if download=True then retrieve will download the files and load will read the downloaded files. if download=False then retrieve will return the url and load will read directly from ftp site. |
False
|
verbose
|
boolean
|
if TRUE prints out additional information. |
True
|
Returns:
| Type | Description |
|---|---|
boolean True
|
|
Source code in monetio/obs/cems_mod.py
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 | |
add_info(dftemp)
-------------Load supplmental data----------------------- Add location (latitude longitude) and time UTC information to dataframe dftemp. cemsinfo.csv contains info on facility id, lat, lon, time offset from UTC. allows transformation from local time to UTC. If not all power stations are found in the cemsinfo.csv file, then Nan will be written in lat, lon and 'time' column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dftemp
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
dftemp |
pandas dataframe
|
|
Source code in monetio/obs/cems_mod.py
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 | |
cemspivot(varname, daterange=None, unitid=False, verbose=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
varname
|
name of column in the cems dataframe |
required | |
daterange
|
define a date range |
None
|
|
unitid
|
|
False
|
|
verbose
|
|
True
|
|
Returns
|
returns dataframe with rows time. Columns are (orispl_code, unit_id). If no unit_id in the file then columns are just orispl_code. if unitid flag set to False then sums over unit_id's that belong to an orispl_code. Values are from the column specified by the varname input. |
required |
Source code in monetio/obs/cems_mod.py
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 | |
columns_rename(columns, verbose=False)
Maps columns with one name to a standard name
Parameters:
columns: list of strings
Returns:
rcolumn: list of strings
Source code in monetio/obs/cems_mod.py
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 | |
create_location_dictionary(verbose=False)
returns dictionary with key orispl_code and value (latitude, longitude) tuple
Source code in monetio/obs/cems_mod.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
create_name_dictionary(verbose=False)
returns dictionary with key orispl_code and value facility name
Source code in monetio/obs/cems_mod.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
get_var(varname, orisp=None, daterange=None, unitid=-99, verbose=True)
returns time series with variable indicated by varname. returns data frame where rows are date and columns are the values of cmatch for each fac_id.
routine looks for column which contains all strings in varname. Currently not case sensitive.
loc and ORISPL CODES. unitid is a unit_id
if a particular unitid is specified then will return values for that unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
varname
|
string or iterable of strings
|
varname may be string or list of strings. |
required |
loc
|
type
|
Description of parameter |
required |
daterange
|
type
|
Description of parameter |
None
|
Returns:
| Type | Description |
|---|---|
type
|
Description of returned object. |
Source code in monetio/obs/cems_mod.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 | |
load(efile, verbose=True)
loads information found in efile into a pandas dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
efile
|
name of csv file to open or url of csv file. |
required | |
verbose
|
if TRUE prints out information |
True
|
Source code in monetio/obs/cems_mod.py
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 | |
match_column(varname)
varname is list of strings. returns column name which contains all the strings.
Source code in monetio/obs/cems_mod.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
rename(ccc, newname, rcolumn, verbose)
keeps track of original and new column names in the namehash attribute
Parameters:
ccc: str newname: str rcolumn: list of str verbose: boolean
Returns:
| Name | Type | Description |
|---|---|---|
rcolumn |
list of str
|
|
Source code in monetio/obs/cems_mod.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
retrieve(rdate, state, download=True, verbose=False)
Short summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rdate
|
datetime object
|
Uses year and month. Day and hour are not used. |
required |
state
|
string
|
state abbreviation to retrieve data for |
required |
download
|
boolean
|
set to True to download if download FALSE then returns string with url of ftp if download TRUE then returns name of downloaded file |
True
|
Returns:
| Type | Description |
|---|---|
efile string
|
if download FALSE then returns string with url of ftp if download TRUE then returns name of downloaded file |
Source code in monetio/obs/cems_mod.py
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 315 316 317 | |
get_date_fmt(date, verbose=False)
Determines what format of the date is in. In some files year is first and others it is last.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
with format either YYYY-mm-DD or mm-DD-YYYY |
required | |
verbose
|
if TRUE print extra information |
False
|
Rerturns
fmt: str string which can be used with datetime object to give format of date string.
Source code in monetio/obs/cems_mod.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 | |