Skip to content

Get CHC to pass pydocstyle #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changehc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ install: venv

lint:
. env/bin/activate; \
pylint $(dir)
pylint $(dir); \
pydocstyle $(dir)

test:
. env/bin/activate ;\
Expand Down
7 changes: 4 additions & 3 deletions changehc/delphi_changehc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@


class Config:
"""Static configuration variables.
"""
"""Static configuration variables."""

## dates
FIRST_DATA_DATE = datetime(2020, 1, 1)
Expand Down Expand Up @@ -45,9 +44,11 @@ class Config:

class Constants:
"""
Contains the maximum number of geo units for each geo type
Contains the maximum number of geo units for each geo type.

Used for sanity checks
"""

# number of counties in usa, including megacounties
NUM_COUNTIES = 3141 + 52
NUM_HRRS = 308
Expand Down
2 changes: 1 addition & 1 deletion changehc/delphi_changehc/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Registry for signal names and geo types"""
"""Registry for signal names and geo types."""
SMOOTHED = "smoothed_outpatient_covid"
SMOOTHED_ADJ = "smoothed_adj_outpatient_covid"
SIGNALS = [SMOOTHED, SMOOTHED_ADJ]
Expand Down
13 changes: 6 additions & 7 deletions changehc/delphi_changehc/download_ftp_files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Downloads files modified in the last 24 hours from the specified ftp server."""
"""Download files modified in the last 24 hours from the specified ftp server."""

# standard
import datetime
Expand All @@ -11,19 +10,19 @@


def print_callback(filename, bytes_so_far, bytes_total):
"""Log file transfer progress"""
"""Log file transfer progress."""
rough_percent_transferred = int(100 * (bytes_so_far / bytes_total))
if (rough_percent_transferred % 25) == 0:
print(f'{filename} transfer: {rough_percent_transferred}%')


def get_files_from_dir(sftp, out_path):
"""Download files from sftp server that have been uploaded in last day
"""Download files from sftp server that have been uploaded in last day.

Args:
sftp: SFTP Session from Paramiko client
out_path: Path to local directory into which to download the files
"""

current_time = datetime.datetime.now()

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


def download(out_path, ftp_conn):
"""Downloads files necessary to create CHC signal from ftp server.
"""Download files necessary to create CHC signal from ftp server.

Args:
out_path: Path to local directory into which to download the files
ftp_conn: Dict containing login credentials to ftp server
"""

# open client
try:
client = paramiko.SSHClient()
Expand Down
4 changes: 1 addition & 3 deletions changehc/delphi_changehc/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@


def run_module():
"""Run the delphi_changehc module.
"""

"""Run the delphi_changehc module."""
params = read_params()

logging.basicConfig(level=logging.DEBUG)
Expand Down
20 changes: 10 additions & 10 deletions changehc/delphi_changehc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@


class CHCSensor:
"""Sensor class to fit a signal using Covid counts from Change HC outpatient data.
"""
"""Sensor class to fit a signal using Covid counts from Change HC outpatient data."""

smoother = Smoother("savgol",
poly_fit_degree=1,
gaussian_bandwidth=Config.SMOOTHER_BANDWIDTH)

@staticmethod
def gauss_smooth(count,total):
"""smooth using the left_gauss_linear
"""Smooth using the left_gauss_linear.

Args:
count, total: array
"""
"""
count_smooth = CHCSensor.smoother.smooth(count)
total_smooth = CHCSensor.smoother.smooth(total)
total_clip = np.clip(total_smooth, 0, None)
Expand All @@ -46,12 +46,12 @@ def backfill(
k=Config.MAX_BACKFILL_WINDOW,
min_visits_to_fill=Config.MIN_CUM_VISITS):
"""
Adjust for backfill (retroactively added observations) by using a
variable length smoother, which starts from the RHS and moves
leftwards (backwards through time). We cumulatively sum the total
visits (denominator), until we have observed some minimum number of
counts, then calculate the sum over that bin. We restrict the
bin size so to avoid inluding long-past values.
Adjust for retroactively added observations (backfill) by using a variable length smoother.

The smoother starts from the RHS and moves leftwards (backwards through time).
We cumulatively sum the total visits (denominator), until we have observed some minimum number of
counts, then calculate the sum over that bin. We restrict the
bin size so to avoid including long-past values.

Args:
num: array of covid counts
Expand Down
15 changes: 9 additions & 6 deletions changehc/delphi_changehc/update_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Generate CHC sensors.

Author: Aaron Rumack
Created: 2020-10-14
"""
Expand All @@ -22,6 +23,7 @@

def write_to_csv(output_dict, write_se, out_name, output_path="."):
"""Write sensor values to csv.

Args:
output_dict: dictionary containing sensor rates, se, unique dates, and unique geo_id
write_se: boolean to write out standard errors, if true, use an obfuscated name
Expand Down Expand Up @@ -73,8 +75,7 @@ def write_to_csv(output_dict, write_se, out_name, output_path="."):


class CHCSensorUpdator: # pylint: disable=too-many-instance-attributes
"""Contains methods to update sensor and write results to csv
"""
"""Contains methods to update sensor and write results to csv."""

def __init__(self,
startdate,
Expand All @@ -84,7 +85,8 @@ def __init__(self,
parallel,
weekday,
se):
"""Init Sensor Updator
"""Init Sensor Updator.

Args:
startdate: first sensor date (YYYY-mm-dd)
enddate: last sensor date (YYYY-mm-dd)
Expand Down Expand Up @@ -120,8 +122,7 @@ def __init__(self,
self.sensor_dates = None

def shift_dates(self):
"""shift estimates forward to account for time lag, compute burnindates, sensordates
"""
"""Shift estimates forward to account for time lag, compute burnindates, sensordates."""
drange = lambda s, e: pd.date_range(start=s,periods=(e-s).days,freq='D')
self.startdate = self.startdate - Config.DAY_SHIFT
self.burnindate = self.startdate - Config.BURN_IN_PERIOD
Expand All @@ -131,7 +132,8 @@ def shift_dates(self):
return True

def geo_reindex(self, data):
"""Reindex based on geography, include all date, geo pairs
"""Reindex based on geography, include all date, geo pairs.

Args:
data: dataframe, the output of loadcombineddata
Returns:
Expand Down Expand Up @@ -177,6 +179,7 @@ def update_sensor(self,
covid_filepath,
outpath):
"""Generate sensor values, and write to csv format.

Args:
denom_filepath: path to the aggregated denominator data
covid_filepath: path to the aggregated covid data
Expand Down
2 changes: 0 additions & 2 deletions changehc/delphi_changehc/weekday.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def get_params(data):
Return a matrix of parameters: the entire vector of betas, for each time
series column in the data.
"""

tmp = data.reset_index()
denoms = tmp.groupby(Config.DATE_COL).sum()["den"]
nums = tmp.groupby(Config.DATE_COL).sum()["num"]
Expand Down Expand Up @@ -113,7 +112,6 @@ def calc_adjustment(params, sub_data):
-- this has the same effect.

"""

tmp = sub_data.reset_index()

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