Skip to content

Commit

Permalink
filter by countries
Browse files Browse the repository at this point in the history
  • Loading branch information
dfguerrerom committed Nov 4, 2024
1 parent 3bef560 commit 79f1fa9
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 15 deletions.
201 changes: 190 additions & 11 deletions Sepal_Global_SDG_15_4_2_Sub_A_Default_values.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -34,9 +34,173 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<style>/*******************************************************************************\n",
" * Customization of the provided css from the different libs used by sepal_ui\n",
" */\n",
"\n",
"/* replace the map panel elements on top */\n",
".leaflet-pane,\n",
".leaflet-top,\n",
".leaflet-bottom {\n",
" z-index: 2 !important;\n",
"}\n",
"\n",
"/* remove the shadow from the widgets on the maps */\n",
".leaflet-widgetcontrol {\n",
" box-shadow: none;\n",
"}\n",
"\n",
"/* remove extra padding on top of the content */\n",
"main.v-content {\n",
" padding-top: 0px !important;\n",
"}\n",
"\n",
".v-alert__wrapper .progress {\n",
" background-color: transparent;\n",
"}\n",
"\n",
"/* set the bar on top of the map (800) when set to fullscreen */\n",
"header.v-app-bar {\n",
" z-index: 800 !important;\n",
"}\n",
"\n",
"/* set the menu_content on top of the map when it's set to fullscreen */\n",
".v-menu__content {\n",
" max-width: 100% !important;\n",
" z-index: 801 !important;\n",
"}\n",
"\n",
"/* make sure navigation drawers are always visible when they exist */\n",
"nav.v-navigation-drawer {\n",
" z-index: 900 !important;\n",
"}\n",
"\n",
"/* create extra position for the leaflet map controls */\n",
".leaflet-center {\n",
" left: 50%;\n",
" transform: translate(-50%, 0%);\n",
"}\n",
"\n",
".leaflet-middle {\n",
" top: 50%;\n",
" position: absolute;\n",
" z-index: 1000;\n",
" pointer-events: none;\n",
" transform: translate(0%, -50%);\n",
"}\n",
"\n",
".leaflet-center.leaflet-middle {\n",
" transform: translate(-50%, -50%);\n",
"}\n",
"\n",
"/* create extra classes to customize the layer_control table */\n",
".v-no-hover:hover {\n",
" background-color: transparent !important;\n",
"}\n",
"\n",
".v-no-border tbody tr td,\n",
".v-no-border tbody tr th {\n",
" border: none !important;\n",
"}\n",
"\n",
"/* extra css rules to make the messages disappear beneath the SimpleSlider */\n",
".v-no-messages .v-messages {\n",
" display: none;\n",
"}\n",
"\n",
".v-no-messages .v-input__slot {\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
"/* specific css for the btn placed on maps */\n",
".v-btn.v-size--default.v-map-btn:not(.v-btn--round) {\n",
" padding: 0px;\n",
" min-width: 0px;\n",
" width: 30px;\n",
" height: 30px;\n",
"}\n",
"\n",
"/* add specific css for the zoom btn of the map */\n",
".v-btn.v-zoom-plus {\n",
" border-bottom-left-radius: 0;\n",
" border-bottom-right-radius: 0;\n",
"}\n",
"\n",
".v-btn.v-zoom-minus {\n",
" margin-top: -1px;\n",
" border-top-left-radius: 0;\n",
" border-top-right-radius: 0;\n",
"}\n",
"\n",
"/* css rules for fullscreen menus */\n",
".v-card.v-menu-fullscreen {\n",
" width: calc(100vw - 80px);\n",
" height: calc(100vh - 20px);\n",
"}\n",
"\n",
"/* hide the disclaimer message placed on top of the ui notebook\n",
" * the message will be displayed until the css is loaded */\n",
"#loading-app {\n",
" display: none !important;\n",
"}\n",
"\n",
"/* Related with https://github.com/12rambau/sepal_ui/issues/893 */\n",
"#rendered_cells,\n",
"#main {\n",
" contain: revert !important;\n",
" background-color: revert !important;\n",
"}\n",
"\n",
"#jp-main-content-panel {\n",
" contain: revert !important;\n",
"}\n",
"\n",
".full-screen-map > .leaflet-container {\n",
" position: fixed !important;\n",
" width: 100vw;\n",
" height: calc(100vh - 48px);\n",
" z-index: 800;\n",
" bottom: 0;\n",
" left: 0;\n",
"}\n",
"</style>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\"/>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": "/*******************************************************************************\n * remove any links from fontawesome 5 created by jupyter in favor of\n * fontawesome 6. to be removed when Jupyter updates it\n */\n\nfunction remove_fa5() {\n let links = document.querySelectorAll(\n \"link[href^='https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@^5']\"\n );\n\n links.forEach((link) => link.remove());\n}\n\nif (document.readyState != \"loading\") remove_fa5();\nelse document.addEventListener(\"DOMContentLoaded\", remove_fa5);\n",
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import os\n",
"from datetime import datetime\n",
Expand All @@ -61,7 +225,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -77,7 +241,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"id": "t9C1qT5bGoqt"
},
Expand Down Expand Up @@ -110,7 +274,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -121,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"id": "mSvTM29TnndR"
},
Expand All @@ -143,7 +307,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -165,11 +329,25 @@
"metadata": {
"id": "BiuBEJwPue2v"
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Length of admin boundaries to process 1\n",
"Length of distinct admin boundaries to process 1\n"
]
}
],
"source": [
"# admin boundary feature collection\n",
"admin_boundaries = ee.FeatureCollection(admin_asset_id)\n",
"\n",
"# Uncomment to process all countries\n",
"# codes_to_process = [840]\n",
"# admin_boundaries = admin_boundaries.filter(ee.Filter.inList(\"M49Code\", codes_to_process))\n",
"\n",
"\n",
"# list to process\n",
"list_of_countries = admin_boundaries.aggregate_array(admin_asset_property_name).getInfo()\n",
"\n",
Expand Down Expand Up @@ -224,7 +402,8 @@
" rsa=False,\n",
" dem=DEM_DEFAULT, #default digital elevation model (DEM). Relevant for the real surface area (RSA) implementation.\n",
" lc_years= year,\n",
" transition_matrix=False\n",
" transition_matrix=False,\n",
" scale=None # None means native resolution\n",
" )\n",
" ).set(\"process_id\", year[0][\"year\"])\n",
" for year in get_a_years(a_years) # creates GEE images and runs stats on each. Images to run are in the 'a_years\" dictionary (above)\n",
Expand Down
7 changes: 6 additions & 1 deletion Sepal_Global_SDG_15_4_2_Sub_B_Default_values.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
"# admin boundary feature collection\n",
"admin_boundaries = ee.FeatureCollection(admin_asset_id)\n",
"\n",
"# # Uncomment to process all countries\n",
"# codes_to_process = [840]\n",
"# admin_boundaries = admin_boundaries.filter(ee.Filter.inList(\"M49Code\", codes_to_process))\n",
"\n",
"# list to process\n",
"list_of_countries = admin_boundaries.aggregate_array(admin_asset_property_name).getInfo()\n",
"\n",
Expand Down Expand Up @@ -284,6 +288,7 @@
" dem=DEM_DEFAULT,\n",
" lc_years= year,\n",
" transition_matrix=default_transition_matrix_path\n",
" scale=None \n",
" )\n",
" ).set(\"process_id\", \"_\".join([str(y[\"year\"]) for y in year]))\n",
" for year in years \n",
Expand Down Expand Up @@ -438,7 +443,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
"version": "3.10.0"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions component/scripts/gee.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def reduce_regions(
dem: str,
lc_years: List[Tuple[Dict]],
transition_matrix: str,
scale: int = None,
scale: Optional[int] = None,
) -> ee.Dictionary:
"""Reduce land use/land cover image to bioclimatic belts regions using planimetric
or real surface area
Expand Down Expand Up @@ -131,11 +131,11 @@ def reduce_regions(
# When using rsa, we need to use the dem scale, otherwise
# we will end with wrong results.
image_area = get_real_surface_area(dem, aoi)
scale = ee_lc_start.projection().nominalScale().getInfo()
scale = scale or ee_lc_start.projection().nominalScale().getInfo()
else:
# Otherwise, we will use the coarse scale to the output.
image_area = ee.Image.pixelArea()
scale = (
scale = scale or (
ee_lc_start.projection()
.nominalScale()
.max(ee_lc_start.projection().nominalScale())
Expand Down

0 comments on commit 79f1fa9

Please sign in to comment.