Skip to content

Commit

Permalink
codacy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OnnoEbbens committed Oct 23, 2023
1 parent 5ec859f commit 9aaa530
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ pylint:
- no-else-raise
- too-many-arguments
- too-many-locals
- too-many-branches
- logging-fstring-interpolation

mccabe:
disable:
- MC0001
260 changes: 131 additions & 129 deletions nlmod/dims/attributes_encodings.py
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
import numpy as np

dim_attrs = {
"time": dict(
name="Time",
description="End time of the stress period",
),
"botm": dict(
name="Bottom elevation",
description="Bottom elevation for each model cell",
units="mNAP",
valid_min=-2000.0,
valid_max=500.0,
),
"top": dict(
name="Top elevation",
description="Top elevation for each model cell",
units="mNAP",
valid_min=-2000.0,
valid_max=500.0,
),
"kh": dict(
name="Horizontal hydraulic conductivity",
description="Horizontal hydraulic conductivity for each model cell",
units="m/day",
valid_min=0.0,
valid_max=1000.0,
),
"kv": dict(
name="Vertical hydraulic conductivity",
description="Vertical hydraulic conductivity for each model cell",
units="m/day",
valid_min=0.0,
valid_max=1000.0,
),
"ss": dict(
name="Specific storage",
description="Specific storage for each model cell",
units="1/m",
valid_min=0.0,
valid_max=1.0,
),
"sy": dict(
name="Specific yield",
description="Specific yield for each model cell",
units="-",
valid_min=0.0,
valid_max=1.0,
),
"porosity": dict(
name="Porosity",
description="Porosity for each model cell",
units="-",
valid_min=0.0,
valid_max=1.0,
),
"recharge": dict(
name="Recharge",
description="Recharge for each model cell",
units="m/day",
valid_min=0.0,
valid_max=0.5,
),
"heads": dict(
name="Heads",
description="Point water heads for each model cell",
units="mNAP",
valid_min=-100.0,
valid_max=500.0,
),
"starting_head": dict(
name="Starting head",
description="Starting head for each model cell",
units="mNAP",
valid_min=-100.0,
valid_max=500.0,
),
"freshwater_head": dict(
name="Freshwater head",
description="Freshwater head for each model cell",
units="mNAP",
valid_min=-100.0,
valid_max=500.0,
),
"pointwater_head": dict(
name="Pointwater head",
description="Pointwater head for each model cell",
units="mNAP",
valid_min=-100.0,
valid_max=500.0,
),
"density": dict(
name="Density",
description="Density for each model cell",
units="kg/m3",
valid_min=950.0,
valid_max=1200.0,
),
"area": dict(
name="Cell area",
description="Cell area for each model cell",
units="m2",
valid_min=0.0,
valid_max=1e8,
),
"time": {
"name": "Time",
"description": "End time of the stress period",
},
"botm": {
"name": "Bottom elevation",
"description": "Bottom elevation for each model cell",
"units": "mNAP",
"valid_min": -2000.0,
"valid_max": 500.0,
},
"top": {
"name": "Top elevation",
"description": "Top elevation for each model cell",
"units": "mNAP",
"valid_min": -2000.0,
"valid_max": 500.0,
},
"kh": {
"name": "Horizontal hydraulic conductivity",
"description": "Horizontal hydraulic conductivity for each model cell",
"units": "m/day",
"valid_min": 0.0,
"valid_max": 1000.0,
},
"kv": {
"name": "Vertical hydraulic conductivity",
"description": "Vertical hydraulic conductivity for each model cell",
"units": "m/day",
"valid_min": 0.0,
"valid_max": 1000.0,
},
"ss": {
"name": "Specific storage",
"description": "Specific storage for each model cell",
"units": "1/m",
"valid_min": 0.0,
"valid_max": 1.0,
},
"sy": {
"name": "Specific yield",
"description": "Specific yield for each model cell",
"units": "-",
"valid_min": 0.0,
"valid_max": 1.0,
},
"porosity": {
"name": "Porosity",
"description": "Porosity for each model cell",
"units": "-",
"valid_min": 0.0,
"valid_max": 1.0,
},
"recharge": {
"name": "Recharge",
"description": "Recharge for each model cell",
"units": "m/day",
"valid_min": 0.0,
"valid_max": 0.5,
},
"heads": {
"name": "Heads",
"description": "Point water heads for each model cell",
"units": "mNAP",
"valid_min": -100.0,
"valid_max": 500.0,
},
"starting_head": {
"name": "Starting head",
"description": "Starting head for each model cell",
"units": "mNAP",
"valid_min": -100.0,
"valid_max": 500.0,
},
"freshwater_head": {
"name": "Freshwater head",
"description": "Freshwater head for each model cell",
"units": "mNAP",
"valid_min": -100.0,
"valid_max": 500.0,
},
"pointwater_head": {
"name": "Pointwater head",
"description": "Pointwater head for each model cell",
"units": "mNAP",
"valid_min": -100.0,
"valid_max": 500.0,
},
"density": {
"name": "Density",
"description": "Density for each model cell",
"units": "kg/m3",
"valid_min": 950.0,
"valid_max": 1200.0,
},
"area": {
"name": "Cell area",
"description": "Cell area for each model cell",
"units": "m2",
"valid_min": 0.0,
"valid_max": 1e8,
},
}


