Package: pyleiades
pyleiadesPython Library for EIA Data Examination & ExhibitionA tool for creating visuals from historical energy data (e.g. the EIA monthly energy review).This tool is designed to provide insightful, aesthetic and more flexible visualizations of the Energy Information Administration (EIA) monthly energy review datasets.
The datasets contain information about the sources of energy Americans have relied on for power since the middle of the 20th century.
The datasets begin in 1949 with annual energy production, consumption, import, and export values, and extend up until the present.
Monthly energy datapoints are reported starting in 1973.The basic energy sources are reported in the following groups:Fossil FuelsCoalNatural GasPetroleumRenewablesWindSolarHydroelectricGeothermalBiomassNuclearFissionThe data is published monthly on theEIA's website, and as of March 31st, 2019 records were provided up through December 2018. This package also includes data up to date through the end of 2018, though more recent data can be downloaded using an included script.All reported values are in units of quadrillion british thermal units (1.0E15 BTU). Be aware that the datasets may providemore precisionthan is published in the PDF reports.Installationpyleiadesis hosted through the Python Package Index (PyPI) and can be easily installed using pip.
From the command line, run$ pip install pyleiadesThe module requires a recent version of Python 3 (3.6 or greater), pandas, and matplotlib, among others.
If you run into trouble running the package, try using the Anaconda environment provided in this repo.
Install the environment using the command$ conda env create -f environment.ymland activate the environment by issuing the command$ conda activate pyleiadesUpdatingAn archive of EIA Monthly Energy Review datasets is kept in thepyleiadesdata repository.
This may not include the most up to date information, and so the package comes with a script to update the available data.
Once the package is installed, run$ update_eia_data.pyfrom the command line to download the most recent data from the EIA website.Using the APIThe API is built around two main object types—theEnergyandVisualclasses.TheEnergyobjectTo access the EIA data directly for a certain energy type, use theEnergyclass.
For example, the energy consumption data for all renewable energy sources can be accessed with:>>> from pyleiades import Energy
>>> renewables = Energy('renewable')The resultingrenewablesobject stores the complete consumption history within theenergy_datadataframe attribute.>>> renewables.energy_data
     date_code      value
6220    194913   2.973984
6221    195013   2.977718
6222    195113   2.958464
6223    195213   2.940181
...Thedate_codecolumn gives the reporting date (in the formatYYYYMM, where the month code 13 indicates a yearly total) and thevaluecolumn gives the consumption amounts (in QBTU) for each date.
In the example above, the first four entries of theenergy_datadataframe are the renewable energy yearly consumption totals for 1949 through 1952.Energy consumption values are the default, however theEnergyobjects can also be used to access production, import and export statistics.
The type of statistic can be selected using thestat_typekeyword argument.>>> renewables = Energy('renewable', stat_type='production')
>>> renewables.energy_data
     date_code     value
6220    194913  1.549262
6221    195013  1.562307
6222    195113  1.534669
6223    195213  1.474369Perhaps more interesting than the complete history, however, are more sophisticated features of the data, like interval specific totals and extremes.Using thetotalsmethod of anEnergyobject allows the data to be totaled at a specified interval—either monthly, yearly, or cumulatively.>>> renewables.totals('monthly')
           value
  date
197301  0.403981
197302  0.360900
197303  0.400161
197304  0.380470Notice that here the monthly data only goes back as far as 1973 (though theenergy_dataattribute showed yearly data for renewable energy dating back to 1949).
By default, thetotalsmethod selects the entire range of available data.
This  behavior can be overriden by providing start and end dates for some interval as keyword arguments.
To only get monthly renewable energy data from 2000 to 2010, this would be:>>> renewables.totals(freq='monthly', start_date='200001', end_date='200912')
           value
  date
200001  0.505523
200002  0.498993
200003  0.558474
200004  0.567147To get extremes over a dataset interval, use themaximaorminimamethods.TheVisualobjectAVisualallows the package to create plots of several energy types.
The initialization parameters for aVisualare similar to those for anEnergyobject.
AVisualcan accept a single energy type or a list of energy types, optionally followed by a type of statistic (consumption by default).visual = Visual(['coal', 'nuclear', 'renewable'])This visual object's methods can then be used to generate any of a variety of visuals.
The syntax is again similar to that of theEnergyobject, however it includes a subject argument corresponding to a method of theEnergyobject.
Here's an example that generates a line graph of energy totals:visual.linegraph(subject='totals', freq='monthly', start_date='1970')Run the very simple installed scriptpyleiades-demo.pyto see the package in action.