Skip to content

Commit 3e1a1ff

Browse files
committed
fixed unused variable issue, other code style issues highlighted by recent Codacy review
monocongo#240 Former-commit-id: 5acce91
1 parent 920629d commit 3e1a1ff

15 files changed

+116
-110
lines changed

.github/ISSUE_TEMPLATE/Bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ A clear and concise description of what you expected to happen.
2323
If applicable, add screenshots to help explain your problem.
2424

2525
**Desktop (please complete the following information):**
26-
- OS: [e.g. iOS]
27-
- Version: [e.g. 22]
26+
- OS: \[e.g. iOS]
27+
- Version: \[e.g. 22]
2828

2929
**Additional context**
3030
Add any other context about the problem here.
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
---
2-
name: Feature request
3-
about: Suggest an idea for this project
4-
5-
---
6-
7-
**Is your feature request related to a problem? Please describe.**
8-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9-
10-
**Describe the solution you'd like**
11-
A clear and concise description of what you want to happen.
12-
13-
**Describe alternatives you've considered**
14-
A clear and concise description of any alternative solutions or features you've considered.
15-
16-
**Additional context**
17-
Add any other context or screenshots about the feature request here.
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
**Is your feature request related to a problem? Please describe.**
8+
A clear and concise description of what the problem is. Ex. I'm always frustrated when \[...]
9+
10+
**Describe the solution you'd like**
11+
A clear and concise description of what you want to happen.
12+
13+
**Describe alternatives you've considered**
14+
A clear and concise description of any alternative solutions or features you've considered.
15+
16+
**Additional context**
17+
Add any other context or screenshots about the feature request here.

.idea/climate_indices.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Hopefully a clear, coherent style will emerge from a reading of the code. We opt
99
* Indent using four spaces (no tabs)
1010
* Whitespaces after list items and method parameters (`[1, 2, 3]`, not `[1,2,3]`), around operators (`x += 1`, not `x+=1`), and around hash arrows.
1111
* Liberal use of whitespace and blank lines
12-
* Comment as much as necessary, more is better than less, and comments are code -- maintain the commentary as if it were being compiled
12+
* Comment as much as necessary, more is better than less, and comments are code \-- maintain the commentary as if it were being compiled
1313
* Underscores instead of camelCase
1414
* This is open source software. Consider the people who will read your code, and make it look nice for them. It's sort of like driving a car: Perhaps you love doing donuts when you're alone, but with passengers the goal is to make the ride as smooth as possible.
1515

@@ -62,7 +62,7 @@ Then merge the changes that you fetched:
6262
For more info, see http://help.github.com/fork-a-repo/
6363

6464
## How to get your pull request accepted
65-
We want your submission. But we also want to provide a stable experience for our users and the community.
65+
We want your submission. But we also want to provide a stable experience for our users and the community.
6666
Follow these rules and you should succeed without a problem.
6767

6868
### Run the tests
@@ -83,7 +83,7 @@ Also, keep your tests as simple as possible. Complex tests end up requiring thei
8383
Always write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should look like this:
8484

8585
`$ git commit -m "A brief summary of the commit
86-
\>
86+
\>
8787
\> A paragraph describing what changed and its impact.`
8888

8989
### Don’t mix code changes with whitespace cleanup

README.md

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,53 @@
66

77
# Climate Indices in Python
88

9-
This project contains Python implementations of various climate index algorithms which provide
9+
This project contains Python implementations of various climate index algorithms which provide
1010
a geographical and temporal picture of the severity of precipitation and temperature anomalies
1111
useful for climate monitoring and research.
1212

1313
The following indices are provided:
1414

