Skip to content

Commit

Permalink
FORMAT: Black
Browse files Browse the repository at this point in the history
  • Loading branch information
davemlz committed Oct 8, 2022
1 parent 03d39ee commit b8a93d8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/update_awesome_spectral_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
).json()
# Save the dict as json file
with open("./spyndex/data/bands.json", "w") as fp:
json.dump(bands, fp, indent=4, sort_keys=True)
json.dump(bands, fp, indent=4, sort_keys=True)
48 changes: 23 additions & 25 deletions spyndex/axioms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from box import Box

from .utils import _get_indices, _load_JSON
from .spyndex import computeIndex
from .utils import _get_indices, _load_JSON


class SpectralIndices(Box):
Expand All @@ -28,7 +28,7 @@ def __repr__(self):

def __str__(self):
"""Human readable output of the Spectral Indices object."""

return f"{list(self.keys())}"


Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, index: dict):
self.reference = index["reference"]
"""URL to the reference/DOI of the Spectral Index."""

self.formula = index["formula"].replace(" ","")
self.formula = index["formula"].replace(" ", "")
"""Formula (as expression) of the Spectral Index."""

self.date_of_addition = index["date_of_addition"]
Expand All @@ -95,7 +95,7 @@ def __repr__(self):
* Bands/Parameters: {self.bands}
* Formula: {self.formula}
* Reference: {self.reference}
"""
"""

return result

Expand All @@ -107,18 +107,18 @@ def __str__(self):
* Bands/Parameters: {self.bands}
* Formula: {self.formula}
* Reference: {self.reference}
"""
"""

return result

def compute(self, params = None, **kwargs):
def compute(self, params=None, **kwargs):
"""Computes a Spectral Index.
Parameters
----------
params: dict
Parameters used as inputs for the computation. The input data must be
compatible with Overloaded Operators. Some inputs' types supported are pandas
Parameters used as inputs for the computation. The input data must be
compatible with Overloaded Operators. Some inputs' types supported are pandas
series, numpy arrays, xarray objects and numeric objects. Earth Engine objects
are also compatible when using eemont.
kwargs:
Expand Down Expand Up @@ -154,7 +154,7 @@ def compute(self, params = None, **kwargs):
else:
parameters = params

return computeIndex(self.short_name,parameters)
return computeIndex(self.short_name, parameters)


def _create_indices():
Expand All @@ -165,7 +165,7 @@ def _create_indices():
for key, value in indices.items():
indices_class[key] = SpectralIndex(value)

return SpectralIndices(indices_class,frozen_box = True)
return SpectralIndices(indices_class, frozen_box=True)


indices = _create_indices()
Expand All @@ -174,7 +174,7 @@ def _create_indices():
class Bands(Box):
"""Bands object.
This object allows interaction with the list of bands required for the Spectral
This object allows interaction with the list of bands required for the Spectral
Indices in the Awesome Spectral Indices list.
See Also
Expand All @@ -196,7 +196,7 @@ def __repr__(self):

def __str__(self):
"""Human readable output of the Constant."""

return f"{list(self.keys())}"


Expand Down Expand Up @@ -240,15 +240,14 @@ def __init__(self, platform_band: dict):
self.bandwidth = platform_band["bandwidth"]
"""Bandwidth of the Band (in nm) for the specific Platform."""


def __repr__(self):
"""Machine readable output of the Band."""

result = f"""PlatformBand(Platform: {self.platform}, Band: {self.name})
* Band: {self.band}
* Center Wavelength (nm): {self.wavelength}
* Bandwidth (nm): {self.bandwidth}
"""
"""

return result

Expand All @@ -259,7 +258,7 @@ def __str__(self):
* Band: {self.band}
* Center Wavelength (nm): {self.wavelength}
* Bandwidth (nm): {self.bandwidth}
"""
"""

return result

Expand All @@ -268,7 +267,7 @@ class Band(object):
"""Band object.
This object allows interaction with specific bands in the the list of required bands
for the Spectral Indices in the Awesome Spectral Indices list. Attributes of the
for the Spectral Indices in the Awesome Spectral Indices list. Attributes of the
Band can be accessed using this object.
See Also
Expand Down Expand Up @@ -328,20 +327,19 @@ def __init__(self, band: dict):
self.modis = PlatformBand(band["modis"])
"""Description of the band for the MODIS platform."""


def __repr__(self):
"""Machine readable output of the Band."""

result = f"""Band({self.short_name}: {self.long_name})
"""
"""

return result

def __str__(self):
"""Human readable output of the Constant."""

result = f"""{self.short_name}: {self.long_name}
"""
"""

return result

Expand All @@ -354,7 +352,7 @@ def _create_bands():
for key, value in bands.items():
bands_class[key] = Band(value)

return Bands(bands_class,frozen_box = True)
return Bands(bands_class, frozen_box=True)


bands = _create_bands()
Expand All @@ -363,7 +361,7 @@ def _create_bands():
class Constants(Box):
"""Constants object.
This object allows interaction with the list of constants of the Spectral Indices in
This object allows interaction with the list of constants of the Spectral Indices in
the Awesome Spectral Indices list.
See Also
Expand Down Expand Up @@ -395,7 +393,7 @@ class Constant(object):
"""Constant object.
This object allows interaction with specific constants in the the list of constants of
the Spectral Indices in the Awesome Spectral Indices list. Attributes of the
the Spectral Indices in the Awesome Spectral Indices list. Attributes of the
Constant can be accessed using this object.
See Also
Expand Down Expand Up @@ -440,7 +438,7 @@ def __repr__(self):

result = f"""Constant({self.short_name}: {self.long_name})
* Default value: {self.default}
"""
"""

return result

Expand All @@ -449,7 +447,7 @@ def __str__(self):

result = f"""{self.short_name}: {self.long_name}
* Default value: {self.default}
"""
"""

return result

Expand All @@ -462,7 +460,7 @@ def _create_constants():
for key, value in constants.items():
constants_class[key] = Constant(value)

return Constants(constants_class,frozen_box = True)
return Constants(constants_class, frozen_box=True)


constants = _create_constants()
20 changes: 10 additions & 10 deletions tests/test_spyndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ def test_numeric_class(self):
def test_numeric_class_kwargs(self):
"""Test the computeIndex() method"""
result = spyndex.indices.NDVI.compute(
N = 0.6,
R = 0.1,
N=0.6,
R=0.1,
)
self.assertIsInstance(result, float)

def test_numeric_kwargs(self):
"""Test the computeIndex() method"""
result = spyndex.computeIndex(
indices,
N = 0.6,
R = 0.1,
G = 0.3,
B = 0.1,
L = spyndex.constants.L.default,
C1 = spyndex.constants.C1.default,
C2 = spyndex.constants.C2.default,
g = spyndex.constants.g.default,
N=0.6,
R=0.1,
G=0.3,
B=0.1,
L=spyndex.constants.L.default,
C1=spyndex.constants.C1.default,
C2=spyndex.constants.C2.default,
g=spyndex.constants.g.default,
)
self.assertIsInstance(result, list)
self.assertIsInstance(result[0], float)
Expand Down

0 comments on commit b8a93d8

Please sign in to comment.