From 35d49ac58a39e09b4b9d8d52775eb8cdd7ec135a Mon Sep 17 00:00:00 2001 From: Chuck Daniels Date: Mon, 17 Jun 2024 11:40:07 -0400 Subject: [PATCH] Ensure offsets and scales are lists of floats (#12) Fixes #3 --- hls_vi/generate_indices.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hls_vi/generate_indices.py b/hls_vi/generate_indices.py index 1b575bf..44fed5f 100644 --- a/hls_vi/generate_indices.py +++ b/hls_vi/generate_indices.py @@ -7,7 +7,7 @@ from datetime import datetime, timezone from enum import Enum, unique from pathlib import Path -from typing import Callable, Mapping, Optional, Tuple, Type +from typing import Callable, Mapping, Optional, SupportsFloat, Tuple, Type from typing_extensions import TypeAlias import matplotlib.pyplot as plt @@ -330,9 +330,9 @@ class Index(Enum): NDVI = ("Normalized Difference Vegetation Index",) NDWI = ("Normalized Difference Water Index",) SAVI = ("Soil-Adjusted Vegetation Index",) - TVI = ("Triangular Vegetation Index", 1) + TVI = ("Triangular Vegetation Index", 1.0) - def __init__(self, long_name: str, scale_factor: float = 0.0001) -> None: + def __init__(self, long_name: str, scale_factor: SupportsFloat = 0.0001) -> None: function_name = self.name.lower() index_function: Optional[IndexFunction] = globals().get(function_name) @@ -341,7 +341,7 @@ def __init__(self, long_name: str, scale_factor: float = 0.0001) -> None: self.long_name = long_name self.compute_index = index_function - self.scale_factor = scale_factor + self.scale_factor = float(scale_factor) def __call__(self, data: BandData) -> np.ma.masked_array: scaled_index = self.compute_index(data) / self.scale_factor