15-
- [SPI](https://climatedataguide.ucar.edu/climate-data/standardized-precipitation-index-spi),
16-
Standardized Precipitation Index, utilizing both gamma and Pearson Type III distributions
17-
- [SPEI](https://www.researchgate.net/publication/252361460_The_Standardized_Precipitation-Evapotranspiration_Index_SPEI_a_multiscalar_drought_index),
18-
Standardized Precipitation Evapotranspiration Index, utilizing both gamma and Pearson Type III distributions
19-
- [PET](https://www.ncdc.noaa.gov/monitoring-references/dyk/potential-evapotranspiration),
20-
Potential Evapotranspiration, utilizing either [Thornthwaite](http://dx.doi.org/10.2307/21073)
21-
or [Hargreaves](http://dx.doi.org/10.13031/2013.26773) equations
22-
- [PDSI](http://www.droughtmanagement.info/palmer-drought-severity-index-pdsi/),
23-
Palmer Drought Severity Index
24-
- [scPDSI](http://www.droughtmanagement.info/self-calibrated-palmer-drought-severity-index-sc-pdsi/),
25-
Self-calibrated Palmer Drought Severity Index
26-
- [PHDI](http://www.droughtmanagement.info/palmer-hydrological-drought-index-phdi/),
27-
Palmer Hydrological Drought Index
28-
- [Z-Index](http://www.droughtmanagement.info/palmer-z-index/),
29-
Palmer moisture anomaly index (Z-index)
30-
- [PMDI](https://climate.ncsu.edu/climate/climdiv), Palmer Modified
31-
Drought Index
32-
- [PNP](http://www.droughtmanagement.info/percent-of-normal-precipitation/),
33-
Percentage of Normal Precipitation
34-
35-
This Python implementation of the above climate index algorithms is being developed
15+
- [SPI](https://climatedataguide.ucar.edu/climate-data/standardized-precipitation-index-spi),
16+
Standardized Precipitation Index, utilizing both gamma and Pearson Type III distributions
17+
- [SPEI](https://www.researchgate.net/publication/252361460_The_Standardized_Precipitation-Evapotranspiration_Index_SPEI_a_multiscalar_drought_index),
18+
Standardized Precipitation Evapotranspiration Index, utilizing both gamma and Pearson Type III distributions
19+
- [PET](https://www.ncdc.noaa.gov/monitoring-references/dyk/potential-evapotranspiration), Potential Evapotranspiration, utilizing either [Thornthwaite](http://dx.doi.org/10.2307/21073)
20+
or [Hargreaves](http://dx.doi.org/10.13031/2013.26773) equations
21+
- [PDSI](http://www.droughtmanagement.info/palmer-drought-severity-index-pdsi/),
22+
Palmer Drought Severity Index
23+
- [scPDSI](http://www.droughtmanagement.info/self-calibrated-palmer-drought-severity-index-sc-pdsi/),
24+
Self-calibrated Palmer Drought Severity Index
25+
- [PHDI](http://www.droughtmanagement.info/palmer-hydrological-drought-index-phdi/),
26+
Palmer Hydrological Drought Index
27+
- [Z-Index](http://www.droughtmanagement.info/palmer-z-index/),
28+
Palmer moisture anomaly index (Z-index)
29+
- [PMDI](https://climate.ncsu.edu/climate/climdiv), Palmer Modified
30+
Drought Index
31+
- [PNP](http://www.droughtmanagement.info/percent-of-normal-precipitation/),
32+
Percentage of Normal Precipitation
33+
34+
This Python implementation of the above climate index algorithms is being developed
3635
with the following goals in mind:
3736

38-
- to provide an open source software package to compute a suite of
39-
climate indices commonly used for climate monitoring, with well
40-
documented code that is faithful to the relevant literature and
41-
which produces scientifically verifiable results
42-
- to provide a central, open location for participation and collaboration
43-
for researchers, developers, and users of climate indices
44-
- to facilitate standardization and consensus on best-of-breed
45-
climate index algorithms and corresponding compliant implementations in Python
46-
- to provide transparency into the operational code used for climate
47-
monitoring activities at NCEI/NOAA, and consequent reproducibility
48-
of published datasets computed from this package
49-
- to incorporate modern software engineering principles and programming
50-
best practices
51-
52-
53-
This is a developmental/forked version of code that is originally developed and
54-
maintained by NIDIS/NCEI/NOAA. The official release version is available at
37+
- to provide an open source software package to compute a suite of
38+
climate indices commonly used for climate monitoring, with well
39+
documented code that is faithful to the relevant literature and
40+
which produces scientifically verifiable results
41+
- to provide a central, open location for participation and collaboration
42+
for researchers, developers, and users of climate indices
43+
- to facilitate standardization and consensus on best-of-breed
44+
climate index algorithms and corresponding compliant implementations in Python
45+
- to provide transparency into the operational code used for climate
46+
monitoring activities at NCEI/NOAA, and consequent reproducibility
47+
of published datasets computed from this package
48+
- to incorporate modern software engineering principles and programming
49+
best practices
50+
51+
52+
This is a developmental/forked version of code that is originally developed and
53+
maintained by NIDIS/NCEI/NOAA. The official release version is available at
5554
[drought.gov](https://www.drought.gov/drought/python-climate-indices).
5655

57-
* [__Documentation__](https://climate-indices.readthedocs.io/en/latest/)
58-
* [__License__](LICENSE)
59-
* [__Disclaimer__](DISCLAIMER)
56+
- [__Documentation__](https://climate-indices.readthedocs.io/en/latest/)
57+
- [__License__](LICENSE)
58+
- [__Disclaimer__](DISCLAIMER)

scripts/process_divisions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,8 @@ def process_divisions(
535535

536536
# ----------------------------------------------------------------------------------------------------------------------
537537
if __name__ == "__main__":
538-
"""
539-
This module is used to perform climate indices processing on nClimGrid datasets in NetCDF.
540-
"""
538+
539+
# This module is used to perform climate indices processing on nClimGrid datasets in NetCDF.
541540

542541
try:
543542

scripts/process_grid.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,23 +1029,23 @@ def _parallel_process(index, arrays_dict, input_var_names, output_var_name, args
10291029
) as pool:
10301030

10311031
"""
1032-
the function _unpacking_apply_along_axis() being applied in Pool.map() is separate
1032+
the function _apply_along_axis() being applied in Pool.map() is separate
10331033
so that subprocesses can import it, and is simply a thin wrapper that handles the
10341034
fact that Pool.map() only takes a single argument:
10351035
"""
10361036

10371037
if index in ["spei", "pet"]:
1038-
pool.map(_unpacking_apply_along_axis_double, chunk_params)
1038+
pool.map(_apply_along_axis_double, chunk_params)
10391039
elif index == "palmers":
1040-
pool.map(_unpacking_apply_along_axis_palmers, chunk_params)
1040+
pool.map(_apply_along_axis_palmers, chunk_params)
10411041
else:
1042-
pool.map(_unpacking_apply_along_axis, chunk_params)
1042+
pool.map(_apply_along_axis, chunk_params)
10431043

10441044

10451045
# ------------------------------------------------------------------------------
1046-
def _unpacking_apply_along_axis(params):
1046+
def _apply_along_axis(params):
10471047
"""
1048-
Like numpy.apply_along_axis(), but and with arguments in a dict instead.
1048+
Like numpy.apply_along_axis(), but with arguments in a dict instead.
10491049
Applicable for applying a function across subarrays of a single input array.
10501050
10511051
This function is useful with multiprocessing.Pool().map(): (1) map() only
@@ -1075,9 +1075,9 @@ def _unpacking_apply_along_axis(params):
10751075

10761076

10771077
# ------------------------------------------------------------------------------
1078-
def _unpacking_apply_along_axis_double(params):
1078+
def _apply_along_axis_double(params):
10791079
"""
1080-
Like numpy.apply_along_axis(), but and with arguments in a dict instead.
1080+
Like numpy.apply_along_axis(), but with arguments in a dict instead.
10811081
Applicable for applying a function across subarrays of two input arrays.
10821082
10831083
This function is useful with multiprocessing.Pool().map(): (1) map() only
@@ -1130,9 +1130,9 @@ def _unpacking_apply_along_axis_double(params):
11301130

11311131

11321132
# ------------------------------------------------------------------------------
1133-
def _unpacking_apply_along_axis_palmers(params):
1133+
def _apply_along_axis_palmers(params):
11341134
"""
1135-
Like numpy.apply_along_axis(), but and with arguments in a dict instead.
1135+
Like numpy.apply_along_axis(), but with arguments in a dict instead.
11361136
Applicable for applying a function across subarrays of Palmer-specific
11371137
input arrays.
11381138
@@ -1249,21 +1249,20 @@ def _prepare_file(netcdf_file, var_name):
12491249

12501250
# ------------------------------------------------------------------------------
12511251
if __name__ == "__main__":
1252-
"""
1253-
This script is used to perform climate indices processing on NetCDF
1254-
gridded datasets.
1255-
1256-
Example command line arguments for SPI only using monthly precipitation input:
1257-
1258-
--index spi
1259-
--periodicity monthly
1260-
--scales 1 2 3 6 9 12 24
1261-
--calibration_start_year 1998
1262-
--calibration_end_year 2016
1263-
--netcdf_precip example_data/nclimgrid_prcp_lowres.nc
1264-
--var_name_precip prcp
1265-
--output_file_base ~/data/test/spi/nclimgrid_lowres
1266-
"""
1252+
1253+
# This script is used to perform climate indices processing on NetCDF
1254+
# gridded datasets.
1255+
#
1256+
# Example command line arguments for SPI only using monthly precipitation input:
1257+
#
1258+
# --index spi
1259+
# --periodicity monthly
1260+
# --scales 1 2 3 6 9 12 24
1261+
# --calibration_start_year 1998
1262+
# --calibration_end_year 2016
1263+
# --netcdf_precip example_data/nclimgrid_prcp_lowres.nc
1264+
# --var_name_precip prcp
1265+
# --output_file_base ~/data/test/spi/nclimgrid_lowres
12671266

12681267
try:
12691268

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ def palmer_pdsi_monthly():
284284
)
285285

286286

287+
@pytest.fixture(scope="module")
288+
def palmer_pdsi_from_scpdsi_monthly():
289+
290+
return np.load(
291+
os.path.join(
292+
os.path.split(__file__)[0], "fixture", "palmer_pdsi_from_scpdsi.npy"
293+
)
294+
)
295+
296+
287297
@pytest.fixture(scope="module")
288298
def palmer_phdi_monthly():
289299

11.7 KB
Binary file not shown.

tests/test_compute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
from climate_indices import compute
77

8-
# ----------------------------------------------------------------------------------------------------------------------
8+
# ------------------------------------------------------------------------------
99
# disable logging messages
1010
logging.disable(logging.CRITICAL)
1111

1212

13-
# ----------------------------------------------------------------------------------------
13+
# ------------------------------------------------------------------------------
1414
@pytest.mark.usefixtures(
1515
"precips_mm_monthly",
1616
"precips_mm_daily",

tests/test_eto.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
logging.disable(logging.CRITICAL)
1212

1313

14-
"""
15-
Tests for `eto.py`.
16-
"""
17-
18-
1914
# ------------------------------------------------------------------------------------------------------------------
2015
def test_eto_hargreaves():
2116

tests/test_indices.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
logging.disable(logging.CRITICAL)
1111

1212

13-
"""
14-
Tests for `indices.py`.
15-
"""
13+
# Tests for `climate_indices.indices.py`.
1614

1715

1816
# ---------------------------------------------------------------------------------------

tests/test_netcdf_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
logging.disable(logging.CRITICAL)
1111

1212

13-
"""
14-
Tests for `netcdf_utils.py`.
15-
"""
13+
# Tests for `scripts.netcdf_utils.py`
1614

1715

1816
# ---------------------------------------------------------------------------------------

tests/test_palmer.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
logging.disable(logging.CRITICAL)
1111

1212

13-
"""
14-
Tests for `palmer.py`.
15-
"""
13+
# Tests for `climate_indices.palmer.py`
1614

1715

1816
# ---------------------------------------------------------------------------------------
@@ -287,6 +285,7 @@ def test_cafec_compute_X(palmer_zindex_monthly):
287285
"data_year_start_monthly",
288286
"calibration_year_start_monthly",
289287
"calibration_year_end_monthly",
288+
"palmer_pdsi_from_scpdsi_monthly",
290289
"palmer_scpdsi_monthly",
291290
"palmer_scphdi_monthly",
292291
"palmer_scpmdi_monthly",
@@ -299,6 +298,7 @@ def test_scpdsi(
299298
data_year_start_monthly,
300299
calibration_year_start_monthly,
301300
calibration_year_end_monthly,
301+
palmer_pdsi_from_scpdsi_monthly,
302302
palmer_scpdsi_monthly,
303303
palmer_scphdi_monthly,
304304
palmer_scpmdi_monthly,
@@ -325,6 +325,14 @@ def test_scpdsi(
325325
err_msg="PDSI not computed as expected from monthly inputs",
326326
)
327327

328+
np.testing.assert_allclose(
329+
pdsi,
330+
palmer_pdsi_from_scpdsi_monthly,
331+
atol=0.001,
332+
equal_nan=True,
333+
err_msg="PDSI not computed as expected from monthly inputs",
334+
)
335+
328336
np.testing.assert_allclose(
329337
phdi,
330338
palmer_scphdi_monthly,

0 commit comments

Comments
 (0)