Breakthrough-Energy / PreREISE

Generate input data for scenario framework
https://breakthrough-energy.github.io/docs/
MIT License
21 stars 28 forks source link

feat: add function to calculate VMT share for each day of the year #298

Closed danielolsen closed 2 years ago

danielolsen commented 2 years ago

Purpose

Add a function to calculate VMT share for each day of the year.

What the code is doing

Two data files are added, moves_daily.csv and moves_monthly.csv, which contain exactly the data as it's presented in the report on MOVES. The 2010 version of the report is used in the Attribution file since it contains the monthly distributions for both regular years and leap years.

A helper function is added which takes a year and an area type (either "urban" or "rural") and returns a pandas Series where the index is each day of the year and the values are the fraction of VMT that are estimated to occur in that day.

Testing

Tested manually for leap years and regular years, and for urban vs. rural. Values are spot checked against the previous values, which are relevant for a regular year that begins on a Sunday, and values for other combinations are checked to ensure that the year sums to one (subject to floating point precision).

Usage Example/Visuals

>>> from prereise.gather.demanddata.transportation_electrification.data_helper import generate_daily_weighting
>>> generate_daily_weighting(2017)
2017-01-01    0.001964
2017-01-02    0.002520
2017-01-03    0.002520
2017-01-04    0.002520
2017-01-05    0.002520
                ...
2017-12-27    0.002786
2017-12-28    0.002786
2017-12-29    0.002786
2017-12-30    0.002171
2017-12-31    0.002171
Freq: D, Length: 365, dtype: float64
>>> generate_daily_weighting(2017).sum()
0.9999999999999999
>>> generate_daily_weighting(2020)
2020-01-01    0.002494
2020-01-02    0.002494
2020-01-03    0.002494
2020-01-04    0.001943
2020-01-05    0.001943
                ...
2020-12-27    0.002132
2020-12-28    0.002737
2020-12-29    0.002737
2020-12-30    0.002737
2020-12-31    0.002737
Freq: D, Length: 366, dtype: float64
>>> generate_daily_weighting(2020).sum()
1.0
>>> generate_daily_weighting(2017, "rural")
2017-01-01    0.002302
2017-01-02    0.002381
2017-01-03    0.002381
2017-01-04    0.002381
2017-01-05    0.002381
                ...
2017-12-27    0.002616
2017-12-28    0.002616
2017-12-29    0.002616
2017-12-30    0.002528
2017-12-31    0.002528
Freq: D, Length: 365, dtype: float64
>>> generate_daily_weighting(2017, "rural").sum()
0.9999999999999999
>>> generate_daily_weighting(2017, "suburban")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\DanielOlsen\repos\bes\PreREISE\prereise\gather\demanddata\transportation_electrification\data_helper.py", line 107, in generate_daily_weighting
    raise ValueError(f"area_type must be one of {allowable_area_types}")
ValueError: area_type must be one of {'rural', 'urban'}

Time estimate

15 minutes.