1
1
# -*- coding: utf-8 -*-
2
2
"""Functions to call when running the function.
3
+
3
4
This module should contain a function called `run_module`, that is executed when
4
5
the module is run with `python -m delphi_combo_cases_and_deaths`.
5
6
This module produces a combined signal for jhu-csse and usa-facts. This signal
@@ -26,6 +27,8 @@ def check_none_data_frame(data_frame, label, date_range):
26
27
27
28
def maybe_append (df1 , df2 ):
28
29
"""
30
+ Append dataframes if available, otherwise return non-None one.
31
+
29
32
If both data frames are available, append them and return. Otherwise, return
30
33
whichever frame is not None.
31
34
"""
@@ -41,9 +44,7 @@ def maybe_append(df1, df2):
41
44
"stderr" : "se" ,
42
45
"sample_size" : "sample_size" }
43
46
def combine_usafacts_and_jhu (signal , geo , date_range , fetcher = covidcast .signal ):
44
- """
45
- Add rows for PR from JHU signals to USA-FACTS signals
46
- """
47
+ """Add rows for PR from JHU signals to USA-FACTS signals."""
47
48
print ("Fetching usa-facts..." )
48
49
usafacts_df = fetcher ("usa-facts" , signal , date_range [0 ], date_range [1 ], geo )
49
50
print ("Fetching jhu-csse..." )
@@ -74,7 +75,9 @@ def combine_usafacts_and_jhu(signal, geo, date_range, fetcher=covidcast.signal):
74
75
return combined_df
75
76
76
77
def extend_raw_date_range (params , sensor_name ):
77
- """A complete issue includes smoothed signals as well as all raw data
78
+ """Extend the date range of the raw data backwards by 7 days.
79
+
80
+ A complete issue includes smoothed signals as well as all raw data
78
81
that contributed to the smoothed values, so that it's possible to use
79
82
the raw values in the API to reconstruct the smoothed signal at will.
80
83
The smoother we're currently using incorporates the previous 7
@@ -99,17 +102,15 @@ def next_missing_day(source, signals):
99
102
return day
100
103
101
104
def sensor_signal (metric , sensor , smoother ):
102
- """Generate the signal name for a particular configuration"""
105
+ """Generate the signal name for a particular configuration. """
103
106
if smoother == "7dav" :
104
107
sensor_name = "_" .join ([smoother , sensor ])
105
108
else :
106
109
sensor_name = sensor
107
110
return sensor_name , "_" .join ([metric , sensor_name ])
108
111
109
112
def configure (variants ):
110
- """
111
- Validate params file and set date range.
112
- """
113
+ """Validate params file and set date range."""
113
114
params = read_params ()
114
115
params ['export_start_date' ] = date (* params ['export_start_date' ])
115
116
yesterday = date .today () - timedelta (days = 1 )
@@ -153,7 +154,7 @@ def configure(variants):
153
154
154
155
155
156
def run_module ():
156
- """Produce a combined cases and deaths signal using data from JHU and USA Facts"""
157
+ """Produce a combined cases and deaths signal using data from JHU and USA Facts. """
157
158
variants = [tuple ((metric , geo_res )+ sensor_signal (metric , sensor , smoother ))
158
159
for (metric , geo_res , sensor , smoother ) in
159
160
product (METRICS , GEO_RESOLUTIONS , SENSORS , SMOOTH_TYPES )]
0 commit comments