diff --git a/DSCIM/environment.yml b/DSCIM/environment.yml index 14dbdf0..3dc2998 100644 --- a/DSCIM/environment.yml +++ b/DSCIM/environment.yml @@ -8,7 +8,7 @@ dependencies: - python==3.9 - pyfiglet==0.8.post1 - pip==22.2.2 - - xarray==2022.6.0 + - xarray==2022.3.0 - pandas==1.4.3 - numpy==1.23.3 - scipy==1.9.1 diff --git a/DSCIM/input/input_creation/run-SESL-on-FAIR-GMST.ipynb b/DSCIM/input/input_creation/run-SESL-on-FAIR-GMST.ipynb index e24fc2a..4a3cb04 100644 --- a/DSCIM/input/input_creation/run-SESL-on-FAIR-GMST.ipynb +++ b/DSCIM/input/input_creation/run-SESL-on-FAIR-GMST.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "f502664b-6e28-4308-9653-84d8dceb38af", "metadata": {}, "outputs": [], @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "3effac15-5964-497b-a509-b135b3d82ed2", "metadata": {}, "outputs": [], @@ -44,9 +44,6 @@ "\n", "import numpy as np\n", "\n", - "def fuse_to_gcsmap(path, fs=\"\"):\n", - " pass\n", - "\n", "settings_dict = dict(\n", " #############\n", " ## GENERAL\n", @@ -54,92 +51,18 @@ " # code metadata\n", " _PACKAGE_DIR=Path(\"./coastal_gmsl_inputs/other\").parent,\n", " FS = \"\",\n", - " # unit of analysis for damage regression/projection\n", - " HIST_GEOG=\"state\",\n", - " PROJ_GEOG=\"cbsa\",\n", " #############\n", " ## HAZARD\n", " #############\n", - " # tracks\n", - " GEOG=\"conus\",\n", - " HIST_TRACK_VERS=\"20210610\",\n", - " HIST_TRACK_NAME=\"ibtracs\",\n", - " IBTRACS_URL=(\n", - " \"https://www.ncei.noaa.gov/data/\"\n", - " \"international-best-track-archive-for-climate-stewardship-ibtracs/v04r00/\"\n", - " \"access/netcdf/\"\n", - " ),\n", - " # synthetic track config\n", - " SYNTH_TRACK_NAME=\"emanuel\",\n", - " SYNTH_TRACK_VERS=\"20220125\",\n", - " SYNTH_TRACK_VERS_HIGH=\"20220125_HT\",\n", - " SYNTH_REFERENCE_PERIOD=[2000, 2020],\n", - " SYNTH_REFERENCE_SCENS=[\"reanal\", \"20th\", \"ssp245\"],\n", - " EMANUEL_RADIUS_RESAMPLE_SEED_INDEX=range(3),\n", - " HAZARD_TRACKS_SYNTH_PROCESSING_VERS=\"v0.1\",\n", - " TRACKRADIUSMODEL_VERS=\"v0.1\",\n", " # projection ### TODO: UPDATE\n", - " GCM_MODELS=[\"ccsm4\", \"ipsl5\", \"hadgem5\", \"mpi5\", \"mri5\", \"miroc5\", \"gfdl5\"],\n", - " GCM_SCENARIOS=[\"rcp45\", \"rcp85\"],\n", - " GCM_PERIODS=[\"2008_2025\", \"2030_2040\", \"2045_2055\", \"2070_2080\", \"2085_2095\"],\n", - " GCM_BASE=\"2008_2025\",\n", " GCM_NRUNS=100,\n", " # reanalysis ### TODO: UPDATE\n", - " REANAL_MODELS=[\"ncep\"],\n", - " REANAL_PERIODS=[\"1979_1989\", \"2008_2018\"],\n", - " REANAL_SCENARIOS=[\"reanal\"],\n", - " REANAL_BASE=\"2008_2018\",\n", " REANAL_NRUNS=200,\n", - " # surge\n", - " HAZARD_SURGE_VERS=\"20220718\",\n", - " SURGE_MODEL_NAME=\"geoclaw\",\n", - " HEIGHT_REL_MAX_WTR_VERS=\"v0.1\",\n", - " CL_GAUGE_VERS=\"v0.3\",\n", - " # wind ### TODO: UPDATE\n", - " HAZARD_WIND_VERS=\"v0.5\",\n", - " WIND_MODEL_NAME=\"licrice\",\n", - " # SLR\n", - " SLR_SYNTH_DATA_VERS=\"20210809\",\n", - " SLR_HIST_DATA_VERS=\"REPLACE_WITH_ACTUAL_VALUE_WHEN_USING_HIST_DATA\",\n", - " SLR_SSP_INTERPOLATION_VERS=\"v0.1\",\n", - " NOAA_TIDE_HARMONICS_VERS=\"20220715\",\n", - " #############\n", - " ## ELEVATION\n", - " #############\n", - " DEM_CATALOGUE_VERS=\"20210420\",\n", - " SRTM15PLUS_VERS=\"V2.4\",\n", - " DATUM_CONVERSION_VERS=\"v0.2\",\n", - " #############\n", - " ## EXPOSURE\n", - " #############\n", - " EXPOSURE_BINNED_VERS=\"20220524\",\n", - " MAX_HEIGHT_FOR_SURGE=20, # meters\n", - " EXPOSURE_BIN_WIDTH_H=0.1,\n", - " EXPOSURE_BIN_WIDTH_V=0.1,\n", - " PROTECTED_LOCATIONS_VERS=\"v0.1\",\n", - " #############\n", - " ## DAMAGE\n", - " #############\n", - " DAMAGE_VERS=\"v0.2\",\n", - " #############\n", - " ## DOSERESPONSE\n", - " #############\n", - " DOSERESPONSE_VERS=\"experiments/br2-experiment-us\",\n", - " DOSERESPONSE_NFOLDS=5,\n", " #############\n", " # MC SAMPLING\n", " #############\n", " MC_NSAMPLES=100,\n", " SAMPLING_VERS=\"v0.2\",\n", - " #############\n", - " ## DOSE\n", - " #############\n", - " DOSE_VERS=\"v0.1\",\n", - " DOSE_MAXS_BIN_EDGES=np.arange(0, 105, 1),\n", - " #############\n", - " ## GEOGRAPHY\n", - " #############\n", - " GLOBAL_PROTECTED_AREAS_VERS=\"v2.0\",\n", ")\n", "############################################################################\n", "\n", @@ -229,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "ba096a4d-062c-4406-8f1a-2504eab92264", "metadata": {}, "outputs": [], @@ -241,27 +164,7 @@ "# place variables from the global settings file that you'd like to override in\n", "# `pytc_settings`\n", "pytc_settings = dict(\n", - " GEOG=\"global\",\n", - " REANAL_MODELS=[\"era5\", \"ncep2\"],\n", - " REANAL_PERIODS=[\"1979_2019\"],\n", - " REANAL_SCENARIOS=[\"reanal\"],\n", - " GCM_MODELS=[\n", - " \"ccsm4\",\n", - " \"ecearth\",\n", - " \"gfdl5\",\n", - " \"hadgem5\",\n", - " \"ipsl5\",\n", - " \"miroc5\",\n", - " \"mpi5\",\n", - " \"mri5\",\n", - " ],\n", - " GCM_SCENARIOS=[\"20th\", \"rcp45\", \"rcp85\"],\n", - " GCM_PERIODS=[\"1999_2005\", \"2006_2030\", \"2079_2099\"],\n", - " SYNTH_REFERENCE_PERIOD=[1999, 2019],\n", - " EMANUEL_RADIUS_RESAMPLE_SEED_INDEX=range(10),\n", " SAMPLING_VERS=\"v0.4\",\n", - " DOSE_VERS=\"v0.1\",\n", - " EXPOSURE_BINNED_VERS=\"v0.14\",\n", " MC_NSAMPLES=1000,\n", ")\n", "\n", @@ -273,94 +176,11 @@ " ##############\n", " # MISC\n", " ##############\n", - " GLOCO_PACKAGE_DIR=pathlib.Path().absolute() / \"coastal_gmsl_inputs/other/\", # \"./input/\n", - " FAIR_SCENARIOS=[\"ssp245\", \"ssp460\", \"ssp370\"],\n", - " CIL_COLORS_3=[\"#3393b0\", \"#ff8c00\", \"#ff6553\"],\n", - " CIL_COLORS_ALT_3=[\"#3393b0\", \"#ff8c00\", \"#880808\"],\n", - " COASTAL_COLORS_3=[\"#3393b0\", \"#a52a2a\", \"#696969\"],\n", - " GENERIC_COLORS_5=[\"#d7191c\", \"#fdae61\", \"black\", \"#abd9e9\", \"#2c7bb6\"],\n", - " INTEG_BOTTOM_CODING_GDPPC=234.235646874999,\n", - " INTEG_ETA=2,\n", - " ISO_DROP_NO_SOCIOECON=[\"ATA\", \"CA-\", \"SP-\"],\n", - " ISO_TERR_TO_CTRY_MAPPER={\n", - " \"ALA\": \"FIN\",\n", - " \"BES\": \"NLD\",\n", - " \"BVT\": \"NOR\",\n", - " \"IOT\": \"GBR\",\n", - " \"CXR\": \"AUS\",\n", - " \"CL-\": \"FRA\",\n", - " \"CCK\": \"AUS\",\n", - " \"ATF\": \"FRA\",\n", - " \"HMD\": \"AUS\",\n", - " \"PCN\": \"GBR\",\n", - " \"SGS\": \"GBR\",\n", - " \"SJM\": \"NOR\",\n", - " \"TKL\": \"NZL\",\n", - " \"UMI\": \"USA\",\n", - " \"KO-\": \"SRB\",\n", - " \"VAT\": \"ITA\",\n", - " },\n", + " GLOCO_PACKAGE_DIR=pathlib.Path().absolute() / \"coastal_gmsl_inputs/other/\", \n", " PPP_BASELINE_YEAR=2019,\n", " ##############\n", - " # SAMPLING\n", - " ##############\n", - " BASINS=[\"AL\", \"SI\", \"SP\", \"IO\", \"WP\", \"EP\"],\n", - " INTENSITY_THRESHOLDS=[\"low\", \"high\"],\n", - " N_BATCHES=500, # how many \"batches\" to create when binning SLR draws by GMSL\n", - " # how many batches to use in final results (subsampling from N_BATCHES)\n", - " CLIP_BATCHES=15,\n", - " ##############\n", - " # PROJECTION\n", - " ##############\n", - " PROJ_YEAR_RANGE=[2018, 2099],\n", - " ##############\n", - " # DOSE RESPONSE\n", - " ##############\n", - " DOSERESPONSE_ALPHAS=np.concatenate([[0], np.logspace(-15, -5, 11, base=10)]),\n", - " # DOSERESPONSE_ALPHAS=[0, 1e-5],\n", - " DOSERESPONSE_TWEEDIE_POWER=np.arange(1, 3.1, 0.25),\n", - " # DOSERESPONSE_TWEEDIE_POWER=[1, 1.5],\n", - " DOSERESPONSE_PARAM_GRID_ALL={\n", - " \"only_observed\": [\n", - " False,\n", - " True,\n", - " ], # whether to only include storms that were fully observed over land\n", - " \"cutoff_year\": [1950, 1980, 2001], # when to cut off regression dataset\n", - " \"covariates\": [\n", - " [],\n", - " [\"gdppc_r\"],\n", - " [\"lr_wind\"],\n", - " [\"gdppc_r\", \"lr_wind\"],\n", - " ], # which covariates to use\n", - " \"normalization\": [None, \"treated\", \"total\"],\n", - " },\n", - " DOSERESPONSE_PARAM_GRID_POLY={\n", - " \"power\": [False, True], # Power or polynomial\n", - " \"maxs\": range(15),\n", - " \"pddi\": [False, \"linear\"],\n", - " },\n", - " DOSERESPONSE_PARAM_GRID_BINNED={\"maxs\": [1, 2], \"pddi\": [False, \"linear\"]},\n", - " # DOSERESPONSE_PARAM_GRID_BINNED={\"maxs\": [1, 2], \"pddi\": [False]},\n", - " ##############\n", " # VERSIONS\n", " ##############\n", - " SYNTH_TRACK_VERS=\"20201118\",\n", - " SYNTH_TRACK_VERS_HIGH=\"20201217\",\n", - " DIVA_VERS=\"20200630\",\n", - " DIVASEGSLR_VERS=\"v0.1\",\n", - " LITPOP_DOWNLOAD_VERS=\"20200714\",\n", - " LITPOP_VERS=\"v0.5\",\n", - " EMDAT_DOWNLOAD_VERS=\"20210421\",\n", - " EMDAT_VERS=\"v0.2\",\n", - " PWT_DOWNLOAD_VERS=\"20210505\",\n", - " PWT_VERS=\"v4.0\",\n", - " ISIMIP_DOWNLOAD_VERS=\"20210505\",\n", - " IIASA_INT_VERS=\"v4.0\",\n", - " CIA_DOWNLOAD_VERS=\"20201215\",\n", - " GDP_POP_GDPPC_K_VERS=\"v0.7\",\n", - " GEG15_VERS=\"v0.1\",\n", - " CIAM_VERS=\"v6.6.0\",\n", - " IR_VERS=\"v0.1\",\n", " FAIR_RCP_VERS=\"v4.0_Jan212022\",\n", " FAIR_RFF_CO2_VERS=\"v5.03_Feb072022\",\n", " FAIR_RFF_CH4_VERS=\"v5.03_Feb072022\",\n", @@ -368,7 +188,6 @@ " FAIR_RFF_OUT_VERS=\"v5.03_Feb072022\",\n", " FAIR_RFF_CO2_MEDIAN_VERS=\"v5.01_Jan72022\",\n", " SESL_VERS=\"v0.1\",\n", - " DAMAGE_PROJ_VERS=\"v0.20\",\n", " AR6_GMSL_VERS=\"v1.0\",\n", " SLR_BINNED_VERS=\"v1.6.0\",\n", "\n", @@ -395,12 +214,10 @@ " kwargs.pop(\"DIR_PARAMS_GLOCO\", out.GLOCO_PACKAGE_DIR / \"params\")\n", " )\n", "\n", - "\n", " ################\n", " # HAZARD\n", " ################\n", "\n", - " \n", " out.DIR_LOCAL = Path('./coastal_gmsl_inputs')#Path(\"./input/\")\n", "\n", " out.PATH_HAZARD_SLR_GMSL_RAW_HIST = Path(\n", @@ -418,7 +235,7 @@ " out.DIR_HAZARD_FAIR_RFF = Path(\n", " kwargs.pop(\n", " \"DIR_HAZARD_FAIR_RFF\",\n", - " out.DIR_LOCAL ,\n", + " out.DIR_LOCAL / \"other\",\n", " )\n", " )\n", " out.PATH_HAZARD_GMST_FAIR_RCP = Path(\n", @@ -435,11 +252,21 @@ " ),\n", " )\n", " )\n", + " out.PATH_HAZARD_SLR_GMSL_FAIR_RCP = Path(\n", + " kwargs.pop(\n", + " \"PATH_HAZARD_SLR_GMSL_FAIR_RCP\",\n", + " (\n", + " out.DIR_LOCAL / out.PATH_HAZARD_GMST_FAIR_RCP.name.replace(\n", + " \"emis_conc_rf_temp_lambdaeff\", \"gmsl\"\n", + " ).replace(\".nc\", \".zarr\")\n", + " ),\n", + " )\n", + " )\n", " out.PATH_HAZARD_SLR_GMSL_FAIR_RFF = Path(\n", " kwargs.pop(\n", " \"PATH_HAZARD_SLR_GMSL_FAIR_RFF\",\n", " (\n", - " f\"/shares/gcp/integration/rff2/climate/ar6_rff_iter0-19_fair162_control_pulse_2020-2030-2040-2050-2060-2070-2080_gmsl_emissions-driven_naturalfix_{out.FAIR_RFF_OUT_VERS}.zarr\"\n", + " f\"./ar6_rff_iter0-19_fair162_control_pulse_2020-2030-2040-2050-2060-2070-2080_gmsl_emissions-driven_naturalfix_{out.FAIR_RFF_OUT_VERS}.zarr\"\n", " ),\n", " )\n", " )\n", @@ -461,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "3423efae-dce0-4090-8454-647fc2abc14a", "metadata": {}, "outputs": [], @@ -471,7 +298,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "ca44be82-e008-44f2-a48f-889007449ffc", "metadata": { "tags": [] @@ -491,7 +318,17 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, + "id": "c5b0762d-9ddb-4fd8-9364-4c6f89a05e9f", + "metadata": {}, + "outputs": [], + "source": [ + "assert xr.__version__ == \"2022.3.0\" # needed for map_blocks to work properly" + ] + }, + { + "cell_type": "code", + "execution_count": null, "id": "eff7e8fd-c96c-4a7a-9abd-856b87ab3c24", "metadata": {}, "outputs": [], @@ -535,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "44901e6d-331e-4b61-a672-ebc50691b948", "metadata": { "tags": [ @@ -592,7 +429,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "20f90c3b-7a08-43bf-9d5c-7682c045f0d1", "metadata": {}, "outputs": [], @@ -682,7 +519,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "1a5e4d4f-381e-4b00-880e-dc7a057fbd44", "metadata": {}, "outputs": [], @@ -1326,7 +1163,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "e98f7364-2ef5-493a-8d70-7602bb43e90c", "metadata": {}, "outputs": [], @@ -1395,7 +1232,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "d5512b2d-797b-4349-ac42-803b8d6d3b52", "metadata": {}, "outputs": [], @@ -1434,7 +1271,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "ca758e0f-c1d1-459d-80c7-871138d9ac8a", "metadata": {}, "outputs": [], @@ -1449,7 +1286,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "b467fc77-07c0-4700-91f7-cbe9ca13ae88", "metadata": {}, "outputs": [], @@ -1478,7 +1315,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "b91dbbb4-cdc2-49bc-902c-e56b3f8b89e5", "metadata": { "tags": [] @@ -1514,7 +1351,9 @@ "cell_type": "code", "execution_count": null, "id": "57eec42a-0b75-4ccc-a26e-70c6a046cb1f", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "sl_rcp_chunked_to_interp = (\n", @@ -1550,33 +1389,6 @@ "interpolated = sl_rcp_chunked_to_interp.tmp.values " ] }, - { - "cell_type": "code", - "execution_count": 18, - "id": "2ea990fe-3b4d-4ae4-8bb4-f3d45bebca9e", - "metadata": {}, - "outputs": [], - "source": [ - "dim = 'rcp'\n", - "src_vals = sl_rcp_chunked.chunk({\"rcp\": -1}).sel(year = 2050)\n", - "trg_vals = sl_rcp_chunked_to_interp.sel(year = 2050)\n", - "diff = trg_vals - src_vals\n", - "lb = diff.where(diff >= 0, np.inf)\n", - "no_lb = np.isinf(lb).all(dim=dim)\n", - "lb = lb.idxmin(dim).where(~no_lb, src_vals.idxmin(dim).broadcast_like(no_lb))\n", - "ub = diff.where(diff <= 0, -np.inf)\n", - "no_ub = np.isinf(ub).all(dim=dim)\n", - "ub = ub.idxmax(dim).where(~no_ub, src_vals.idxmax(dim).broadcast_like(no_ub))\n", - "assert not (no_lb & no_ub & trg_vals.notnull()).any()\n", - "lb_val = src_vals.sel({dim: lb}, drop=True)\n", - "ub_val = src_vals.sel({dim: ub}, drop=True)\n", - "\n", - "full_range = ub_val - lb_val\n", - "assert (ub_val.where(full_range == 0, 0) == lb_val.where(full_range == 0, 0)).all()\n", - "\n", - "ub_wt = ((trg_vals - lb_val) / full_range).where(full_range != 0, 1)\n" - ] - }, { "cell_type": "code", "execution_count": null, @@ -1627,7 +1439,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "7f445396-05b2-42ff-9008-29be41fa77c2", "metadata": {}, "outputs": [], @@ -1641,7 +1453,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "e2363ce7-55ce-42d9-8417-878b9d347ccf", "metadata": {}, "outputs": [], @@ -1672,7 +1484,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "420f50b3-1afb-4290-b624-d76669b83d1f", "metadata": {}, "outputs": [], @@ -1727,7 +1539,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "id": "f72a6d4f-6b0e-4665-8c18-a2fdff79d7fd", "metadata": {}, "outputs": [], @@ -1900,7 +1712,7 @@ "metadata": {}, "outputs": [], "source": [ - "out_rff = xr.concat(\n", + "out_rff_diag = xr.concat(\n", " (\n", " baseline_rff.expand_dims(pulse_year=[0]),\n", " baseline_rff\n", @@ -1913,433 +1725,7 @@ }, { "cell_type": "markdown", - "id": "c5ac5961-5d54-4542-9bb5-8bbde0cad2c4", - "metadata": {}, - "source": [ - "## Diagnostics" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "86db0020-e0e7-4b20-9e23-98357d154c76", - "metadata": {}, - "outputs": [], - "source": [ - "out_rff_diag = (\n", - " out_rff.sel(pulse_year=[0, 2020], gas=\"CO2\")\n", - " .load()\n", - " .stack(simulation=[\"rff_sp\", \"iter\"])\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6384babd-7e0d-4895-b90f-75445ab29a24", - "metadata": {}, - "outputs": [], - "source": [ - "DIAG_YEARS = [2100, 2150, 2300]\n", - "\n", - "diag = {}\n", - "for key, out, temp in [\n", - " (\"rcp\", out_rcp.gmsl, fair_temps_rcp),\n", - " (\n", - " \"rff\",\n", - " out_rff_diag,\n", - " fair_temps_rff_diag,\n", - " ),\n", - "]:\n", - " quantiles = [0.01, 0.05, 0.17, 0.5, 0.83, 0.95, 0.99]\n", - " sl_diff = out.sel(pulse_year=2020, drop=True) - out.sel(pulse_year=0, drop=True)\n", - " t_diff = temp.sel(pulse_year=2020, drop=True) - temp.sel(pulse_year=0, drop=True)\n", - " rat = sl_diff / t_diff.reindex(year=sl_diff.year)\n", - " gmsl_pulse_qs = sl_diff.sel(year=DIAG_YEARS).quantile(q=quantiles, dim=\"simulation\")\n", - " gmst_pulse_qs = t_diff.sel(year=DIAG_YEARS).quantile(q=quantiles, dim=\"simulation\")\n", - " rat_qs = rat.sel(year=DIAG_YEARS).quantile(q=quantiles, dim=\"simulation\")\n", - " gmsl_base_qs = out.sel(pulse_year=0, year=DIAG_YEARS).quantile(\n", - " q=quantiles, dim=\"simulation\"\n", - " )\n", - " diag[key] = {\n", - " \"gmsl_pulse_qs\": gmsl_pulse_qs,\n", - " \"gmst_pulse_qs\": gmst_pulse_qs,\n", - " \"rat_qs\": rat_qs,\n", - " \"gmsl_base_qs\": gmsl_base_qs,\n", - " }" - ] - }, - { - "cell_type": "markdown", - "id": "2257426b-77ea-4a58-9343-f5bc9c2f3feb", - "metadata": {}, - "source": [ - "### $\\Delta$ GMSL from Pulse (cm)" - ] - }, - { - "cell_type": "markdown", - "id": "7290009e-3315-4232-8dcd-62d97a060d30", - "metadata": {}, - "source": [ - "#### 2100" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ea08005c-9102-40f8-9846-59e9ee357b13", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmsl_pulse_qs\"].sel(year=2100).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "74db084d-84ab-4495-a14d-778c242a41c2", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmsl_pulse_qs\"].sel(year=2100).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "f5e5f118-d66d-4267-b6e7-a8ba6b5f130d", - "metadata": {}, - "source": [ - "#### 2150" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "64909200-627f-4c27-8ed6-76984742d4e7", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmsl_pulse_qs\"].sel(year=2150).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "64995a76-91d2-4e14-bb25-9dbf4164e687", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmsl_pulse_qs\"].sel(year=2150).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "28ef4517-4391-40f8-b45d-89a96418880c", - "metadata": {}, - "source": [ - "#### 2300" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5dc55911-a71a-46e5-9bea-89975d425dfd", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmsl_pulse_qs\"].sel(year=2300).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8c5c111f-29cd-4e99-8610-cfcc8a2fa70d", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmsl_pulse_qs\"].sel(year=2300).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "e92e8f6e-60ea-4abe-bcd8-59aaeebf5059", - "metadata": {}, - "source": [ - "### $\\Delta$ GMST from Pulse ($^{\\circ}C$)" - ] - }, - { - "cell_type": "markdown", - "id": "b5cd918e-44e1-48d5-8093-a6f75e7f4f84", - "metadata": {}, - "source": [ - "#### 2100" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d27778ea-b7d1-430c-8f96-7d6f8fedfccd", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmst_pulse_qs\"].sel(year=2100).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ca4f0185-8023-4351-8227-3c9019976a00", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmst_pulse_qs\"].sel(year=2100).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "291a9c67-927c-4d0d-8687-d276685ee7f5", - "metadata": {}, - "source": [ - "#### 2150" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "50120028-e3b2-4887-b912-705a32dd01d4", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmst_pulse_qs\"].sel(year=2150).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c09b25cd-d684-4ed0-a44a-a8341b562df6", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmst_pulse_qs\"].sel(year=2150).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "5a216573-e215-43d1-9a64-fb2519720a55", - "metadata": {}, - "source": [ - "#### 2300" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7eac0ce5-a6ab-4f41-bab4-84aa547a4823", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmst_pulse_qs\"].sel(year=2300).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5e733f2b-e4c9-409e-9069-b142eee7228f", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmst_pulse_qs\"].sel(year=2300).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "c830d574-91c6-474b-a6af-99ed976a1b16", - "metadata": {}, - "source": [ - "### $\\Delta$ GMSL / $\\Delta$ GMST ($\\frac{cm}{^{\\circ}C}$)" - ] - }, - { - "cell_type": "markdown", - "id": "d44c5626-e8bc-4c0c-89d1-495251355f3e", - "metadata": {}, - "source": [ - "#### 2100" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3f71abb9-ec00-4a0b-988d-ead7dfd628d3", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"rat_qs\"].sel(year=2100).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8d6e53b2-6cc6-4b0e-a6b1-0acf5a6c006d", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"rat_qs\"].sel(year=2100).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "c66d9f91-3b93-4e34-8d29-7d24eea28e14", - "metadata": {}, - "source": [ - "#### 2150" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0acd930b-d8dd-45aa-9a4a-6e6663e24297", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"rat_qs\"].sel(year=2150).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "71c982a9-08ae-4452-8ca7-121776eb3e59", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"rat_qs\"].sel(year=2150).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "6b8d8988-c1b6-46af-9345-946b1e8e43f7", - "metadata": {}, - "source": [ - "#### 2300" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3d27e435-e7de-4e68-a7fe-5c1dc76cd20e", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"rat_qs\"].sel(year=2300).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "82fd48f3-1d7a-4521-82ac-9ecf61d3b3a7", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"rat_qs\"].sel(year=2300).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "75d0f18f-0602-43e5-9402-e843b67feafd", - "metadata": {}, - "source": [ - "### Baseline GMSL, rel. 1991-2009 (cm)" - ] - }, - { - "cell_type": "markdown", - "id": "8b500f8d-5f43-4bd0-942b-df79a0b80d14", - "metadata": {}, - "source": [ - "#### 2100" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9f47216e-be39-431f-863f-bc8111923e97", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmsl_base_qs\"].sel(year=2100).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "be7ade6d-8580-4f2d-8389-8fa6189149eb", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmsl_base_qs\"].sel(year=2100).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "8670df48-a662-44e1-9bac-b36866ffe58d", - "metadata": {}, - "source": [ - "#### 2150" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "448b053e-5e52-4f77-8c36-b515aa42a523", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmsl_base_qs\"].sel(year=2150).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "086a8aa4-67e2-48ea-9280-e77d8c2a57f7", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmsl_base_qs\"].sel(year=2150).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "29bf1ad9-5f20-45bb-bf35-8e4764f8e957", - "metadata": {}, - "source": [ - "#### 2300" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "68ca18a7-701c-4a54-ac3a-3a9131ba5a8d", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rcp\"][\"gmsl_base_qs\"].sel(year=2300).to_series().unstack()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "af089cc9-9e13-4929-afb0-b6511952c541", - "metadata": {}, - "outputs": [], - "source": [ - "diag[\"rff\"][\"gmsl_base_qs\"].sel(year=2300).to_series()" - ] - }, - { - "cell_type": "markdown", - "id": "283e9a5f-d473-4c93-a021-c532929853ea", + "id": "5dc9a669-9c8b-4a3a-92d0-bccf0d8aaa3a", "metadata": {}, "source": [ "## Reshape to add back runtype dim and crop years" @@ -2352,45 +1738,28 @@ "metadata": {}, "outputs": [], "source": [ - "out_rcp = unflatten_runtype(out_rcp.sel(year=slice(None, 2300)))\n", - "out_rff = unflatten_runtype(out_rff.sel(year=slice(None, 2300))).persist()" + "out_rff = unflatten_runtype(out_rff_diag.sel(year=slice(None, 2300))).persist()\n", + "out_rcp_diag = out_rcp" ] }, { "cell_type": "code", "execution_count": null, - "id": "27ebe0b7-8742-4a09-a5df-2cb43b42b12e", + "id": "4c3112fc-af03-4eaf-9bca-93a355e7e0a6", "metadata": {}, "outputs": [], "source": [ - "out_rcp = out_rcp.chunk(\n", - " {k: v for k, v in out_rff.chunksizes.items() if k in out_rcp.dims}\n", - ").persist()\n", - "\n", - "out_rff = (\n", - " out_rff.to_dataset(name=\"gmsl\")\n", - " .rename(iter=\"simulation\")\n", - " .chunk({\"year\": 100})\n", - " .persist()\n", - ")" + "out_rff = out_rff.compute()" ] }, { "cell_type": "markdown", - "id": "da126f90-40dc-4c41-97f0-952e9a695d92", + "id": "141cc3e0-f579-41b7-a3d7-29308dba895d", "metadata": {}, "source": [ "## Add attrs and save" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "7001895d-cb4c-4e00-8025-9a0f3500087e", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": null, @@ -2398,6 +1767,9 @@ "metadata": {}, "outputs": [], "source": [ + "\n", + "out_rff = out_rff.to_dataset(name=\"gmsl\").rename({\"iter\":\"simulation\"})\n", + "\n", "REF_PERIOD = \"1991-2009\"\n", "\n", "attr_all = {\n", @@ -2409,15 +1781,6 @@ " \"contact\": CONTACT,\n", "}\n", "\n", - "out_rcp.attrs.update(\n", - " {\n", - " **attr_all,\n", - " \"description\": DESCRIPTION_RCP,\n", - " \"method\": METHOD_RCP,\n", - " \"version\": ps.FAIR_RCP_VERS,\n", - " }\n", - ")\n", - "\n", "out_rff.attrs.update(\n", " {\n", " **attr_all,\n", @@ -2427,7 +1790,7 @@ " }\n", ")\n", "\n", - "for ds in [out_rcp, out_rff]:\n", + "for ds in [out_rff,]:\n", " ds.gmsl.attrs.update(\n", " {\n", " \"description\": \"Simulations of 19-year centered mean of Global Mean Sea Level anomaly under SSP scenarios\",\n", @@ -2436,16 +1799,7 @@ " \"long_name\": \"GMSL sims rel. \" + REF_PERIOD,\n", " }\n", " )\n", - " ds.pulse_year.attrs.update({\"description\": \"Year of GHG pulse\"})\n", - "\n", - "out_rcp.gmsl_median.attrs.update(\n", - " {\n", - " \"description\": \"Simulation of 19-year centered mean of Global Mean Sea Level anomaly under SSP scenarios, using median SESL and FAIR parameters\",\n", - " \"units\": \"cm\",\n", - " \"reference_period\": REF_PERIOD,\n", - " \"long_name\": \"GMSL med. rel. 1991-2009\",\n", - " }\n", - ")" + " ds.pulse_year.attrs.update({\"description\": \"Year of GHG pulse\"})\n" ] }, { @@ -2455,8 +1809,7 @@ "metadata": {}, "outputs": [], "source": [ - "out_rcp.to_zarr(ps.PATH_HAZARD_SLR_GMSL_FAIR_RCP, mode=\"w\")\n", - "# out_rff.to_zarr(ps.PATH_HAZARD_SLR_GMSL_FAIR_RFF, mode=\"w\")" + "out_rff.to_zarr(ps.PATH_HAZARD_SLR_GMSL_FAIR_RFF, mode=\"w\")\n" ] }, {