Skip to content

Commit

Permalink
Fix initial lint errors #27
Browse files Browse the repository at this point in the history
- remove unused imports
- fix trailing white spaces and indentation
- update workflow to ignore version import
  • Loading branch information
bdubayah authored Jun 21, 2021
1 parent 6f9fe0c commit 286d0f4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
pip install flake8
- name: Lint with flake8
run: |
flake8 --max-line-length 80 dora_exp_pipeline
flake8 --max-line-length 80 --per-file-ignores="__init__.py:F401" dora_exp_pipeline
12 changes: 6 additions & 6 deletions dora_exp_pipeline/dora_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ 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: '
f'{os.path.abspath(self.data_to_fit)}')

# 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)):
Expand All @@ -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").
Expand Down
6 changes: 3 additions & 3 deletions dora_exp_pipeline/dora_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,22 @@ 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
with open(dir_path, 'r') as csv_file:
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

Expand Down
1 change: 0 additions & 1 deletion dora_exp_pipeline/dora_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions dora_exp_pipeline/dora_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions dora_exp_pipeline/lrx_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.'
)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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 '
Expand Down
6 changes: 3 additions & 3 deletions dora_exp_pipeline/random_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand Down

0 comments on commit 286d0f4

Please sign in to comment.