Skip to content

Commit f091bdf

Browse files
authored
Merge pull request #569 from cmu-delphi/chc-docs
Get CHC to pass pydocstyle
2 parents 5abec9b + 6fc6340 commit f091bdf

File tree

9 files changed

+37
-40
lines changed

9 files changed

+37
-40
lines changed

changehc/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ install: venv
1313

1414
lint:
1515
. env/bin/activate; \
16-
pylint $(dir)
16+
pylint $(dir); \
17+
pydocstyle $(dir)
1718

1819
test:
1920
. env/bin/activate ;\

changehc/delphi_changehc/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010

1111
class Config:
12-
"""Static configuration variables.
13-
"""
12+
"""Static configuration variables."""
1413

1514
## dates
1615
FIRST_DATA_DATE = datetime(2020, 1, 1)
@@ -59,9 +58,11 @@ class Config:
5958

6059
class Constants:
6160
"""
62-
Contains the maximum number of geo units for each geo type
61+
Contains the maximum number of geo units for each geo type.
62+
6363
Used for sanity checks
6464
"""
65+
6566
# number of counties in usa, including megacounties
6667
NUM_COUNTIES = 3141 + 52
6768
NUM_HRRS = 308

changehc/delphi_changehc/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Registry for signal names and geo types"""
1+
"""Registry for signal names and geo types."""
22
SMOOTHED = "smoothed_outpatient_covid"
33
SMOOTHED_ADJ = "smoothed_adj_outpatient_covid"
44
SMOOTHED_CLI = "smoothed_outpatient_cli"

changehc/delphi_changehc/download_ftp_files.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Downloads files modified in the last 24 hours from the specified ftp server."""
1+
"""Download files modified in the last 24 hours from the specified ftp server."""
32

43
# standard
54
import datetime
@@ -11,19 +10,19 @@
1110

1211

1312
def print_callback(filename, bytes_so_far, bytes_total):
14-
"""Log file transfer progress"""
13+
"""Log file transfer progress."""
1514
rough_percent_transferred = int(100 * (bytes_so_far / bytes_total))
1615
if (rough_percent_transferred % 25) == 0:
1716
print(f'{filename} transfer: {rough_percent_transferred}%')
1817

1918

2019
def get_files_from_dir(sftp, out_path):
21-
"""Download files from sftp server that have been uploaded in last day
20+
"""Download files from sftp server that have been uploaded in last day.
21+
2222
Args:
2323
sftp: SFTP Session from Paramiko client
2424
out_path: Path to local directory into which to download the files
2525
"""
26-
2726
current_time = datetime.datetime.now()
2827

2928
# go through files in recieving dir
@@ -45,12 +44,12 @@ def get_files_from_dir(sftp, out_path):
4544

4645

4746
def download_covid(out_path, ftp_conn):
48-
"""Downloads files necessary to create chng-covid signal from ftp server.
47+
"""Download files necessary to create chng-covid signal from ftp server.
48+
4949
Args:
5050
out_path: Path to local directory into which to download the files
5151
ftp_conn: Dict containing login credentials to ftp server
5252
"""
53-
5453
# open client
5554
try:
5655
client = paramiko.SSHClient()
@@ -74,12 +73,12 @@ def download_covid(out_path, ftp_conn):
7473

7574

7675
def download_cli(out_path, ftp_conn):
77-
"""Downloads files necessary to create chng-cli signal from ftp server.
76+
"""Download files necessary to create chng-cli signal from ftp server.
77+
7878
Args:
7979
out_path: Path to local directory into which to download the files
8080
ftp_conn: Dict containing login credentials to ftp server
8181
"""
82-
8382
# open client
8483
try:
8584
client = paramiko.SSHClient()

changehc/delphi_changehc/load_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def load_chng_data(filepath, dropdate, base_geo,
2727
Returns:
2828
cleaned dataframe
2929
"""
30-
3130
assert base_geo == "fips", "base unit must be 'fips'"
3231
count_flag = False
3332
date_flag = False

changehc/delphi_changehc/run.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from .update_sensor import CHCSensorUpdator
2020

2121
def retrieve_files(params, filedate):
22-
"""Return filenames of relevant files, downloading them if necessary
23-
"""
22+
"""Return filenames of relevant files, downloading them if necessary."""
2423
files = params["input_files"]
2524
if files["denom"] is None:
2625

@@ -57,8 +56,7 @@ def retrieve_files(params, filedate):
5756

5857

5958
def make_asserts(params):
60-
"""Assert that for each type, filenames are either all present or all absent
61-
"""
59+
"""Assert that for each type, filenames are either all present or all absent."""
6260
files = params["input_files"]
6361
if "covid" in params["types"]:
6462
assert (files["denom"] is None) == (files["covid"] is None), \
@@ -79,9 +77,7 @@ def make_asserts(params):
7977

8078

8179
def run_module():
82-
"""Run the delphi_changehc module.
83-
"""
84-
80+
"""Run the delphi_changehc module."""
8581
params = read_params()
8682

