Skip to content

Commit

Permalink
Merge branch 'master' into am/classifier_labels
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling authored Oct 15, 2024
2 parents 510771e + 9eee138 commit bfa2f99
Show file tree
Hide file tree
Showing 29 changed files with 334 additions and 134 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
shell: bash -leo pipefail {0}
strategy:
fail-fast: false
matrix:
Expand All @@ -23,9 +23,13 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v1.9.0
with:
# https://github.com/mamba-org/setup-micromamba/issues/227
micromamba-version: 1.5.10-0
environment-file: ${{ matrix.env }}
cache-environment: true
cache-downloads: true

- name: Test
env:
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
commit_id = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).strip().decode("ascii")
nbsphinx_prolog = f"""
.. image:: https://colab.research.google.com/assets/colab-badge.svg
:target: {{{{ "https://githubtocolab.com/wildlife-dynamics/ecoscope/blob/{commit_id}/doc/source/" + env.docname|urlencode + ".ipynb" }}}}
:target: {{{{ "https://colab.research.google.com/github/wildlife-dynamics/ecoscope/blob/{commit_id}/doc/source/" + env.docname|urlencode + ".ipynb" }}}}
----
""" # noqa
18 changes: 9 additions & 9 deletions doc/source/notebooks/01. IO/EarthRanger_IO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -614,7 +614,11 @@
"metadata": {},
"outputs": [],
"source": [
"patrol_df = er_io.get_patrols()\n",
"patrol_df = er_io.get_patrols(\n",
" since=pd.Timestamp(\"2017-01-01\").isoformat(),\n",
" until=pd.Timestamp(\"2017-04-01\").isoformat(),\n",
")\n",
"\n",
"\n",
"relocs = er_io.get_patrol_observations(\n",
" patrol_df,\n",
Expand Down Expand Up @@ -709,8 +713,8 @@
")\n",
"\n",
"if not elephants.empty:\n",
" for i, value in elephants.iterrows():\n",
" er_io.delete_observation(observation_id=elephants.loc[i, \"extra__id\"])"
" for observation_id in elephants[\"extra__id\"].unique():\n",
" er_io.delete_observation(observation_id)"
]
},
{
Expand Down Expand Up @@ -863,11 +867,7 @@
"metadata": {},
"outputs": [],
"source": [
"relocs.drop(\n",
" columns=relocs.columns[relocs.applymap(lambda x: isinstance(x, list)).any()],\n",
" errors=\"ignore\",\n",
" inplace=True,\n",
")\n",
"relocs = relocs.select_dtypes(exclude=[list])\n",
"\n",
"relocs.to_file(os.path.join(output_dir, \"observations.gpkg\"), layer=\"observations\")"
]
Expand Down
22 changes: 2 additions & 20 deletions doc/source/notebooks/01. IO/GEE_IO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand All @@ -38,7 +38,6 @@
"source": [
"import os\n",
"import sys\n",
"import zipfile\n",
"\n",
"import shapely\n",
"\n",
Expand Down Expand Up @@ -208,26 +207,9 @@
"ecoscope.io.utils.download_file(\n",
" url=img.getDownloadUrl(download_config),\n",
" path=img_zip_file,\n",
" unzip=True,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Unzip"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with zipfile.ZipFile(img_zip_file) as z:\n",
" for name in z.namelist():\n",
" z.extract(name, output_dir)"
]
}
],
"metadata": {
Expand Down
20 changes: 2 additions & 18 deletions doc/source/notebooks/01. IO/Landscape Dynamics Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand All @@ -40,7 +40,6 @@
"source": [
"import os\n",
"import sys\n",
"import zipfile\n",
"\n",
"import geopandas as gpd\n",
"\n",
Expand Down Expand Up @@ -90,25 +89,10 @@
" url=\"https://maraelephant.maps.arcgis.com/sharing/rest/content/items/162e299f0c7d472b8e36211e946bb273/data\",\n",
" path=output_dir,\n",
" overwrite_existing=False,\n",
" unzip=True,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extract ZIP"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"zipfile.ZipFile(os.path.join(output_dir, \"active_public_uncategorized_shpfiles.zip\")).extractall(path=output_dir)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -252,7 +252,7 @@
"metadata": {},
"outputs": [],
"source": [
"relocs[[\"groupby_col\", \"fixtime\", \"geometry\"]].explore()"
"relocs[[\"groupby_col\", \"geometry\"]].explore()"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -152,7 +152,7 @@
"metadata": {},
"outputs": [],
"source": [
"traj.explore()"
"traj[\"geometry\"].explore()"
]
},
{
Expand Down Expand Up @@ -546,7 +546,7 @@
" individual=\"1d22ff96-44d4-45c4-adc3-db1513acbe7d\",\n",
" interpolation=\"dofjojfs\",\n",
" )\n",
"except NotImplemented as e:\n",
"except NotImplementedError as e:\n",
" print(e)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/source/notebooks/04. EcoMap & EcoPlot/EcoMap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions doc/source/notebooks/04. EcoMap & EcoPlot/EcoPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -98,7 +98,6 @@
"ecoscope.io.download_file(\n",
" f\"{ECOSCOPE_RAW}/tests/sample_data/vector/er_relocs.csv.zip\",\n",
" os.path.join(output_dir, \"er_relocs.csv.zip\"),\n",
" unzip=False,\n",
")\n",
"\n",
"data = pd.read_csv(os.path.join(output_dir, \"er_relocs.csv.zip\"), header=0, index_col=0)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"ECOSCOPE_RAW = \"https://raw.githubusercontent.com/wildlife-dynamics/ecoscope/master\"\n",
"\n",
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].3' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].5' &> /dev/null"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions ecoscope/analysis/astronomy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import warnings

import numpy as np
import pyproj
import pandas as pd
import pyproj

try:
import astroplan
Expand Down Expand Up @@ -109,4 +110,4 @@ def get_daynight_ratio(traj, n_grid_points=150) -> pd.Series:
day_distance += (day_night_df.dist_meters * i).sum()
night_distance += ((1 - i) * day_night_df.dist_meters).sum()

return day_distance / night_distance
return night_distance / day_distance
15 changes: 13 additions & 2 deletions ecoscope/analysis/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,22 @@ def apply_color_map(dataframe, input_column_name, cmap, output_column_name=None)
cmap = mpl.colormaps[cmap]
cmap = cmap.resampled(dataframe[input_column_name].nunique())

cmap_colors = cmap(range(dataframe[input_column_name].nunique()))
if pd.api.types.is_numeric_dtype(dataframe[input_column_name].dtype):
cmap_colors = []
val_min = dataframe[input_column_name].min()
val_max = dataframe[input_column_name].max()
for val in dataframe[input_column_name].unique():
cmap_colors.append(cmap((val - val_min) / (val_max - val_min)))
else:
cmap_colors = cmap(range(len(dataframe[input_column_name].unique())))

color_list = []
for color in cmap_colors:
color_list.append(tuple([round(val * 255) for val in color]))

# convert to hex first to put values in range(0,255), then to an RGBA tuple
cmap = pd.Series(
[hex_to_rgba(mpl.colors.to_hex(color)) for color in cmap_colors],
color_list,
index=dataframe[input_column_name].unique(),
)

Expand Down
2 changes: 1 addition & 1 deletion ecoscope/analysis/ecograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def compute(df):
G = self._get_ecograph(df, subject_name, radius, cutoff, tortuosity_length)
self.graphs[subject_name] = G

self.trajectory.groupby("groupby_col")[self.trajectory.columns].progress_apply(compute)
self.trajectory.groupby("groupby_col")[self.trajectory.columns].apply(compute)

def to_csv(self, output_path):
"""
Expand Down
5 changes: 4 additions & 1 deletion ecoscope/analysis/feature_density.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy as np


def calculate_feature_density(selection, grid, geometry_type="point"):
def clip_density(cell):
if geometry_type == "point":
Expand All @@ -12,5 +15,5 @@ def clip_density(cell):
raise ValueError("Unsupported geometry type")

grid["density"] = grid.geometry.apply(clip_density)
# grid["density"] = grid["density"].replace(0, np.nan) # Set 0's to nan so they don't draw on map
grid["density"] = grid["density"].replace(0, np.nan) # Set 0's to nan so they don't draw on map
return grid
Loading

0 comments on commit bfa2f99

Please sign in to comment.