From b8a93d80047b92814b3b713e7e8f6c28c334b675 Mon Sep 17 00:00:00 2001 From: davemlz Date: Sat, 8 Oct 2022 14:17:20 +0200 Subject: [PATCH] FORMAT: Black --- .../update_awesome_spectral_indices.py | 2 +- spyndex/axioms.py | 48 +++++++++---------- tests/test_spyndex.py | 20 ++++---- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/.github/scripts/update_awesome_spectral_indices.py b/.github/scripts/update_awesome_spectral_indices.py index ee1bd6a..fc57a52 100755 --- a/.github/scripts/update_awesome_spectral_indices.py +++ b/.github/scripts/update_awesome_spectral_indices.py @@ -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) \ No newline at end of file + json.dump(bands, fp, indent=4, sort_keys=True) diff --git a/spyndex/axioms.py b/spyndex/axioms.py index 91622e9..03c0443 100644 --- a/spyndex/axioms.py +++ b/spyndex/axioms.py @@ -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): @@ -28,7 +28,7 @@ def __repr__(self): def __str__(self): """Human readable output of the Spectral Indices object.""" - + return f"{list(self.keys())}" @@ -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"] @@ -95,7 +95,7 @@ def __repr__(self): * Bands/Parameters: {self.bands} * Formula: {self.formula} * Reference: {self.reference} - """ + """ return result @@ -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: @@ -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(): @@ -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() @@ -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 @@ -196,7 +196,7 @@ def __repr__(self): def __str__(self): """Human readable output of the Constant.""" - + return f"{list(self.keys())}" @@ -240,7 +240,6 @@ 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.""" @@ -248,7 +247,7 @@ def __repr__(self): * Band: {self.band} * Center Wavelength (nm): {self.wavelength} * Bandwidth (nm): {self.bandwidth} - """ + """ return result @@ -259,7 +258,7 @@ def __str__(self): * Band: {self.band} * Center Wavelength (nm): {self.wavelength} * Bandwidth (nm): {self.bandwidth} - """ + """ return result @@ -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 @@ -328,12 +327,11 @@ 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 @@ -341,7 +339,7 @@ def __str__(self): """Human readable output of the Constant.""" result = f"""{self.short_name}: {self.long_name} - """ + """ return result @@ -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() @@ -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 @@ -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 @@ -440,7 +438,7 @@ def __repr__(self): result = f"""Constant({self.short_name}: {self.long_name}) * Default value: {self.default} - """ + """ return result @@ -449,7 +447,7 @@ def __str__(self): result = f"""{self.short_name}: {self.long_name} * Default value: {self.default} - """ + """ return result @@ -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() diff --git a/tests/test_spyndex.py b/tests/test_spyndex.py index 371ab30..ee8826a 100644 --- a/tests/test_spyndex.py +++ b/tests/test_spyndex.py @@ -81,8 +81,8 @@ 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) @@ -90,14 +90,14 @@ 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)