From 99c7d8511864e1cdffbdfb8a4e7158a856d13841 Mon Sep 17 00:00:00 2001 From: Ian Bolliger Date: Mon, 11 Apr 2022 18:25:58 +0000 Subject: [PATCH 1/2] add lat lon to sliiders-econ --- .../create-SLIIDERS-ECON.ipynb | 632 ++++++++++++++++-- .../download-sliiders-econ-input-data.ipynb | 35 +- sliiders/spatial.py | 7 +- 3 files changed, 586 insertions(+), 88 deletions(-) diff --git a/notebooks/create-SLIIDERS-ECON/create-SLIIDERS-ECON.ipynb b/notebooks/create-SLIIDERS-ECON/create-SLIIDERS-ECON.ipynb index 0aeb3b9..a2af991 100644 --- a/notebooks/create-SLIIDERS-ECON/create-SLIIDERS-ECON.ipynb +++ b/notebooks/create-SLIIDERS-ECON/create-SLIIDERS-ECON.ipynb @@ -35,9 +35,18 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/srv/conda/envs/notebook/lib/python3.9/site-packages/dask_gateway/client.py:21: FutureWarning: format_bytes is deprecated and will be removed in a future release. Please use dask.utils.format_bytes instead.\n", + " from distributed.utils import LoopRunner, format_bytes\n" + ] + } + ], "source": [ "from collections import OrderedDict\n", "\n", @@ -49,12 +58,12 @@ "from gcsfs import GCSFileSystem\n", "from scipy.stats import gumbel_r\n", "\n", + "from sliiders.dask import upload_pkg\n", "from sliiders.settings import (\n", " EXPOSURE_BIN_WIDTH_V,\n", " PATH_CIAM_2016,\n", " PATH_CIAM_ADM1_VORONOI_INTERSECTIONS,\n", " PATH_CIAM_COASTLINES,\n", - " PATH_SEG_CENTROIDS,\n", " PATH_COUNTRY_LEVEL_EXPOSURE,\n", " PATH_COUNTRY_LEVEL_EXPOSURE_PROJ,\n", " PATH_EXPOSURE_AREA_BY_CIAM_AND_ELEVATION,\n", @@ -64,12 +73,28 @@ " PATH_GADM,\n", " PATH_GTSM_SURGE,\n", " PATH_PWT_RAW,\n", + " PATH_SEG_CENTROIDS,\n", " PATH_SLIIDERS_ECON,\n", " PATH_SLIIDERS_SLR,\n", " SVALS,\n", ")\n", - "from sliiders.spatial import coastlen_poly, get_great_circle_nearest_index\n", - "from sliiders.utils import upload_pkg" + "from sliiders.spatial import coastlen_poly, get_great_circle_nearest_index" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "\n", + "PATH_COUNTRY_LEVEL_EXPOSURE_PROJ = Path(\n", + " \"/gcs/rhg-data/impactlab-rhg/coastal/sliiders/int/exposure/ypk/archive/old_version/gdp_gdppc_pop_capital_proj_2010_2100.parquet\"\n", + ")\n", + "PATH_COUNTRY_LEVEL_EXPOSURE = Path(\n", + " \"/gcs/rhg-data/impactlab-rhg/coastal/sliiders/int/exposure/ypk/archive/old_version/gdp_gdppc_pop_capital_1950_2020.parquet\"\n", + ")" ] }, { @@ -88,13 +113,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "ce1123bfbc4b4d78994359ec6424e8b4", + "model_id": "3065940ee08a4549b19bfe60151cb6e9", "version_major": 2, "version_minor": 0 }, @@ -128,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -154,11 +179,7 @@ " PATH_EXPOSURE_BINNED_WITHELEV,\n", " ),\n", " )\n", - ")\n", - "\n", - "PATH_SLIIDERS_SLR = FS.get_mapper(PATH_SLIIDERS_SLR.relative_to(\"/gcs\"))\n", - "PATH_SLIIDERS_ECON = FS.get_mapper(PATH_SLIIDERS_ECON.relative_to(\"/gcs\"))\n", - "PATH_CIAM_2016 = FS.get_mapper(PATH_CIAM_2016.relative_to(\"/gcs\"))" + ")" ] }, { @@ -222,8 +243,8 @@ "coastlen_ftrs = client.map(\n", " coastlen_poly,\n", " segadm_df.seg_adm.values,\n", - " PATH_CIAM_COASTLINES,\n", - " PATH_CIAM_ADM1_VORONOI_INTERSECTIONS,\n", + " coastlines_shp_path=PATH_CIAM_COASTLINES,\n", + " seg_adm_voronoi_parquet_path=PATH_CIAM_ADM1_VORONOI_INTERSECTIONS,\n", " filesystem=FS,\n", ")" ] @@ -514,7 +535,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -551,7 +572,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -577,7 +598,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "metadata": { "tags": [] }, @@ -606,7 +627,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -677,7 +698,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -698,7 +719,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -720,7 +741,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": { "tags": [] }, @@ -741,7 +762,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -771,7 +792,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -811,7 +832,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -844,7 +865,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -871,7 +892,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -887,7 +908,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "metadata": { "tags": [] }, @@ -930,7 +951,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -985,7 +1006,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -1009,7 +1030,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -1028,7 +1049,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -1042,6 +1063,29 @@ "out = out.sel(seg_adm=any_exp)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add segment centroid lat/lon" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "out = xr.merge(\n", + " (\n", + " out,\n", + " segpts.rename(columns={\"lat\": \"seg_lat\", \"lon\": \"seg_lon\"})\n", + " .to_xarray()\n", + " .sel(seg=out.seg, drop=True),\n", + " )\n", + ")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -1470,7 +1514,7 @@ " * iam (iam) object 'IIASA' 'OECD'\n", " * elev (elev) float64 0.05 0.15 0.25 0.35 ... 19.75 19.85 19.95\n", " * bound (bound) object 'lower' 'upper'\n", - "Data variables: (12/17)\n", + "Data variables: (12/19)\n", " elev_bounds (elev, bound) float32 dask.array<chunksize=(200, 2), meta=np.ndarray>\n", " SLR_site_id (seg_adm) object dask.array<chunksize=(500,), meta=np.ndarray>\n", " length (seg_adm) float32 dask.array<chunksize=(500,), meta=np.ndarray>\n", @@ -1478,12 +1522,12 @@ " mobcapfrac (country) float32 dask.array<chunksize=(204,), meta=np.ndarray>\n", " gumbel_params (seg_adm, params) float32 dask.array<chunksize=(500, 2), meta=np.ndarray>\n", " ... ...\n", - " pop_scale (ssp, iam, year, country) float32 dask.array<chunksize=(5, 2, 101, 204), meta=np.ndarray>\n", - " ypcc (ssp, iam, year, country) float32 dask.array<chunksize=(5, 2, 101, 204), meta=np.ndarray>\n", " landarea (seg_adm, elev) float32 dask.array<chunksize=(500, 200), meta=np.ndarray>\n", " interior (ssp, iam, year, country) float32 dask.array<chunksize=(5, 2, 101, 204), meta=np.ndarray>\n", " wetland (seg_adm, elev) float32 dask.array<chunksize=(500, 200), meta=np.ndarray>\n", - " wetlandservice (ssp, iam, year, country) float32 dask.array<chunksize=(5, 2, 101, 204), meta=np.ndarray>