Skip to content

Commit

Permalink
Fix ETD calculation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Wu committed Jan 22, 2025
1 parent 1f52997 commit 0c3a664
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
11 changes: 8 additions & 3 deletions ecoscope/analysis/UD/etd_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
from dataclasses import dataclass

import numpy as np

from ecoscope.base import Trajectory
from ecoscope.io import raster

try:
import numba as nb
import scipy
from sklearn import neighbors
from scipy.optimize import minimize
from scipy.stats import weibull_min
from sklearn import neighbors
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Missing optional dependencies required by this module. \
Expand Down Expand Up @@ -169,8 +170,12 @@ def calculate_etd_range(
grid_centroids[1, 0] = y_max - raster_profile.pixel_size * 0.5

centroids_coords = np.dot(grid_centroids, np.mgrid[1:2, :num_columns, :num_rows].T.reshape(-1, 3, 1))
centroids_coords = centroids_coords.squeeze().T

if centroids_coords.ndim != 2:
centroids_coords = centroids_coords.reshape(1, -1)

tr = neighbors.KDTree(centroids_coords.squeeze().T)
tr = neighbors.KDTree(centroids_coords)

del centroids_coords

Expand Down Expand Up @@ -207,7 +212,7 @@ def calculate_etd_range(
raster_ndarray = raster_ndarray / raster_ndarray.sum()

# Set the null data values
raster_ndarray[raster_ndarray == 0] = raster_profile.nodata_value
raster_ndarray[np.isnan(raster_ndarray) | (raster_ndarray == 0)] = raster_profile.nodata_value

# write raster_ndarray to GeoTIFF file.
raster.RasterPy.write(
Expand Down
4 changes: 4 additions & 0 deletions ecoscope/analysis/percentile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def calculate_percentile_area(cls, profile: PercentileAreaProfile):
# calculate percentile value
# percentile_val = np.percentile(data_array[~np.isnan(data_array)], 100.0 - percentile)
values = np.sort(data_array[~np.isnan(data_array)]).flatten()

if len(values) == 0:
continue

csum = np.cumsum(values)
percentile_val = values[np.argmin(np.abs(csum[-1] * (1 - percentile / 100) - csum))]

Expand Down
2 changes: 1 addition & 1 deletion ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ def upload(obs):
"records"
)
del obs["geometry"]
obs = pack_columns(obs, columns=["source", "recorded_at", "location"])
obs = pack_columns(obs, columns=["source", "recorded_at", "location", "exclusion_flags", "additional"])
post_data = obs.to_dict("records")
results = super(EarthRangerIO, self).post_observation(post_data)
except ERClientException as exc:
Expand Down
2 changes: 1 addition & 1 deletion ecoscope/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def draw_historic_timeseries(
The title shown in the plot legend for historic band
historic_mean_column: str
The name of the dataframe column to pull historic mean values from
current_value_title: str
historic_mean_title: str
The title shown in the plot legend for historic mean values
layout_kwargs: dict
Additional kwargs passed to plotly.go.Figure(layout)
Expand Down

0 comments on commit 0c3a664

Please sign in to comment.