Skip to content

Commit

Permalink
Ensure offsets and scales are lists of floats (#12)
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
chuckwondo authored Jun 17, 2024
1 parent 627a3a5 commit 35d49ac
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hls_vi/generate_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 35d49ac

Please sign in to comment.