prereise.gather package

Subpackages

Submodules

prereise.gather.const module

prereise.gather.helpers module

prereise.gather.helpers.get_monthly_net_generation(state, eia_form_923, resource, hps=True)[source]

Return monthly total net generation for a given resource and state from EIA form 923.

Parameters:
  • state (str) – state abbreviation.

  • eia_form_923 (pandas.DataFrame) – EIA form 923. The reduced form as returned by trim_eia_form_923() can be used.

  • resource (str) – type of generator.

  • hps (bool) – determine whether pumped hydro storage is included in the result if resource is ‘hydro’.

Returns:

(list) – monthly net generation of the query fuel type in state.

Raises:
  • TypeError – if eia_form_923 is not a data frame or resource is not a str.

  • ValueError – if state or resource is invalid.

prereise.gather.helpers.trim_eia_form_923(filename)[source]

Remove columns in EIA form 923 that are unnecessary to calculate the monthly generation per resource as performed by get_monthly_net_generation().

Parameters:

filename (str) – name of the reference file.

Returns:

(pandas.DataFrame) – EIA form 923 with only relevant columns.

prereise.gather.request_util module

class prereise.gather.request_util.RateLimit(interval=None)[source]

Bases: object

Provides a way to call an arbitrary function at most once per interval.

Parameters:

interval (int/float) – the amount of time in seconds to wait between actions

invoke(action)[source]

Call the action and return its value, waiting if necessary

Parameters:

action (callable) – the thing to do

Returns:

(Any) – the return value of the action

exception prereise.gather.request_util.TransientError[source]

Bases: Exception

Used for errors which can be retried

prereise.gather.request_util.rate_limit(_func=None, interval=None)[source]
prereise.gather.request_util.retry(_func=None, max_attempts=5, interval=None, raises=False, allowed_exceptions=<class 'urllib.error.HTTPError'>)[source]

Creates a decorator to handle retry logic.

Parameters:
  • max_attempts (int) – the max number of retries

  • interval (int/float) – minimum spacing between retries

  • raises (bool) – whether to re-raise the error after max_attempts is reached

  • allowed_exceptions (tuple) – exceptions for which the function will be retried, all others will be surfaced to the caller

Returns:

(Any) – the return value of the decorated function, or None if raises is False and all attempts failed

Module contents