8783
logging.basicConfig(level=logging.DEBUG)

changehc/delphi_changehc/sensor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020

2121

2222
class CHCSensor:
23-
"""Sensor class to fit a signal using Covid counts from Change HC outpatient data.
24-
"""
23+
"""Sensor class to fit a signal using Covid counts from Change HC outpatient data."""
24+
2525
smoother = Smoother("savgol",
2626
poly_fit_degree=1,
2727
gaussian_bandwidth=Config.SMOOTHER_BANDWIDTH)
2828

2929
@staticmethod
3030
def gauss_smooth(count,total):
31-
"""smooth using the left_gauss_linear
31+
"""Smooth using the left_gauss_linear.
3232
3333
Args:
3434
count, total: array
35-
"""
35+
"""
3636
count_smooth = CHCSensor.smoother.smooth(count)
3737
total_smooth = CHCSensor.smoother.smooth(total)
3838
total_clip = np.clip(total_smooth, 0, None)
@@ -46,12 +46,12 @@ def backfill(
4646
k=Config.MAX_BACKFILL_WINDOW,
4747
min_visits_to_fill=Config.MIN_CUM_VISITS):
4848
"""
49-
Adjust for backfill (retroactively added observations) by using a
50-
variable length smoother, which starts from the RHS and moves
51-
leftwards (backwards through time). We cumulatively sum the total
52-
visits (denominator), until we have observed some minimum number of
53-
counts, then calculate the sum over that bin. We restrict the
54-
bin size so to avoid inluding long-past values.
49+
Adjust for retroactively added observations (backfill) by using a variable length smoother.
50+
51+
The smoother starts from the RHS and moves leftwards (backwards through time).
52+
We cumulatively sum the total visits (denominator), until we have observed some minimum number of
53+
counts, then calculate the sum over that bin. We restrict the
54+
bin size so to avoid including long-past values.
5555
5656
Args:
5757
num: array of covid counts

changehc/delphi_changehc/update_sensor.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
Generate CHC sensors.
3+
34
Author: Aaron Rumack
45
Created: 2020-10-14
56
"""
@@ -21,6 +22,7 @@
2122

2223
def write_to_csv(output_dict, write_se, out_name, output_path="."):
2324
"""Write sensor values to csv.
25+
2426
Args:
2527
output_dict: dictionary containing sensor rates, se, unique dates, and unique geo_id
2628
write_se: boolean to write out standard errors, if true, use an obfuscated name
@@ -72,8 +74,7 @@ def write_to_csv(output_dict, write_se, out_name, output_path="."):
7274

7375

7476
class CHCSensorUpdator: # pylint: disable=too-many-instance-attributes
75-
"""Contains methods to update sensor and write results to csv
76-
"""
77+
"""Contains methods to update sensor and write results to csv."""
7778

7879
def __init__(self,
7980
startdate,
@@ -84,7 +85,8 @@ def __init__(self,
8485
weekday,
8586
numtype,
8687
se):
87-
"""Init Sensor Updator
88+
"""Init Sensor Updator.
89+
8890
Args:
8991
startdate: first sensor date (YYYY-mm-dd)
9092
enddate: last sensor date (YYYY-mm-dd)
@@ -123,8 +125,7 @@ def __init__(self,
123125
self.sensor_dates = None
124126

125127
def shift_dates(self):
126-
"""shift estimates forward to account for time lag, compute burnindates, sensordates
127-
"""
128+
"""Shift estimates forward to account for time lag, compute burnindates, sensordates."""
128129
drange = lambda s, e: pd.date_range(start=s,periods=(e-s).days,freq='D')
129130
self.startdate = self.startdate - Config.DAY_SHIFT
130131
self.burnindate = self.startdate - Config.BURN_IN_PERIOD
@@ -134,7 +135,8 @@ def shift_dates(self):
134135
return True
135136

136137
def geo_reindex(self, data):
137-
"""Reindex based on geography, include all date, geo pairs
138+
"""Reindex based on geography, include all date, geo pairs.
139+
138140
Args:
139141
data: dataframe, the output of loadcombineddata
140142
Returns:
@@ -178,6 +180,7 @@ def update_sensor(self,
178180
data,
179181
outpath):
180182
"""Generate sensor values, and write to csv format.
183+
181184
Args:
182185
data: pd.DataFrame with columns num and den
183186
outpath: output path for the csv results

changehc/delphi_changehc/weekday.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def get_params(data):
5555
Return a matrix of parameters: the entire vector of betas, for each time
5656
series column in the data.
5757
"""
58-
5958
tmp = data.reset_index()
6059
denoms = tmp.groupby(Config.DATE_COL).sum()["den"]
6160
nums = tmp.groupby(Config.DATE_COL).sum()["num"]
@@ -113,7 +112,6 @@ def calc_adjustment(params, sub_data):
113112
-- this has the same effect.
114113
115114
"""
116-
117115
tmp = sub_data.reset_index()
118116

119117
wd_correction = np.zeros((len(tmp["num"])))

0 commit comments

Comments
 (0)