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 31, 2024
2 parents d68fb54 + 2858aec commit f9f0692
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ changelog:
- title: New Features
labels:
- changelog-enhancement
- title: Bug Fixes
labels:
- bug
- title: Other Changes
labels:
- "*"
2 changes: 1 addition & 1 deletion .github/workflows/link_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Verify Linked Issue
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
# 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
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ jobs:
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
build-for-prefix:
name: Build prefix package
needs:
- build
- install
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Download the built dist
uses: actions/download-artifact@v4
with:
name: pip-dist
path: dist/
- name: Add tag to recipe
run: sed -i "s/TAG_VERSION/${{ github.ref_name }}/g" publish/recipes/release/ecoscope.yaml
- name: Add dist to recipe
run: sed -i "s/DIST_NAME/$(find ./dist/*.tar.gz -printf "%f\n")/g" publish/recipes/release/ecoscope.yaml
- name: Log the generated recipe
run: cat publish/recipes/release/ecoscope.yaml
- name: Create channel
run: mkdir -p /tmp/ecoscope/release/artifacts
- name: Build prefix release
uses: prefix-dev/[email protected]
with:
recipe-path: publish/recipes/release/ecoscope.yaml
build-args: --output-dir /tmp/ecoscope/release/artifacts --channel https://prefix.dev/ecoscope-workflows --channel conda-forge
- run: |
for file in /tmp/ecoscope/release/artifacts/**/*.conda; do
rattler-build upload prefix -c ecoscope-workflows "$file"
done
env:
PREFIX_API_KEY: ${{ secrets.PREFIX_API_KEY }}
publish-to-pypi:
name: Publish to PyPI
needs:
Expand Down
2 changes: 1 addition & 1 deletion 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].5' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /dev/null"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion 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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /dev/null"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion 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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /dev/null"
]
},
{
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].5' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /dev/null"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion 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].5' &> /dev/null"
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /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].5' &> /dev/null"
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected].8' &> /dev/null"
]
},
{
Expand Down
8 changes: 8 additions & 0 deletions ecoscope/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def _create_trajsegments(gdf):
"heading": track_properties.heading,
"geometry": shapely.linestrings(coords),
"junk_status": gdf.junk_status,
"nsd": track_properties.nsd,
},
crs=4326,
index=gdf.index,
Expand Down Expand Up @@ -625,6 +626,13 @@ def dist_meters(self):
_, _, distance = self.inverse_transformation
return distance

@property
def nsd(self):
start_point = df["geometry"].iloc[0]
geod = Geod(ellps="WGS84")
geod_displacement = [geod.inv(start_point.x, start_point.y, geo.x, geo.y)[2] for geo in df["_geometry"]]
return [(x**2) / (1000 * 2) for x in geod_displacement]

@property
def timespan_seconds(self):
return (df["_fixtime"] - df["fixtime"]).dt.total_seconds()
Expand Down
23 changes: 23 additions & 0 deletions ecoscope/io/async_earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ecoscope
from ecoscope.io.utils import to_hex
from ecoscope.io.earthranger_utils import clean_kwargs, to_gdf, clean_time_cols
from erclient.client import ERClientException, ERClientNotFound

try:
from erclient.client import AsyncERClient
Expand All @@ -30,6 +31,28 @@ def __init__(self, sub_page_size=4000, tcp_limit=5, **kwargs):
kwargs["client_id"] = kwargs.get("client_id", "das_web_client")
super().__init__(**kwargs)

@classmethod
async def create(cls, **kwargs):
client = cls(**kwargs)

await client._init_client()
return client

async def _init_client(self):
if not self.auth:
try:
await self.login()
except ERClientNotFound:
raise ERClientNotFound("Failed login. Check Stack Trace for specific reason.")
else:
try:
await self.get_me()
except ERClientException:
raise ERClientException("Authorization token is invalid or expired.")

async def get_me(self):
return await self._get("user/me", params={})

