Skip to content

Commit

Permalink
unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Wu committed Dec 18, 2024
1 parent 87332c6 commit a5e167d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
11 changes: 5 additions & 6 deletions ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import math
import typing

import ecoscope
import geopandas as gpd
import numpy as np
import pandas as pd
import pytz
import requests
from erclient.client import ERClient, ERClientException, ERClientNotFound
from shapely.geometry import shape
from tqdm.auto import tqdm

import ecoscope
from ecoscope.io.earthranger_utils import (
clean_kwargs,
clean_time_cols,
dataframe_to_dict,
format_iso_time,
pack_columns,
to_gdf,
to_hex,
pack_columns,
)
from erclient.client import ERClient, ERClientException, ERClientNotFound
from shapely.geometry import shape
from tqdm.auto import tqdm


class EarthRangerIO(ERClient):
Expand Down
52 changes: 49 additions & 3 deletions tests/test_ecoplot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import pytest
import numpy as np
import pandas as pd
from ecoscope.plotting.plot import EcoPlotData, ecoplot, mcp, nsd, speed, stacked_bar_chart, pie_chart
from ecoscope.base import Trajectory
import pytest

from ecoscope.analysis.classifier import apply_color_map
from ecoscope.base import Trajectory
from ecoscope.plotting.plot import (
EcoPlotData,
draw_historic_timeseries,
ecoplot,
mcp,
nsd,
pie_chart,
speed,
stacked_bar_chart,
)


@pytest.fixture
Expand Down Expand Up @@ -175,3 +185,39 @@ def test_pie_chart_numerical(chart_df):
"rgba(0, 0, 255, 1.0)",
"rgba(255, 255, 255, 1.0)",
)


def test_draw_historic_timeseries():
df = pd.DataFrame(
{
"min": [0.351723, 0.351723, 0.303219, 0.303219, 0.342149, 0.342149],
"max": [0.667335, 0.667335, 0.708183, 0.708183, 0.727095, 0.727095],
"mean": [0.472017, 0.472017, 0.543062, 0.543062, 0.555547, 0.555547],
"NDVI": [0.609656, 0.671868, 0.680008, 0.586662, 0.612170, np.nan],
"img_date": pd.to_datetime(
[
"2023-11-09",
"2023-11-25",
"2023-12-11",
"2023-12-27",
"2024-01-09",
"2024-01-25",
]
),
}
)

chart = draw_historic_timeseries(
df,
current_value_column="NDVI",
current_value_title="NDVI",
historic_min_column="min",
historic_max_column="max",
historic_mean_column="mean",
)

assert len(chart.data) == 4
assert chart.data[0].showlegend is False
assert chart.data[1].name == "Historic Min-Max"
assert chart.data[2].name == "Historic Mean"
assert chart.data[3].name == "NDVI"

0 comments on commit a5e167d

Please sign in to comment.