From 6d8cf36c02a10861bb5b502b5397dbb5b60b88d2 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 6 Dec 2023 15:20:42 +0300 Subject: [PATCH] remove remaining collar voltage code from core library --- ecoscope/io/utils.py | 23 -- ecoscope/plotting/__init__.py | 2 - ecoscope/plotting/plot.py | 44 ---- notebooks/01. IO/EarthRanger_IO.ipynb | 10 +- .../06. Data Management/Collar Voltage.ipynb | 204 ------------------ 5 files changed, 3 insertions(+), 280 deletions(-) delete mode 100644 notebooks/06. Data Management/Collar Voltage.ipynb diff --git a/ecoscope/io/utils.py b/ecoscope/io/utils.py index 51ea6f9c..cf850e8c 100644 --- a/ecoscope/io/utils.py +++ b/ecoscope/io/utils.py @@ -25,29 +25,6 @@ def pack_columns(dataframe: pd.DataFrame, columns: typing.List): return dataframe -def extract_voltage(s: typing.Dict): - """ - Extracts voltage from different source-provider in EarthRanger - Parameters - ---------- - s: typing.Dict - - Returns - ------- - typing.Any - - """ - additional = s["extra__observation_details"] or {} - voltage = additional.get("battery", None) # savannah tracking - if not voltage: - voltage = additional.get("mainVoltage", None) # vectronics - if not voltage: - voltage = additional.get("batt", None) # AWT - if not voltage: - voltage = additional.get("power", None) # Followit - return voltage - - def download_file(url, path, overwrite_existing=False, chunk_size=1024, **request_kwargs): r = requests.get(url, stream=True, **request_kwargs) diff --git a/ecoscope/plotting/__init__.py b/ecoscope/plotting/__init__.py index 52ec3e00..23d6dd37 100644 --- a/ecoscope/plotting/__init__.py +++ b/ecoscope/plotting/__init__.py @@ -1,7 +1,6 @@ from ecoscope.plotting.plot import ( EcoPlotData, add_seasons, - collar_event_timeline, ecoplot, mcp, nsd, @@ -12,7 +11,6 @@ __all__ = [ "EcoPlotData", "add_seasons", - "collar_event_timeline", "ecoplot", "mcp", "nsd", diff --git a/ecoscope/plotting/plot.py b/ecoscope/plotting/plot.py index ec743533..60a58418 100644 --- a/ecoscope/plotting/plot.py +++ b/ecoscope/plotting/plot.py @@ -1,7 +1,3 @@ -import logging -import os -import uuid - import numpy as np import pandas as pd import plotly.graph_objs as go @@ -9,10 +5,6 @@ from plotly.subplots import make_subplots from sklearn.neighbors import KernelDensity -from ecoscope.io.utils import extract_voltage - -logger = logging.getLogger(__name__) - class EcoPlotData: def __init__(self, grouped, x_col="x", y_col="y", groupby_style=None, **style): @@ -158,42 +150,6 @@ def add_seasons(fig, season_df): return fig -def collar_event_timeline(relocations, collar_events): - fig = go.FigureWidget() - - ys = [0] - if not collar_events.empty: - times = collar_events["time"].to_list() - times.append(relocations["fixtime"][-1]) - xs = [[times[i]] * 3 + [times[i + 1]] for i in range(len(collar_events))] - ys = [[0, i + 1, 0, 0] for i in range(len(collar_events))] - colors = collar_events["colors"] - - for x, y, color in zip(xs, ys, colors): - fig.add_trace(go.Scatter(x=x, y=y, line_color=color)) - fig.update_layout( - annotations=[ - go.layout.Annotation(x=row.time, y=i, text=f"{row.event_type}
{row.time.date()}") - for i, (_, row) in enumerate(collar_events.iterrows(), 1) - ] - ) - - x = relocations.fixtime - y = np.full(len(x), np.max(ys) / 10) - fig.add_trace(go.Scatter(x=x, y=y, line_color="rgb(0,0,255)", mode="markers", marker_size=1)) - - fig.update_layout( - margin_l=0, - margin_r=0, - margin_t=0, - margin_b=15, - yaxis_visible=False, - showlegend=False, - ) - - return fig - - def mcp(relocations): relocations = relocations.to_crs(relocations.estimate_utm_crs()) diff --git a/notebooks/01. IO/EarthRanger_IO.ipynb b/notebooks/01. IO/EarthRanger_IO.ipynb index 349e9ade..9eccafdd 100644 --- a/notebooks/01. IO/EarthRanger_IO.ipynb +++ b/notebooks/01. IO/EarthRanger_IO.ipynb @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "tags": [] }, @@ -644,9 +644,7 @@ "metadata": {}, "outputs": [], "source": [ - "spatial_feature = er_io.get_spatial_feature(\n", - " spatial_feature_id=\"8868718f-0154-45bf-a74d-a66706ef958f\"\n", - " )\n", + "spatial_feature = er_io.get_spatial_feature(spatial_feature_id=\"8868718f-0154-45bf-a74d-a66706ef958f\")\n", "spatial_feature" ] }, @@ -663,9 +661,7 @@ "metadata": {}, "outputs": [], "source": [ - "spatial_features = er_io.get_spatial_features_group(\n", - " spatial_features_group_id=\"15698426-7e0f-41df-9bc3-495d87e2e097\"\n", - " )\n", + "spatial_features = er_io.get_spatial_features_group(spatial_features_group_id=\"15698426-7e0f-41df-9bc3-495d87e2e097\")\n", "spatial_features" ] }, diff --git a/notebooks/06. Data Management/Collar Voltage.ipynb b/notebooks/06. Data Management/Collar Voltage.ipynb deleted file mode 100644 index 5a162a9f..00000000 --- a/notebooks/06. Data Management/Collar Voltage.ipynb +++ /dev/null @@ -1,204 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Collar Voltage" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## Setup" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Ecoscope" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "!pip install ecoscope &> /dev/null" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "import getpass\n", - "import os\n", - "import sys\n", - "\n", - "import pandas as pd\n", - "\n", - "import ecoscope\n", - "\n", - "ecoscope.init()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Google Drive Setup" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "output_dir = \"Ecoscope-Outputs\"\n", - "\n", - "if \"google.colab\" in sys.modules:\n", - " from google.colab import drive\n", - "\n", - " drive.mount(\"/content/drive/\", force_remount=True)\n", - " output_dir = os.path.join(\"/content/drive/MyDrive/\", output_dir)\n", - "\n", - "os.makedirs(output_dir, exist_ok=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Connect EarthRanger" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "ER_SERVER = os.getenv(\"ER_SERVER\", \"https://mep-dev.pamdas.org\")\n", - "ER_USERNAME = os.getenv(\"ER_USERNAME\", \"username\") # replace with your username\n", - "\n", - "ER_PASSWORD = os.getenv(\"ER_PASSWORD\", \"\")\n", - "\n", - "if not ER_PASSWORD:\n", - " ER_PASSWORD = getpass.getpass(\"Please enter your ER password: \")\n", - "\n", - "er_io = ecoscope.io.EarthRangerIO(\n", - " server=ER_SERVER,\n", - " username=ER_USERNAME,\n", - " password=ER_PASSWORD,\n", - " tcp_limit=5,\n", - " sub_page_size=4000,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## Download Observations with Details" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "observations = er_io.get_subjectgroup_observations(\n", - " group_name=\"Elephants_Shimba\",\n", - " include_subject_details=True,\n", - " include_subjectsource_details=True,\n", - " include_details=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "observations.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## Plot Collar Voltage" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "start_time = pd.Timestamp(\"2022-06-02\").isoformat()\n", - "start_time" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "ecoscope.plotting.plot_collar_voltage(observations, start_time=start_time)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.10" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}