encoding_requirements = {
"heads": dict(dval_max=0.005),
"botm": dict(dval_max=0.005),
"top": dict(dval_max=0.005),
"kh": dict(dval_max=1e-6),
"kv": dict(dval_max=1e-6),
"ss": dict(dval_max=1e-8),
"sy": dict(dval_max=0.005),
"porosity": dict(dval_max=0.005),
"recharge": dict(dval_max=0.0005),
"starting_head": dict(dval_max=0.005),
"freshwater_head": dict(dval_max=0.005),
"pointwater_head": dict(dval_max=0.005),
"density": dict(dval_max=0.005),
"area": dict(dval_max=0.05),
"heads": {"dval_max": 0.005},
"botm": {"dval_max": 0.005},
"top": {"dval_max": 0.005},
"kh": {"dval_max": 1e-6},
"kv": {"dval_max": 1e-6},
"ss": {"dval_max": 1e-8},
"sy": {"dval_max": 0.005},
"porosity": {"dval_max": 0.005},
"recharge": {"dval_max": 0.0005},
"starting_head": {"dval_max": 0.005},
"freshwater_head": {"dval_max": 0.005},
"pointwater_head": {"dval_max": 0.005},
"density": {"dval_max": 0.005},
"area": {"dval_max": 0.05},
}


Expand Down Expand Up @@ -156,12 +156,12 @@ def get_encodings(
Returns
-------
encodings : dict
encodings : dict or None
Dictionary containing the encodings for each data_var
TODO: add support for strings
"""
encodings = dict()
encodings = {}
for varname, da in ds.data_vars.items():
# Encoding for strings is not supported by netCDF
if np.issubdtype(da.dtype, np.character):
Expand All @@ -171,11 +171,11 @@ def get_encodings(
"_FillValue" not in da.attrs
), f"Custom fillvalues are not supported. {varname} has a fillvalue set."

encoding = dict(
zlib=True,
complevel=5,
fletcher32=True, # Store checksums to detect corruption
)
encoding = {
"zlib": True,
"complevel": 5,
"fletcher32": True, # Store checksums to detect corruption
}

isfloat = np.issubdtype(da.dtype, np.floating)
isint = np.issubdtype(da.dtype, np.integer)
Expand Down Expand Up @@ -221,20 +221,22 @@ def get_encodings(
else:
encodings[varname] = encoding

if not set_encoding_inplace:
if set_encoding_inplace:
return None
else:
return encodings


def compute_scale_and_offset(minValue, maxValue):
def compute_scale_and_offset(min_value, max_value):
"""
Computes the scale_factor and offset for the dataset using a minValue and maxValue,
Computes the scale_factor and offset for the dataset using a min_value and max_value,
and int16. Useful for maximizing the compression of a dataset.
Parameters
----------
minValue : float
min_value : float
Minimum value of the dataset
maxValue : float
max_value : float
Maximum value of the dataset
Returns
Expand All @@ -247,7 +249,7 @@ def compute_scale_and_offset(minValue, maxValue):
# stretch/compress data to the available packed range
# from -32766 to 32767, because -32767 is the default fillvalue.
width = 32766 + 32767
scale_factor = (maxValue - minValue) / width
scale_factor = (max_value - min_value) / width
add_offset = 1.0 + scale_factor * (width - 1) / 2
return scale_factor, add_offset

Expand Down
2 changes: 1 addition & 1 deletion nlmod/dims/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import xarray as xr

from ..util import LayerError, MissingValueError
from ..util import LayerError
from . import resample

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion nlmod/read/geotop.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_lithok_colors():
8: (216, 163, 32),
9: (95, 95, 255),
}
colors = {key: tuple([x / 255 for x in color]) for key, color in colors.items()}
colors = {key: (x / 255 for x in color) for key, color in colors.items()}
return colors


Expand Down
2 changes: 1 addition & 1 deletion nlmod/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def download_modpath_provisional_exe(bindir=None, timeout=120):
elif sys.platform.startswith("linux"):
fname = "mp7_linux_20230911_8eca8d8"
else:
raise (Exception(f"Unknown platform: {sys.platform}"))
raise (OsError(f"Unknown platform: {sys.platform}"))
url = "https://github.com/MODFLOW-USGS/modpath-v7/raw/develop/msvs/bin_PROVISIONAL"
url = f"{url}/{fname}"
r = requests.get(url, allow_redirects=True, timeout=timeout)
Expand Down

0 comments on commit 9aaa530

Please sign in to comment.