diff --git a/nowcast/.pylintrc b/nowcast/.pylintrc index 90d5d3f91..786c72eb8 100644 --- a/nowcast/.pylintrc +++ b/nowcast/.pylintrc @@ -16,9 +16,9 @@ disable=logging-format-interpolation, [BASIC] # Allow arbitrarily short-named variables. -variable-rgx=[a-z_][a-z0-9_]* -argument-rgx=[a-z_][a-z0-9_]* -attr-rgx=[a-z_][a-z0-9_]* +variable-rgx=[A-Za-z_][a-z0-9_]* +argument-rgx=[A-Za-z_][a-z0-9_]* +attr-rgx=[A-Za-z_][a-z0-9_]* [DESIGN] diff --git a/nowcast/delphi_nowcast/deconvolution/deconvolution.py b/nowcast/delphi_nowcast/deconvolution/deconvolution.py index dd6b00f61..03e4a9c08 100644 --- a/nowcast/delphi_nowcast/deconvolution/deconvolution.py +++ b/nowcast/delphi_nowcast/deconvolution/deconvolution.py @@ -74,7 +74,7 @@ def deconvolve_double_smooth_ntf( x_k = None alpha_0 = np.zeros(n - k - 1) u_0 = np.zeros(n - k - 1) - for t in range(n_iters): + for _ in range(n_iters): x_k = x_update_1 @ (Cty + rho * D.T @ (alpha_0 + u_0)) Dx = D @ x_k alpha_k = _soft_thresh(Dx - u_0, lam / rho) diff --git a/nowcast/delphi_nowcast/deconvolution/ground_truth.py b/nowcast/delphi_nowcast/deconvolution/ground_truth.py deleted file mode 100644 index f251771f7..000000000 --- a/nowcast/delphi_nowcast/deconvolution/ground_truth.py +++ /dev/null @@ -1,47 +0,0 @@ -"""Functions to construct the ground truth for a given location.""" -from datetime import date -from typing import List, Dict, Tuple - -import numpy as np - -from .deconvolution import deconvolve_double_smooth_tf_cv -from ..constants import Default -from ..data_containers import LocationSeries, SensorConfig -from ..epidata import get_historical_sensor_data, get_indicator_data, export_to_csv - - -def construct_truths(start_date: date, - end_date: date, - as_of: date, # most likely today - truth: SensorConfig, - locations: List[LocationSeries], - export_dir: str = "") -> Dict[Tuple, LocationSeries]: - raw_indicator = get_indicator_data([truth], locations, as_of) - output = {} - for location in locations: - indicator_key = (truth.source, truth.signal, location.geo_type, location.geo_value) - location, missing_dates = get_historical_sensor_data(truth, location, end_date, start_date) - location, export = fill_missing_days(location, raw_indicator[indicator_key], missing_dates) - output[indicator_key] = location - if export_dir and export.values: - export_to_csv(export, truth, as_of, export_dir) - return output - - -def fill_missing_days(stored_vals: LocationSeries, - indicator_data: LocationSeries, - missing_dates: List[date]): - export_data = LocationSeries(stored_vals.geo_value, stored_vals.geo_type) - for day in missing_dates: - try: - y = np.array(indicator_data.get_data_range(min(indicator_data.dates), day, "linear")) - x = np.arange(1, len(y) + 1) - except ValueError: - continue - deconv_vals = deconvolve_double_smooth_tf_cv( - y, x, Default.DELAY_DISTRIBUTION - ) - missing_day_val = deconv_vals[-1] - stored_vals.add_data(day, missing_day_val) - export_data.add_data(day, missing_day_val) # holds only data to get exported - return stored_vals, export_data diff --git a/nowcast/delphi_nowcast/sensorization/ar_model.py b/nowcast/delphi_nowcast/sensorization/ar_model.py index ca7bc68db..34feb9b74 100644 --- a/nowcast/delphi_nowcast/sensorization/ar_model.py +++ b/nowcast/delphi_nowcast/sensorization/ar_model.py @@ -1,4 +1,6 @@ -from datetime import datetime, timedelta, date +"""Fit autoregression models.""" + +from datetime import timedelta, date from typing import Tuple import numpy as np diff --git a/nowcast/delphi_nowcast/sensorization/regression_model.py b/nowcast/delphi_nowcast/sensorization/regression_model.py index dab70d0ba..a22cc01c3 100644 --- a/nowcast/delphi_nowcast/sensorization/regression_model.py +++ b/nowcast/delphi_nowcast/sensorization/regression_model.py @@ -1,4 +1,6 @@ -from datetime import datetime, timedelta, date +"""Fit linear regression mdels.""" + +from datetime import timedelta, date import numpy as np diff --git a/nowcast/delphi_nowcast/sensorization/sensor.py b/nowcast/delphi_nowcast/sensorization/sensor.py index 913e07fce..39fa07876 100644 --- a/nowcast/delphi_nowcast/sensorization/sensor.py +++ b/nowcast/delphi_nowcast/sensorization/sensor.py @@ -1,5 +1,4 @@ """Functions to run sensorization.""" -import os from collections import defaultdict from typing import List, DefaultDict from datetime import timedelta, date @@ -54,7 +53,7 @@ def compute_sensors(as_of_date: date, (sensor.source, sensor.signal, loc.geo_type, loc.geo_value) ) if not covariates: - # TODO convert to log statements #689 + # TODO convert to log statements #689 # pylint: disable=fixme print(f"No data: {(sensor.source, sensor.signal, loc.geo_type, loc.geo_value)}") continue reg_sensor = compute_regression_sensor(sensor_pred_date, covariates, loc, REG_INTERCEPT) @@ -95,7 +94,7 @@ def historical_sensors(start_date: date, output = defaultdict(list) for location in ground_truths: for sensor in sensors: - sensor_vals, missing_dates = get_historical_sensor_data( + sensor_vals, _ = get_historical_sensor_data( sensor, location, start_date, end_date ) if sensor_vals.data: