Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 28, 2024
1 parent 8734791 commit 34b4055
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ dmypy.json
_build/
docs/api/
src/GOSTurban/_version.py
docs/notebooks/
docs/notebooks/
23 changes: 14 additions & 9 deletions notebooks/Tutorials/LEI_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import importlib\n",
"import rasterio\n",
"import rasterio.features\n",
"\n",
"import geopandas as gpd\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"import GOSTrocks.rasterMisc as rMisc\n",
"import GOSTrocks.ghslMisc as ghslMisc\n",
Expand Down Expand Up @@ -69,18 +66,22 @@
" temp_folder = \"C:/Temp\"\n",
" # clip from global GHSL file\n",
" ghsl_folder = \"J:/Data/GLOBAL/GHSL/built\"\n",
" ghsl_files = [os.path.join(ghsl_folder, x) for x in os.listdir(ghsl_folder) if x.endswith(\".tif\")] \n",
" ghsl_files = [\n",
" os.path.join(ghsl_folder, x)\n",
" for x in os.listdir(ghsl_folder)\n",
" if x.endswith(\".tif\")\n",
" ]\n",
" inA = gpd.read_file(aoi_file)\n",
" \n",
"\n",
" temp_ghsl_files = []\n",
" for ghsl_file in ghsl_files:\n",
" temp_file = os.path.join(temp_folder, os.path.basename(ghsl_file))\n",
" temp_ghsl_files.append(temp_file)\n",
" if not os.path.exists(temp_file):\n",
" rMisc.clipRaster(rasterio.open(ghsl_file), inA, temp_file)\n",
" \n",
"\n",
" ghsl_res, ghsl_profile = ghslMisc.combine_ghsl_annual(temp_ghsl_files)\n",
" with rasterio.open(input_ghsl, 'w', **ghsl_profile) as outR:\n",
" with rasterio.open(input_ghsl, \"w\", **ghsl_profile) as outR:\n",
" outR.write_band(1, ghsl_res)"
]
},
Expand Down Expand Up @@ -183,7 +184,9 @@
],
"source": [
"# This calculates the change from 1990 and 2000\n",
"lei_raw = lei.calculate_LEI(input_ghsl, old_list=list(range(1975,1991,5)), new_list=list(range(1995,2001,5)))\n",
"lei_raw = lei.calculate_LEI(\n",
" input_ghsl, old_list=list(range(1975, 1991, 5)), new_list=list(range(1995, 2001, 5))\n",
")\n",
"lei_90_00 = pd.DataFrame(lei_raw, columns=[\"geometry\", \"old\", \"total\"])\n",
"lei_90_00[\"LEI\"] = lei_90_00[\"old\"] / lei_90_00[\"total\"]\n",
"lei_90_00.head()"
Expand Down Expand Up @@ -302,7 +305,9 @@
],
"source": [
"# This calculates the change from 2000 and 2014\n",
"lei_raw = lei.calculate_LEI(input_ghsl, old_list=list(range(1975,2011,5)), new_list=list(range(2015,2030,5)))\n",
"lei_raw = lei.calculate_LEI(\n",
" input_ghsl, old_list=list(range(1975, 2011, 5)), new_list=list(range(2015, 2030, 5))\n",
")\n",
"lei_00_14 = pd.DataFrame(lei_raw, columns=[\"geometry\", \"old\", \"total\"])\n",
"lei_00_14[\"LEI\"] = lei_00_14[\"old\"] / lei_00_14[\"total\"]\n",
"lei_00_14.head()"
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ elevation
geojson
hatch
git


2 changes: 1 addition & 1 deletion src/GOSTurban/LEI.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ def calculate_LEI(val, leap_val, exp_val):
res["class"] = res["LEI"].apply(lambda x: calculate_LEI(x, leap_val, exp_val))
xx = res.groupby("class")

return xx['area'].sum()
return xx["area"].sum()

0 comments on commit 34b4055

Please sign in to comment.