Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed Jul 19, 2024
1 parent d82884e commit a546b27
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
fetch-depth: 0
- name: Lint Code Base
uses: super-linter/super-linter/[email protected]
uses: super-linter/super-linter@v4
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_PYTHON_BLACK: false
Expand Down
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ repos:
[
--rcfile,
.github/linters/.python-lint,
--ignore-paths,
tests/,
]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.3
Expand Down
15 changes: 0 additions & 15 deletions sup3r/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,3 @@
SUP3R_DIR = os.path.dirname(os.path.realpath(__file__))
CONFIG_DIR = os.path.join(SUP3R_DIR, 'configs')
TEST_DATA_DIR = os.path.join(os.path.dirname(SUP3R_DIR), 'tests', 'data')


VERSION_RECORD = {
'sup3r': __version__,
'tensorflow': tf.__version__,
'sklearn': sklearn.__version__,
'pandas': pd.__version__,
'numpy': np.__version__,
'nrel-phygnn': phygnn.__version__,
'nrel-rex': rex.__version__,
'python': sys.version,
'xarray': xarray.__version__,
'h5netcdf': h5netcdf.__version__,
'dask': dask.__version__,
}
3 changes: 1 addition & 2 deletions sup3r/bias/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
from scipy.spatial import KDTree

import sup3r.preprocessing
from sup3r import VERSION_RECORD
from sup3r.preprocessing import DataHandlerNC as DataHandler
from sup3r.preprocessing.utilities import _compute_if_dask, expand_paths
from sup3r.utilities import ModuleName
from sup3r.utilities import VERSION_RECORD, ModuleName
from sup3r.utilities.cli import BaseCLI

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion sup3r/bias/bias_calc_vortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from rex import Resource
from scipy.interpolate import interp1d

from sup3r import VERSION_RECORD
from sup3r.postprocessing import OutputHandler, RexOutputs
from sup3r.utilities import VERSION_RECORD

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion sup3r/models/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from tensorflow.keras import optimizers

import sup3r.utilities.loss_metrics
from sup3r import VERSION_RECORD
from sup3r.preprocessing.data_handlers.base import ExoData
from sup3r.preprocessing.utilities import _numpy_if_tensor
from sup3r.utilities import VERSION_RECORD
from sup3r.utilities.utilities import Timer

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion sup3r/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import tensorflow as tf
from tensorflow.keras import optimizers

from sup3r import VERSION_RECORD
from sup3r.utilities import VERSION_RECORD

from .abstract import AbstractInterface, AbstractSingleModel

Expand Down
2 changes: 1 addition & 1 deletion sup3r/models/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import tensorflow as tf
from tensorflow.keras import optimizers

from sup3r import VERSION_RECORD
from sup3r.utilities import VERSION_RECORD

from .abstract import AbstractInterface, AbstractSingleModel

Expand Down
6 changes: 1 addition & 5 deletions sup3r/pipeline/forward_pass_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ def main(ctx, verbose):
)
@click.pass_context
def from_config(ctx, config_file, verbose=False, pipeline_step=None):
"""Run sup3r forward pass from a config file.
TODO: Can we figure out how to remove the first ForwardPassStrategy
initialization here, so that its only initialized once for each node?
"""
"""Run sup3r forward pass from a config file."""

config = BaseCLI.from_config_preflight(
ModuleName.FORWARD_PASS, ctx, config_file, verbose
Expand Down
4 changes: 2 additions & 2 deletions sup3r/postprocessing/writers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from rex.outputs import Outputs as BaseRexOutputs
from scipy.interpolate import griddata

from sup3r import VERSION_RECORD, __version__
from sup3r.preprocessing.derivers.utilities import parse_feature
from sup3r.utilities import VERSION_RECORD
from sup3r.utilities.utilities import pd_date_range

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -293,7 +293,7 @@ def full_version_record(self):

def set_version_attr(self):
"""Set the version attribute to the h5 file."""
self.h5.attrs['version'] = __version__
self.h5.attrs['version'] = VERSION_RECORD['sup3r']
self.h5.attrs['full_version_record'] = json.dumps(
self.full_version_record
)
Expand Down
2 changes: 1 addition & 1 deletion sup3r/qa/qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def get_node_cmd(cls, config):
log_arg_str += f', log_file="{log_file}"'

cmd = (
f"python -c '{import_str};\n"
f"python -c '{import_str};\n"
't0 = time.time();\n'
f'logger = init_logger({log_arg_str});\n'
f'qa = {qa_init_str};\n'
Expand Down
27 changes: 27 additions & 0 deletions sup3r/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
"""Sup3r utilities"""

import os
import sys
from enum import Enum

import dask
import h5netcdf
import numpy as np
import pandas as pd
import phygnn
import rex
import sklearn
import tensorflow as tf
import xarray

from .._version import __version__

VERSION_RECORD = {
'sup3r': __version__,
'tensorflow': tf.__version__,
'sklearn': sklearn.__version__,
'pandas': pd.__version__,
'numpy': np.__version__,
'nrel-phygnn': phygnn.__version__,
'nrel-rex': rex.__version__,
'python': sys.version,
'xarray': xarray.__version__,
'h5netcdf': h5netcdf.__version__,
'dask': dask.__version__,
}


class ModuleName(str, Enum):
"""A collection of the module names available in sup3r.
Expand Down
4 changes: 2 additions & 2 deletions tests/data_handlers/test_dh_nc_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_get_just_coords_nc():
assert np.array_equal(
handler.lat_lon[-1, 0, :],
(
handler.extracter[Dimension.LATITUDE].min(),
handler.extracter[Dimension.LONGITUDE].min(),
handler.extracter.data[Dimension.LATITUDE].min(),
handler.extracter.data[Dimension.LONGITUDE].min(),
),
)
assert not handler.data_vars
Expand Down
6 changes: 4 additions & 2 deletions tests/extracters/test_extracter_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def test_data_caching(input_files, ext, shape, target, features):
assert extracter.data.dtype == np.dtype(np.float32)
loader = Loader(cacher.out_files)
assert np.array_equal(
loader[features, ...].compute(), extracter[features, ...].compute()
loader.data[features, ...].compute(),
extracter.data[features, ...].compute(),
)

# make sure full domain can be loaded with extracters
extracter = Extracter(cacher.out_files)
assert np.array_equal(
loader[features, ...].compute(), extracter[features, ...].compute()
loader.data[features, ...].compute(),
extracter.data[features, ...].compute(),
)

0 comments on commit a546b27

Please sign in to comment.