Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notebook precommit #378

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ repos:
hooks:
# Run the linter and absolufy-imports.
- id: ruff
args: [--fix]
args: [--fix, --extend-select, E501, --line-length, "120"]
# Run the formatter.
- id: ruff-format
args: [--line-length, "120"]
- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
hooks:
Expand All @@ -21,13 +22,4 @@ repos:
- id: codespell
files: ^.*\.(py|md|rst|ipynb)$
args: ["-w"]
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.3.1
hooks:
- id: nbqa-black
args: ['--line-length=120']
- id: nbqa-flake8
args: ['--ignore=E203,E402,W503', '--max-line-length=120']
#- id: nbqa-isort
#args: ['-m3', '--tc']
exclude: ^ecoscope/contrib/
3 changes: 2 additions & 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,8 @@
},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down
3 changes: 2 additions & 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,8 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down
10 changes: 8 additions & 2 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,8 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -155,7 +156,12 @@
"metadata": {},
"outputs": [],
"source": [
"types = [\"Road_Primary_Murram\", \"Road_Primary_Dirt/Sand\", \"Road_Secondary_Dirt/Sand\", \"Road_Secondary_Murram\"]\n",
"types = [\n",
" \"Road_Primary_Murram\",\n",
" \"Road_Primary_Dirt/Sand\",\n",
" \"Road_Secondary_Dirt/Sand\",\n",
" \"Road_Secondary_Murram\",\n",
"]\n",
"\n",
"roads_gdf = polylines_gdf[polylines_gdf[\"type\"].isin(types)].copy()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -142,7 +143,11 @@
"metadata": {},
"outputs": [],
"source": [
"gdf = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(x=data[\"location-long\"], y=data[\"location-lat\"]), crs=4326)"
"gdf = gpd.GeoDataFrame(\n",
" data,\n",
" geometry=gpd.points_from_xy(x=data[\"location-long\"], y=data[\"location-lat\"]),\n",
" crs=4326,\n",
")"
]
},
{
Expand Down Expand Up @@ -444,7 +449,12 @@
"metadata": {},
"outputs": [],
"source": [
"relocs.to_csv(os.path.join(output_dir, \"relocs_clean.csv.zip\"), header=True, index=True, compression=\"zip\")"
"relocs.to_csv(\n",
" os.path.join(output_dir, \"relocs_clean.csv.zip\"),\n",
" header=True,\n",
" index=True,\n",
" compression=\"zip\",\n",
")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -526,7 +527,10 @@
"# Wrong individual name\n",
"try:\n",
" ecograph.to_geotiff(\n",
" \"collective_influence\", os.path.join(output_dir, \"salif_ci_int.tif\"), individual=\"ofjoodjo\", interpolation=\"max\"\n",
" \"collective_influence\",\n",
" os.path.join(output_dir, \"salif_ci_int.tif\"),\n",
" individual=\"ofjoodjo\",\n",
" interpolation=\"max\",\n",
" )\n",
"except ValueError as e:\n",
" print(e)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -299,7 +300,9 @@
"outputs": [],
"source": [
"salif = get_percentile_area(\n",
" percentile_levels=[50, 60, 70, 80, 90, 99.9], raster_path=etd.at[\"Salif Keita\"], subject_id=\"Salif Keita\"\n",
" percentile_levels=[50, 60, 70, 80, 90, 99.9],\n",
" raster_path=etd.at[\"Salif Keita\"],\n",
" subject_id=\"Salif Keita\",\n",
")"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down
61 changes: 50 additions & 11 deletions doc/source/notebooks/04. EcoMap & EcoPlot/EcoMap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -210,7 +211,11 @@
")\n",
"\n",
"df = pd.read_csv(os.path.join(output_dir, \"movebank_data.csv\"), index_col=0)\n",
"gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(x=df[\"location-long\"], y=df[\"location-lat\"]), crs=4326)\n",
"gdf = gpd.GeoDataFrame(\n",
" df,\n",
" geometry=gpd.points_from_xy(x=df[\"location-long\"], y=df[\"location-lat\"]),\n",
" crs=4326,\n",
")\n",
"movebank_relocations_gdf = ecoscope.base.Relocations.from_gdf(\n",
" gdf, groupby_col=\"individual-local-identifier\", time_col=\"timestamp\"\n",
")\n",
Expand Down Expand Up @@ -276,13 +281,23 @@
"m.add_layer(EcoMap.get_named_tile_layer(\"OpenStreetMap\"))\n",
"\n",
"# Set DEM visualization parameters\n",
"vis_params = {\"min\": 0, \"max\": 4000, \"opacity\": 0.5, \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"]}\n",
"vis_params = {\n",
" \"min\": 0,\n",
" \"max\": 4000,\n",
" \"opacity\": 0.5,\n",
" \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
"}\n",
"\n",
"# Add Google Earth Engine elevation layer\n",
"dem = ee.Image(\"USGS/SRTMGL1_003\")\n",
"m.add_layer(m.ee_layer(dem.updateMask(dem.gt(0)), vis_params))\n",
"\n",
"apply_color_map(region_gdf, \"ZoneID\", [\"#7fc97f\", \"#beaed4\", \"#fdc086\", \"#ffff99\"], output_column_name=\"zone_colors\")\n",
"apply_color_map(\n",
" region_gdf,\n",
" \"ZoneID\",\n",
" [\"#7fc97f\", \"#beaed4\", \"#fdc086\", \"#ffff99\"],\n",
" output_column_name=\"zone_colors\",\n",
")\n",
"m.add_layer(m.polygon_layer(region_gdf, opacity=0.5, fill_color_column=\"zone_colors\"), zoom=True)\n",
"\n",
"# Add trajectory\n",
Expand Down Expand Up @@ -324,7 +339,10 @@
"\n",
"m = EcoMap(width=800, height=600)\n",
"m.add_layer(EcoMap.get_named_tile_layer(\"OpenStreetMap\"))\n",
"m.add_layer(m.geotiff_layer(tiff=os.path.join(output_dir, \"mara_dem.tif\"), cmap=\"jet\"), zoom=True)\n",
"m.add_layer(\n",
" m.geotiff_layer(tiff=os.path.join(output_dir, \"mara_dem.tif\"), cmap=\"jet\"),\n",
" zoom=True,\n",
")\n",
"m"
]
},
Expand Down Expand Up @@ -357,8 +375,16 @@
"m.add_layer(EcoMap.get_named_tile_layer(\"OpenStreetMap\"))\n",
"\n",
"# Add day_night\n",
"apply_color_map(movebank_relocations_gdf, \"is_night\", [\"#292965\", \"#e7a553\"], output_column_name=\"colors\")\n",
"m.add_layer(m.point_layer(movebank_relocations_gdf, get_radius=700, fill_color_column=\"colors\"), zoom=True)\n",
"apply_color_map(\n",
" movebank_relocations_gdf,\n",
" \"is_night\",\n",
" [\"#292965\", \"#e7a553\"],\n",
" output_column_name=\"colors\",\n",
")\n",
"m.add_layer(\n",
" m.point_layer(movebank_relocations_gdf, get_radius=700, fill_color_column=\"colors\"),\n",
" zoom=True,\n",
")\n",
"\n",
"m.add_legend(title=\"Is Night\", labels=[\"True\", \"False\"], colors=[\"#292965\", \"#e7a553\"])\n",
"m.add_north_arrow(placement=\"top-left\")\n",
Expand Down Expand Up @@ -403,8 +429,16 @@
"m.add_layer(EcoMap.get_named_tile_layer(\"OpenStreetMap\"))\n",
"\n",
"# Add day_night\n",
"apply_color_map(movebank_trajectory_gdf, \"extra__is_night\", [\"#292965\", \"#e7a553\"], output_column_name=\"colors\")\n",
"m.add_layer(m.polyline_layer(movebank_trajectory_gdf, get_width=200, color_column=\"colors\"), zoom=True)\n",
"apply_color_map(\n",
" movebank_trajectory_gdf,\n",
" \"extra__is_night\",\n",
" [\"#292965\", \"#e7a553\"],\n",
" output_column_name=\"colors\",\n",
")\n",
"m.add_layer(\n",
" m.polyline_layer(movebank_trajectory_gdf, get_width=200, color_column=\"colors\"),\n",
" zoom=True,\n",
")\n",
"\n",
"m.add_legend(title=\"Is Night\", labels=[\"True\", \"False\"], colors=[\"#292965\", \"#e7a553\"])\n",
"m.add_north_arrow(placement=\"top-left\")\n",
Expand Down Expand Up @@ -463,15 +497,20 @@
"outputs": [],
"source": [
"percentile_areas = get_percentile_area(\n",
" percentile_levels=[50, 60, 70, 80, 90, 99.9], raster_path=etd.at[\"Salif Keita\"], subject_id=\"Salif Keita\"\n",
" percentile_levels=[50, 60, 70, 80, 90, 99.9],\n",
" raster_path=etd.at[\"Salif Keita\"],\n",
" subject_id=\"Salif Keita\",\n",
").to_crs(4326)\n",
"\n",
"m = EcoMap(width=800, height=600, static=True)\n",
"m.add_layer(EcoMap.get_named_tile_layer(\"OpenStreetMap\"))\n",
"\n",
"apply_color_map(percentile_areas, \"percentile\", \"RdYlGn\")\n",
"\n",
"m.add_layer(m.polygon_layer(percentile_areas, fill_color_column=\"percentile_colormap\"), zoom=True)\n",
"m.add_layer(\n",
" m.polygon_layer(percentile_areas, fill_color_column=\"percentile_colormap\"),\n",
" zoom=True,\n",
")\n",
"\n",
"m.add_north_arrow(placement=\"top-left\")\n",
"m.add_title(\"Salif ETD Range\")\n",
Expand Down
9 changes: 7 additions & 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,8 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -134,7 +135,11 @@
"epdata2 = plotting.EcoPlotData(grouped2, \"segment_start\", \"speed_kmhr\", line=dict(color=\"blue\"))\n",
"epdata3 = plotting.EcoPlotData(grouped2, \"segment_start\", \"timespan_seconds\", line=dict(color=\"red\"))\n",
"\n",
"plotting.ecoplot([epdata1, epdata2, epdata3], \"My Plot\", os.path.join(output_dir, \"ecoplot_example.png\"))"
"plotting.ecoplot(\n",
" [epdata1, epdata2, epdata3],\n",
" \"My Plot\",\n",
" os.path.join(output_dir, \"ecoplot_example.png\"),\n",
")"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -183,7 +184,11 @@
"metadata": {},
"outputs": [],
"source": [
"new_grid_5_km.to_file(os.path.join(output_dir, \"out_landscape_grid.gpkg\"), layer=\"new_grid_5_km\", driver=\"GPKG\")"
"new_grid_5_km.to_file(\n",
" os.path.join(output_dir, \"out_landscape_grid.gpkg\"),\n",
" layer=\"new_grid_5_km\",\n",
" driver=\"GPKG\",\n",
")"
]
},
{
Expand Down Expand Up @@ -228,7 +233,9 @@
"outputs": [],
"source": [
"new_grid_1_km_aligned.to_file(\n",
" os.path.join(output_dir, \"out_landscape_grid.gpkg\"), layer=\"new_grid_1_km_aligned\", driver=\"GPKG\"\n",
" os.path.join(output_dir, \"out_landscape_grid.gpkg\"),\n",
" layer=\"new_grid_1_km_aligned\",\n",
" driver=\"GPKG\",\n",
")"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down Expand Up @@ -207,7 +208,11 @@
"metadata": {},
"outputs": [],
"source": [
"windows.to_csv(os.path.join(output_dir, \"season_time_windows.csv\"), date_format=\"%Y-%m-%d %H:%M:%S\", index=True)"
"windows.to_csv(\n",
" os.path.join(output_dir, \"season_time_windows.csv\"),\n",
" date_format=\"%Y-%m-%d %H:%M:%S\",\n",
" index=True,\n",
")"
]
},
{
Expand Down Expand Up @@ -246,7 +251,9 @@
"source": [
"# Plot the NDVI Distribution and Seasonal Transition\n",
"fig = plotting.plot.plot_seasonal_dist(\n",
" ndvi_vals[\"NDVI\"], cuts, output_file=os.path.join(output_dir, \"seasonal_transition.png\")\n",
" ndvi_vals[\"NDVI\"],\n",
" cuts,\n",
" output_file=os.path.join(output_dir, \"seasonal_transition.png\"),\n",
")\n",
"fig.show()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"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]' &> /dev/null"
"%pip install \\\n",
" 'ecoscope[analysis,mapping,plotting] @ git+https://github.com/wildlife-dynamics/[email protected]' &> /dev/null"
]
},
{
Expand Down
Loading
Loading