Skip to content

Commit

Permalink
Ensure scales are floats
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
chuckwondo committed Jun 17, 2024
1 parent 627a3a5 commit eb402ec
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 @@ -8,7 +8,7 @@
from enum import Enum, unique
from pathlib import Path
from typing import Callable, Mapping, Optional, Tuple, Type
from typing_extensions import TypeAlias
from typing_extensions import SupportsFloat, TypeAlias

import matplotlib.pyplot as plt
import numpy as np
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 eb402ec

Please sign in to comment.