async def get_sources(
self,
manufacturer_id=None,
Expand Down
19 changes: 13 additions & 6 deletions ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,29 @@ def __init__(self, sub_page_size=4000, tcp_limit=5, **kwargs):
self.tcp_limit = tcp_limit
kwargs["client_id"] = kwargs.get("client_id", "das_web_client")
super().__init__(**kwargs)
try:
self.login()
except ERClientNotFound:
raise ERClientNotFound("Failed login. Check Stack Trace for specific reason.")

if not self.auth:
try:
self.login()
except ERClientNotFound:
raise ERClientNotFound("Failed login. Check Stack Trace for specific reason.")
else:
try:
self.get_me()
except ERClientException:
raise ERClientException("Authorization token is invalid or expired.")

def _token_request(self, payload):
response = requests.post(self.token_url, data=payload)
if response.ok:
self.auth = json.loads(response.text)
self.auth = response.json()
expires_in = int(self.auth["expires_in"]) - 5 * 60
self.auth_expires = pytz.utc.localize(datetime.datetime.utcnow()) + datetime.timedelta(seconds=expires_in)
return True

self.auth = None
self.auth_expires = pytz.utc.localize(datetime.datetime.min)
raise ERClientNotFound(json.loads(response.text)["error_description"])
raise ERClientNotFound(response.json().get("error_description", "invalid token"))

"""
GET Functions
Expand Down
3 changes: 2 additions & 1 deletion ecoscope/mapping/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def pil_layer(image, bounds, opacity=1):
return layer

@staticmethod
def get_named_tile_layer(layer: str) -> BitmapTileLayer:
def get_named_tile_layer(layer: str, opacity: float = 1) -> BitmapTileLayer:
# From Leafmap
# https://github.com/opengeos/leafmap/blob/master/leafmap/basemaps.py
xyz_tiles = {
Expand Down Expand Up @@ -534,6 +534,7 @@ def get_named_tile_layer(layer: str) -> BitmapTileLayer:
max_zoom=layer.get("max_zoom", None),
min_zoom=layer.get("min_zoom", None),
max_requests=layer.get("max_requests", None),
opacity=opacity,
)

def to_html(
Expand Down
73 changes: 73 additions & 0 deletions publish/recipes/release/ecoscope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
context:
name: ecoscope
version: TAG_VERSION

package:
name: ecoscope
version: ${{ version }}

source:
path: ../../../dist/DIST_NAME

build:
noarch: python
script: SETUPTOOLS_SCM_PRETEND_VERSION=${{ version }} pip install . -v
number: 5

requirements:
host:
- python
- setuptools >=45
- setuptools-scm >=6.2
- pip
run:
- python
- backoff
- earthengine-api
- earthranger-client
- fiona <1.10.0
- geopandas <=0.14.2
- numpy <2 # added by me, but should be ensured by geopandas anyway
- pyproj
- rasterio
- tqdm
# ~ analysis ~
- astroplan
# - datashader # (cisaacstern) per atmorling, not required for current workflows
- igraph
- mapclassify
# - matplotlib # disabling in favor of matplotlib-base which is smaller
- matplotlib-base
- networkx
- numba
- scipy
- scikit-image
- scikit-learn
# ~ plotting ~
# - kaleido # not available on conda and do we actually use this?
- plotly
# - scikit-learn # duplicate with analysis
# ~ mapping ~
- lonboard==0.0.3
# - matplotlib # duplicate with analysis
# - mapclassify # duplicate with analysis

tests:
- python:
imports:
- ecoscope
- ecoscope.analysis
- ecoscope.base
- ecoscope.io
- ecoscope.mapping
- ecoscope.plotting

about:
summary: Standard Analytical Reporting Framework for Conservation
license: BSD-3-Clause
license_file: LICENSE

extra:
recipe-maintainers:
- cisaacstern
- atmorling
Loading

0 comments on commit f9f0692

Please sign in to comment.