From 286d0f481852cd3cae11ad303a1fbdd0e1f8876d Mon Sep 17 00:00:00 2001 From: Bryce Dubayah Date: Mon, 21 Jun 2021 10:03:27 -0400 Subject: [PATCH] Fix initial lint errors #27 - remove unused imports - fix trailing white spaces and indentation - update workflow to ignore version import --- .github/workflows/main.yml | 2 +- dora_exp_pipeline/dora_config.py | 12 ++++++------ dora_exp_pipeline/dora_data_loader.py | 6 +++--- dora_exp_pipeline/dora_exp.py | 1 - dora_exp_pipeline/dora_feature.py | 3 --- dora_exp_pipeline/lrx_outlier_detection.py | 10 ++++------ dora_exp_pipeline/random_outlier_detection.py | 6 +++--- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 597a72a..6c8c5e5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,4 +18,4 @@ jobs: pip install flake8 - name: Lint with flake8 run: | - flake8 --max-line-length 80 dora_exp_pipeline \ No newline at end of file + flake8 --max-line-length 80 --per-file-ignores="__init__.py:F401" dora_exp_pipeline \ No newline at end of file diff --git a/dora_exp_pipeline/dora_config.py b/dora_exp_pipeline/dora_config.py index ec87431..ba21167 100644 --- a/dora_exp_pipeline/dora_config.py +++ b/dora_exp_pipeline/dora_config.py @@ -67,11 +67,11 @@ def log_configs(self, config_file): def verify_config_parameters(self): # Verify `data_type` field if not isinstance(self.data_type, str): - raise RuntimeError(f'data_type field must be a string') + raise RuntimeError('data_type field must be a string') # Verify `data_to_fit` if not isinstance(self.data_to_fit, str): - raise RuntimeError(f'data_to_fit field must be a string') + raise RuntimeError('data_to_fit field must be a string') if not os.path.exists(self.data_to_fit): raise RuntimeError(f'data_to_fit not found: ' @@ -79,7 +79,7 @@ def verify_config_parameters(self): # Verify `data_to_score` if not isinstance(self.data_to_score, str): - raise RuntimeError(f'data_to_score field must be a string') + raise RuntimeError('data_to_score field must be a string') if (len(self.data_to_score) != 0 and not os.path.exists(self.data_to_score)): @@ -88,15 +88,15 @@ def verify_config_parameters(self): # Verify `features` if not isinstance(self.features, dict): - raise RuntimeError(f'features field must be a dictionary') + raise RuntimeError('features field must be a dictionary') # Verify `outlier_detection` if not isinstance(self.outlier_detection, dict): - raise RuntimeError(f'outlier_detection field must be a dictionary') + raise RuntimeError('outlier_detection field must be a dictionary') # Verify `results` if not isinstance(self.results, dict): - raise RuntimeError(f'results field must be a dictionary') + raise RuntimeError('results field must be a dictionary') # Copyright (c) 2021 California Institute of Technology ("Caltech"). diff --git a/dora_exp_pipeline/dora_data_loader.py b/dora_exp_pipeline/dora_data_loader.py index 2e527c5..09ca89f 100644 --- a/dora_exp_pipeline/dora_data_loader.py +++ b/dora_exp_pipeline/dora_data_loader.py @@ -173,7 +173,7 @@ def _load(self, dir_path: str) -> dict: data_dict.setdefault('id', []) data_dict.setdefault('data', []) - # TODO: add support for other data types + # TODO: add support for other data types # (e.g., .h5 dataframes, .npy) if dir_path.endswith('.csv'): # Load the csv data @@ -181,14 +181,14 @@ def _load(self, dir_path: str) -> dict: csv_reader = csv.reader(csv_file, quoting=csv.QUOTE_NONNUMERIC) # Read each row into the data_dict for row in csv_reader: - # Assumes the first column is the ID + # Assumes the first column is the ID # and all other columns are time steps data_dict['id'].append(row[0]) data_dict['data'].append(np.array(row[1:])) else: raise RuntimeError(f'File extension not supported. ' f'Valid file extensions: ' - f'{file_types}') + f'{file_types}') return data_dict diff --git a/dora_exp_pipeline/dora_exp.py b/dora_exp_pipeline/dora_exp.py index 55b9ebb..cc585aa 100644 --- a/dora_exp_pipeline/dora_exp.py +++ b/dora_exp_pipeline/dora_exp.py @@ -12,7 +12,6 @@ import sys from dora_exp_pipeline.dora_config import DoraConfig from dora_exp_pipeline.dora_data_loader import get_data_loader_by_name -from dora_exp_pipeline.dora_feature import z_score_normalize from dora_exp_pipeline.outlier_detection import register_od_alg # from src.demud_outlier_detection import DEMUDOutlierDetection from dora_exp_pipeline.iforest_outlier_detection import IForestOutlierDetection diff --git a/dora_exp_pipeline/dora_feature.py b/dora_exp_pipeline/dora_feature.py index f365f2c..5dbe488 100644 --- a/dora_exp_pipeline/dora_feature.py +++ b/dora_exp_pipeline/dora_feature.py @@ -3,10 +3,7 @@ # # Steven Lu, June 29, 2020 -import os import numpy as np -from scipy.stats import skew -from scipy.stats import kurtosis from skimage import transform from six import add_metaclass from abc import ABCMeta, abstractmethod diff --git a/dora_exp_pipeline/lrx_outlier_detection.py b/dora_exp_pipeline/lrx_outlier_detection.py index 1ebc566..56138bb 100644 --- a/dora_exp_pipeline/lrx_outlier_detection.py +++ b/dora_exp_pipeline/lrx_outlier_detection.py @@ -11,9 +11,7 @@ import sys import numpy as np from dora_exp_pipeline.outlier_detection import OutlierDetection -from dora_exp_pipeline.util import load_images from dora_exp_pipeline.util import DEFAULT_DATA_DIR -from dora_exp_pipeline.util import get_image_file_list class LocalRXOutlierDetection(OutlierDetection): @@ -36,7 +34,7 @@ def _rank_internal(self, files, rank_data, prior_data, config, seed, features_1d = config.features['one_dimensional'] features_keys = features_1d.keys() if 'flattened_pixel_values' not in features_keys or \ - len(features_keys) > 1: + len(features_keys) > 1: raise RuntimeError( 'LRX must be used with `flattened_pixel_values` feature alone.' ) @@ -91,7 +89,7 @@ def _rank_targets(self, data_test, files, inner_window, outer_window, bands, # Local RX (LRX) def get_LRX_scores(images, w_inner, w_outer, bands): - # Images has shape N x M where N is number of images and + # Images has shape N x M where N is number of images and # M is flattened image dimension. Divide by bands to get # image dimensions. rows, cols = images.shape @@ -112,7 +110,7 @@ def get_LRX_scores(images, w_inner, w_outer, bands): for j in range(s, im.shape[1]-s): scores[idx, i, j] = lrx(im[i - s: i + s + 1, j - s: j + s + 1], w_inner) - return np.mean(scores[:,s:-s,s:-s], axis=(1, 2)), scores + return np.mean(scores[:, s:-s, s:-s], axis=(1, 2)), scores def lrx(patch, w_in): @@ -183,7 +181,7 @@ def main(): help='size of inner window (default 3)') parser.add_argument('-u', '--outer_window', type=int, default=5, help='size of outer window (default 5)') - parser.add_argument('-b', '--bands', type=int, default=1, + parser.add_argument('-b', '--bands', type=int, default=1, help='number of bands in input images (default 1)') parser.add_argument('--seed', type=int, default=1234, help='Integer used to seed the random generator. This ' diff --git a/dora_exp_pipeline/random_outlier_detection.py b/dora_exp_pipeline/random_outlier_detection.py index cc14d8d..f1ec647 100755 --- a/dora_exp_pipeline/random_outlier_detection.py +++ b/dora_exp_pipeline/random_outlier_detection.py @@ -9,10 +9,10 @@ # Steven Lu, May 13, 2020, refactored the code to extract common functionalities # out to util.py. -import sys import numpy as np from dora_exp_pipeline.outlier_detection import OutlierDetection + class RandomOutlierDetection(OutlierDetection): def __init__(self): super(RandomOutlierDetection, self).__init__('random') @@ -23,8 +23,8 @@ def _random(self, train, test, seed): random_state = np.random.RandomState(seed) random_state.shuffle(indices) - # This interprets the indices as the scores so when - # the scores are sorted later they will have the + # This interprets the indices as the scores so when + # the scores are sorted later they will have the # random order. return indices