jdechalendar / gridemissions

Tools for power sector emissions tracking
MIT License
35 stars 6 forks source link

api.retrieve variable "elec" currently returns "co2" data #6

Closed eljpsm closed 2 years ago

eljpsm commented 2 years ago

Running the code: Screenshot from 2022-06-09 08-19-33 Results in: Screenshot from 2022-06-09 08-19-12

This also means that the "co2i" variable results in an AssertionError in src/gridemissions/eia_api.py column_name_to_ba at line 162.

jdechalendar commented 2 years ago

This was not a bug but the unintended result of a change to the API that this bit of code is making calls to. I changed the API very recently to reflect the refactoring changes I am making in #5 .

Apologies if this caused confusion and/or issues on your end. I will make merging #5 more of a priority. I want to propagate the changes I started there to the rest of the package, but this should not interfere with the api module, so it can wait. I'll close this issue when I merge #5 as the issue seems to be resolved there.

If you switch to branch jac-dev you should get the behavior below using a slightly modified version of your script to reflect the changes. The two changes below are to the variable parameter that I renamed to dataset (I have multiple datasets per variable, so this made more sense) and to the ba parameter that I renamed region. ba stood for balancing area, which I think is not as clear as "region".

I also just updated the API to be stricter in what it accepts - so executing your script should now return a 400 error.

from gridemissions import api

co2 = api.retrieve(dataset="co2", region="CISO", start="20190101", end="20200101", field="D")
elec = api.retrieve(dataset="elec", region="CISO", start="20190101", end="20200101", field="D")
print(co2)
print(elec)

co2i = api.retrieve(dataset="co2i", region="CISO", start="20190101", end="20200101", field="D")
print(co2i)
                             CO2_CISO_D
2019-01-01 00:00:00+00:00  5.578992e+06
2019-01-01 01:00:00+00:00  7.265524e+06
2019-01-01 02:00:00+00:00  7.655497e+06
2019-01-01 03:00:00+00:00  7.368712e+06
2019-01-01 04:00:00+00:00  7.200278e+06
...                                 ...
2019-12-31 20:00:00+00:00  4.126468e+06
2019-12-31 21:00:00+00:00  3.968577e+06
2019-12-31 22:00:00+00:00  4.067027e+06
2019-12-31 23:00:00+00:00  4.407957e+06
2020-01-01 00:00:00+00:00  5.216647e+06

[8761 rows x 1 columns]
                           EBA.CISO-ALL.D.H
2019-01-01 00:00:00+00:00      22537.708903
2019-01-01 01:00:00+00:00      25692.192549
2019-01-01 02:00:00+00:00      27369.421665
2019-01-01 03:00:00+00:00      27033.501617
2019-01-01 04:00:00+00:00      26422.278882
...                                     ...
2019-12-31 20:00:00+00:00      21965.866279
2019-12-31 21:00:00+00:00      22089.316440
2019-12-31 22:00:00+00:00      21622.904639
2019-12-31 23:00:00+00:00      21451.754324
2020-01-01 00:00:00+00:00      20438.049380

[8761 rows x 1 columns]
                           CO2i_CISO_D
2019-01-01 00:00:00+00:00   247.540335
2019-01-01 01:00:00+00:00   282.791111
2019-01-01 02:00:00+00:00   279.709857
2019-01-01 03:00:00+00:00   272.577030
2019-01-01 04:00:00+00:00   272.507839
...                                ...
2019-12-31 20:00:00+00:00   187.858187
2019-12-31 21:00:00+00:00   179.660493
2019-12-31 22:00:00+00:00   188.088854
2019-12-31 23:00:00+00:00   205.482367
2020-01-01 00:00:00+00:00   255.241913

[8761 rows x 1 columns]
eljpsm commented 2 years ago

No problem, I'll check out the jac-dev branch. Thanks!