diff --git a/.virtual_documents/rime/pp_combined_example.ipynb b/.virtual_documents/rime/pp_combined_example.ipynb new file mode 100644 index 0000000..b3f1821 --- /dev/null +++ b/.virtual_documents/rime/pp_combined_example.ipynb @@ -0,0 +1,407 @@ + + + +from rime.process_config import * +from rime.rime_functions import * +from rime.utils import * + +import dask +import dask.dataframe as dd +# from dask.diagnostics import ProgressBar +from dask.diagnostics import Profiler, ResourceProfiler, CacheProfiler, ProgressBar +from dask.distributed import Client + +# from dask.distributed import Client # uncomment this to open Dask client to see performance +import glob +import numpy as np +import pandas as pd +import pyam +import re +import time +import xarray as xr +import yaml + + +# Load a yaml file that will help select multiple climate indicator files (not necessarily needed) +with open("indicator_params.yml", "r") as f: + params = yaml.full_load(f) + + +dask.config.set(scheduler="processes") +dask.config.set(num_workers=num_workers) +client = Client() # uncomment this to open Dask client + + + + + + + + +os.getcwd() + + +df_scens_in = pyam.IamDataFrame('test_data/emissions_temp_AR6_small.xlsx') +dft = df_scens_in.filter(variable=temp_variable) # temp_variable as defined in the config file, = 'AR6 climate diagnostics|Surface Temperature (GSAT)|MAGICCv7.5.3|50.0th Percentile' + +# Replace & fill missing SSP scenario allocation +dft = ssp_helper(dft, ssp_meta_col="Ssp_family", default_ssp="SSP2") + + + + + +scenarios = ["SSP1-26", "SSP2-45", "SSP3-Baseline", "SSP5-Baseline"] +variable = ( + "AR6 climate diagnostics|Surface Temperature (GSAT)|MAGICCv7.5.3|50.0th Percentile" +) +ssps = df_scens_in.filter(scenario=scenarios, model="IMAGE*", variable=variable) +imps = df_scens_in.filter( + IMP_marker=["CurPol", "ModAct", "SP", "GS", "Neg"], variable=variable +) # ,'Ren-2.0','Neg-2.0' +ssps_imp = ssps.append(imps) +ssps_imp = ssp_helper(ssps_imp, ssp_meta_col="Ssp_family", default_ssp="SSP2") +ssps_imp + + + + + + + + +# Requires some configuration - need to download the data from https://zenodo.org/records/10212339, and set the file paths in the file process_config.py + + + +# ind = "pr" +# var = "pr" +# short = "r10" # params["indicators"][ind][var]["short_name"] +ssp = "ssp2" +ftype = "abs" + + +# published data + +# # Prepare data +# impact_data_dir = 'test_data//' +# files = glob.glob(f"{impact_data_dir}/{var}*{short}_*{ftype}.nc4") +# mapdata = xr.open_mfdataset( +# files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gmt" +# ) +# mapdata = xr.concat([mapdata[x] for x in mapdata.data_vars], dim='gmt').to_dataset(name=f'{var}_{short}') +# mapdata = tidy_mapdata(mapdata) +# mapdata = mapdata.sortby("gmt").drop_duplicates("gmt") + + +# impact_data_dir = '/mnt/c/users/byers/iiasa/ECE.prog - Documents/Research Theme - NEXUS/Hotspots_Explorer_2p0/rcre_testing/rime_testdata' +# files = glob.glob(f"{impact_data_dir}/*{var}*{short}_*{ftype}.nc4") +# files + + + +# Prepare data (using split_files on sharepoint) +# impact_data_dir = '/mnt/c/users/byers/iiasa/ECE.prog - Documents/Research Theme - NEXUS/Hotspots_Explorer_2p0/rcre_testing/rime_testdata' +impact_data_dir = 'test_data' +# indicators = ['dri','iavar'] +ind = 'dri_qtot' + +files = glob.glob(f"{impact_data_dir}/*{ind}_*{ftype}.nc4") +mapdata = xr.open_mfdataset( + files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gwl" +) +mapdata +# mapdata = xr.concat([mapdata[x] for x in mapdata.data_vars], dim='gwl').to_dataset(name=f'{var}_{short}') +mapdata = tidy_mapdata(mapdata) +# mapdata = mapdata.sortby("gwl").drop_duplicates("gwl") + + +mapdata + + +print("Test multiple IAM scenarios, 1 indicator") + +start = time.time() + +# Run function +# Using dask for small numbers of scenarios ~<10 can be slower due to spawning of workers. +# use_dask=True currently broken +map_out_MS = map_transform_gwl_wrapper( + ssps_imp, + mapdata, + years, + caution_checks=True, + use_dask=False, + include_orig_gwl=False, + gwl_name="gwl", + drawdown_max=0.15, + temp_min=1.2, + temp_max=3.0, + interpolation=0.01, +) + +comp = dict(zlib=True, complevel=5) +encoding = {var: comp for var in map_out_MS.data_vars} +filename = f"scenario_maps_multiscenario_{ftype}_test_notebook.nc" +map_out_MS.to_netcdf(filename, encoding=encoding) + +print("FINISHED Test multiple scenarios, 1 indicator") +print(f"{time.time()-start}") + + +map_out_MS + + + + + + + + +# Doesn't work -0 +# AttributeError: 'DataArray' object has no attribute 'rename_vars' +# lines 230-233 in map_transform_gmt + +gwl_name = "gwl" +print("Test 1 scenario, multiple indicators") +start = time.time() +ssp = "ssp2" +mapdata = xr.Dataset() + +# impact_data_dir = '/mnt/p/watxene/ISIMIP_postprocessed/cse/split_files_fixed' +impact_data_dir = 'test_data' +indicators = ['dri','iavar'] +for ind in indicators: + + print(ind) + files = glob.glob(f"{impact_data_dir}/ISI*{ind}*_{ftype}*.nc4") + + a = xr.open_mfdataset( + files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gwl") + for x in a.data_vars: + mapdata[x] = a[x] + + +mapdata = tidy_mapdata(mapdata) +mapdata + + +os.getcwd() + + + + + +map_out_MI = map_transform_gwl_wrapper( + ssps_imp.filter(IMP_marker="CurPol"), + mapdata, + years, + use_dask=False, + include_orig_gwl=False, + gwl_name="gwl", + drawdown_max=0.15, + temp_min=1.2, + temp_max=3.0, + interpolation=0.01, +) + +comp = dict(zlib=True, complevel=5) +encoding = {var: comp for var in map_out_MI.data_vars} +filename = f"scenario_maps_multiindicator_{ftype}_test_notebook.nc" +# map_out_MI.to_netcdf(filename, encoding=encoding) + +print("FINISHED 1 scenario, multiple indicators") +print(f"{time.time()-start}") + + + + + +map_out_MI + + + + + +filename = "test_map_notebook.html" +plot_maps_dashboard( + map_out_MI, + filename=filename, + year=2063, + cmap="magma_r", + shared_axes=True, + clim=None, +) +#os.startfile(filename) # Windows +import webbrowser +webbrowser.open(f'file://{os.path.realpath(filename)}') + + + + + + + + +filesall = glob.glob(fname_input_climate) +files = filesall # [:6] +f = files[-0] +# load input climate impacts data file +ds = xr.open_mfdataset(f) +ds = ds.sel(year=years) +ds + + +varis = list(ds.data_vars.keys())[:lvaris] +dsi = ds[varis] +print(f"# of variables = {len(varis)}") + + + + + +mode = "GMT" +if mode == "GMT": + dfp = df_scens_in.filter(variable=temp_variable) +elif mode == "bypass": + dfp = prepare_cumulative(df_scens_in, years=years, use_dask=True) + ts = dfp.timeseries().apply(co2togmt_simple) + ts = pyam.IamDataFrame(ts) + ts.rename( + { + "variable": {ts.variable[0]: "RIME|GSAT_tcre"}, + "unit": {ts.unit[0]: "°C"}, + }, + inplace=True, + ) + # Export data to check error and relationships + # ts.append(dfp).to_csv('c://users//byers//downloads//tcre_gmt_output.csv') + dfp = ts + dfp.meta = df_scens_in.meta.copy() +dfp = dfp.filter(year=years) + + +# For testing on C1 scenarios +# few_scenarios = True +# very_few_scenarios = False + +# if few_scenarios: +# dfp = dfp.filter(Category=["C1*"]) +# if very_few_scenarios: +# dfp = dfp.filter(model="REMIND 2.1*", scenario="*") + +dfp = ssps_imp + + +# pre-prepare the dataset into correct format +# Assign SSP to meta and select SSP2 in case SSP not present in name +dfp = ssp_helper(dfp, ssp_meta_col="Ssp_family", default_ssp="SSP2", keep_meta=False) + +dft = dfp.timeseries() +dft = dft.join(dfp.meta["Ssp_family"]).reset_index() +# dft = dft.apply(fix_duplicate_temps, years=years, axis=1) + + + + + +start = time.time() +year_res = 10 +parallel = True +if parallel: + """ + For parallel processing, convert dft as a wide IAMC pd.Dataframe + into a dask.DataFrame. + """ + ddf = dd.from_pandas(dft, npartitions=1000) + + # dfx = dft.iloc[0].squeeze() # FOR DEBUIGGING THE FUNCTION + outd = ddf.apply( + table_impacts_gmt, + dsi=dsi, + ssp_meta_col="Ssp_family", + axis=1, + meta=("result", None), + ) + + with ProgressBar(): + # try: + df_new = outd.compute(num_workers=num_workers) +else: + df_new = dft.apply(table_impacts_gmt, dsi=dsi, axis=1) + +expandeddGMT = pd.concat([df_new[x] for x in df_new.index]) +print(f" Done: {time.time()-start}") + +filename = f"RIME_output_{region}_{year_res}yr.csv" + +# expandedd.to_csv(filename, encoding="utf-8", index=False) +print(f" Saved: {region} yrs={year_res}\n {time.time()-start}") +print(f"{len(dsi.data_vars)} variables, {len(dfp.meta)} scenarios") + + + + + +expandeddGMT = pyam.IamDataFrame(expandeddGMT) + + +expandeddGMT.variable + + +# model = "IMAG*" +scenario = [ + "CO_Bridge", + "EN_INDCi2030_3000f", + "EN_NPi2020_400f_lowBECCS", + # 'NGFS2_Current Policies', + "SSP1-26", + "SSP2-45", + # 'SSP3-Baseline', + # 'SSP5-Baseline', + "SusDev_SDP-PkBudg1000", +] +variable = "RIME|sdii|Hazard|Risk score|Population weighted" +# variable = 'RIME|wsi|Exposure|Population|%' +variable = "RIME|cdd|Exposure|Population|%" +expandeddGMT.filter(variable=variable, scenario=scenario, region="GBR").plot() + + +expandeddGMT.filter(variable=variable, scenario=scenario, region="PAK").plot() + + +expandeddGMT.variable + + + + + +imps.scenario + + +color_map = { + "SSP1-26": "AR6-SSP1-2.6", + "SSP2-45": "AR6-SSP2-4.5", + "SSP3-Baseline": "AR6-SSP3-7.0", + "SSP5-Baseline": "AR6-SSP5-8.5", + "NGFS2_Current Policies": "AR6-IP-CurPol", + # 'EN_NPi2020_900f': 'AR6-IMP-Neg2.0', + "EN_INDCi2030_3000f": "AR6-IP-ModAct", + # 'SSP2_openres_lc_50': 'AR6-IMP-Ren2.0', + # AR6-IMP-GS', + "CO_Bridge": "AR6-IMP-GS", + "EN_NPi2020_400f_lowBECCS": "AR6-IMP-Neg", + "SusDev_SDP-PkBudg1000": "AR6-IMP-SP", +} + +pyam.run_control().update({"color": {"scenario": color_map}}) + +ssps_imp.filter( + variable="AR6 climate diagnostics|Surface Temperature (GSAT)|MAGICCv7.5.3|50.0th Percentile", + scenario="SSP*", +).plot(legend=False, fill_between=True, color="scenario", title="") + + +ssps_imp.filter( + variable="AR6 climate diagnostics|Surface Temperature (GSAT)|MAGICCv7.5.3|50.0th Percentile" +).plot(legend=False, fill_between=True, color="scenario", title="") diff --git a/poetry.lock b/poetry.lock index 57b2da4..9b39fe8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1242,49 +1242,62 @@ files = [ [[package]] name = "matplotlib" -version = "3.8.3" +version = "3.7.0" description = "Python plotting package" optional = false -python-versions = ">=3.9" +python-versions = ">=3.8" files = [ - {file = "matplotlib-3.8.3-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:cf60138ccc8004f117ab2a2bad513cc4d122e55864b4fe7adf4db20ca68a078f"}, - {file = "matplotlib-3.8.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:5f557156f7116be3340cdeef7f128fa99b0d5d287d5f41a16e169819dcf22357"}, - {file = "matplotlib-3.8.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f386cf162b059809ecfac3bcc491a9ea17da69fa35c8ded8ad154cd4b933d5ec"}, - {file = "matplotlib-3.8.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b3c5f96f57b0369c288bf6f9b5274ba45787f7e0589a34d24bdbaf6d3344632f"}, - {file = "matplotlib-3.8.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:83e0f72e2c116ca7e571c57aa29b0fe697d4c6425c4e87c6e994159e0c008635"}, - {file = "matplotlib-3.8.3-cp310-cp310-win_amd64.whl", hash = "sha256:1c5c8290074ba31a41db1dc332dc2b62def469ff33766cbe325d32a3ee291aea"}, - {file = "matplotlib-3.8.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:5184e07c7e1d6d1481862ee361905b7059f7fe065fc837f7c3dc11eeb3f2f900"}, - {file = "matplotlib-3.8.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d7e7e0993d0758933b1a241a432b42c2db22dfa37d4108342ab4afb9557cbe3e"}, - {file = "matplotlib-3.8.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:04b36ad07eac9740fc76c2aa16edf94e50b297d6eb4c081e3add863de4bb19a7"}, - {file = "matplotlib-3.8.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7c42dae72a62f14982f1474f7e5c9959fc4bc70c9de11cc5244c6e766200ba65"}, - {file = "matplotlib-3.8.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:bf5932eee0d428192c40b7eac1399d608f5d995f975cdb9d1e6b48539a5ad8d0"}, - {file = "matplotlib-3.8.3-cp311-cp311-win_amd64.whl", hash = "sha256:40321634e3a05ed02abf7c7b47a50be50b53ef3eaa3a573847431a545585b407"}, - {file = "matplotlib-3.8.3-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:09074f8057917d17ab52c242fdf4916f30e99959c1908958b1fc6032e2d0f6d4"}, - {file = "matplotlib-3.8.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5745f6d0fb5acfabbb2790318db03809a253096e98c91b9a31969df28ee604aa"}, - {file = "matplotlib-3.8.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b97653d869a71721b639714b42d87cda4cfee0ee74b47c569e4874c7590c55c5"}, - {file = "matplotlib-3.8.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:242489efdb75b690c9c2e70bb5c6550727058c8a614e4c7716f363c27e10bba1"}, - {file = "matplotlib-3.8.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:83c0653c64b73926730bd9ea14aa0f50f202ba187c307a881673bad4985967b7"}, - {file = "matplotlib-3.8.3-cp312-cp312-win_amd64.whl", hash = "sha256:ef6c1025a570354297d6c15f7d0f296d95f88bd3850066b7f1e7b4f2f4c13a39"}, - {file = "matplotlib-3.8.3-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:c4af3f7317f8a1009bbb2d0bf23dfaba859eb7dd4ccbd604eba146dccaaaf0a4"}, - {file = "matplotlib-3.8.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4c6e00a65d017d26009bac6808f637b75ceade3e1ff91a138576f6b3065eeeba"}, - {file = "matplotlib-3.8.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7b49ab49a3bea17802df6872f8d44f664ba8f9be0632a60c99b20b6db2165b7"}, - {file = "matplotlib-3.8.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6728dde0a3997396b053602dbd907a9bd64ec7d5cf99e728b404083698d3ca01"}, - {file = "matplotlib-3.8.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:813925d08fb86aba139f2d31864928d67511f64e5945ca909ad5bc09a96189bb"}, - {file = "matplotlib-3.8.3-cp39-cp39-win_amd64.whl", hash = "sha256:cd3a0c2be76f4e7be03d34a14d49ded6acf22ef61f88da600a18a5cd8b3c5f3c"}, - {file = "matplotlib-3.8.3-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:fa93695d5c08544f4a0dfd0965f378e7afc410d8672816aff1e81be1f45dbf2e"}, - {file = "matplotlib-3.8.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e9764df0e8778f06414b9d281a75235c1e85071f64bb5d71564b97c1306a2afc"}, - {file = "matplotlib-3.8.3-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:5e431a09e6fab4012b01fc155db0ce6dccacdbabe8198197f523a4ef4805eb26"}, - {file = "matplotlib-3.8.3.tar.gz", hash = "sha256:7b416239e9ae38be54b028abbf9048aff5054a9aba5416bef0bd17f9162ce161"}, + {file = "matplotlib-3.7.0-cp310-cp310-macosx_10_12_universal2.whl", hash = "sha256:3da8b9618188346239e51f1ea6c0f8f05c6e218cfcc30b399dd7dd7f52e8bceb"}, + {file = "matplotlib-3.7.0-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:c0592ba57217c22987b7322df10f75ef95bc44dce781692b4b7524085de66019"}, + {file = "matplotlib-3.7.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:21269450243d6928da81a9bed201f0909432a74e7d0d65db5545b9fa8a0d0223"}, + {file = "matplotlib-3.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:eb2e76cd429058d8954121c334dddfcd11a6186c6975bca61f3f248c99031b05"}, + {file = "matplotlib-3.7.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:de20eb1247725a2f889173d391a6d9e7e0f2540feda24030748283108b0478ec"}, + {file = "matplotlib-3.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c5465735eaaafd1cfaec3fed60aee776aeb3fd3992aa2e49f4635339c931d443"}, + {file = "matplotlib-3.7.0-cp310-cp310-win32.whl", hash = "sha256:092e6abc80cdf8a95f7d1813e16c0e99ceda8d5b195a3ab859c680f3487b80a2"}, + {file = "matplotlib-3.7.0-cp310-cp310-win_amd64.whl", hash = "sha256:4f640534ec2760e270801056bc0d8a10777c48b30966eef78a7c35d8590915ba"}, + {file = "matplotlib-3.7.0-cp311-cp311-macosx_10_12_universal2.whl", hash = "sha256:f336e7014889c38c59029ebacc35c59236a852e4b23836708cfd3f43d1eaeed5"}, + {file = "matplotlib-3.7.0-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:3a10428d4f8d1a478ceabd652e61a175b2fdeed4175ab48da4a7b8deb561e3fa"}, + {file = "matplotlib-3.7.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:46ca923e980f76d34c1c633343a72bb042d6ba690ecc649aababf5317997171d"}, + {file = "matplotlib-3.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c849aa94ff2a70fb71f318f48a61076d1205c6013b9d3885ade7f992093ac434"}, + {file = "matplotlib-3.7.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:827e78239292e561cfb70abf356a9d7eaf5bf6a85c97877f254009f20b892f89"}, + {file = "matplotlib-3.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:691ef1f15360e439886186d0db77b5345b24da12cbc4fc57b26c4826db4d6cab"}, + {file = "matplotlib-3.7.0-cp311-cp311-win32.whl", hash = "sha256:21a8aeac39b4a795e697265d800ce52ab59bdeb6bb23082e2d971f3041074f02"}, + {file = "matplotlib-3.7.0-cp311-cp311-win_amd64.whl", hash = "sha256:01681566e95b9423021b49dea6a2395c16fa054604eacb87f0f4c439750f9114"}, + {file = "matplotlib-3.7.0-cp38-cp38-macosx_10_12_universal2.whl", hash = "sha256:cf119eee4e57389fba5ac8b816934e95c256535e55f0b21628b4205737d1de85"}, + {file = "matplotlib-3.7.0-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:21bd4033c40b95abd5b8453f036ed5aa70856e56ecbd887705c37dce007a4c21"}, + {file = "matplotlib-3.7.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:111ef351f28fd823ed7177632070a6badd6f475607122bc9002a526f2502a0b5"}, + {file = "matplotlib-3.7.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:f91d35b3ef51d29d9c661069b9e4ba431ce283ffc533b981506889e144b5b40e"}, + {file = "matplotlib-3.7.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:0a776462a4a63c0bfc9df106c15a0897aa2dbab6795c693aa366e8e283958854"}, + {file = "matplotlib-3.7.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0dfd4a0cbd151f6439e6d7f8dca5292839ca311e7e650596d073774847ca2e4f"}, + {file = "matplotlib-3.7.0-cp38-cp38-win32.whl", hash = "sha256:56b7b79488209041a9bf7ddc34f1b069274489ce69e34dc63ae241d0d6b4b736"}, + {file = "matplotlib-3.7.0-cp38-cp38-win_amd64.whl", hash = "sha256:8665855f3919c80551f377bc16df618ceabf3ef65270bc14b60302dce88ca9ab"}, + {file = "matplotlib-3.7.0-cp39-cp39-macosx_10_12_universal2.whl", hash = "sha256:f910d924da8b9fb066b5beae0b85e34ed1b6293014892baadcf2a51da1c65807"}, + {file = "matplotlib-3.7.0-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:cf6346644e8fe234dc847e6232145dac199a650d3d8025b3ef65107221584ba4"}, + {file = "matplotlib-3.7.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3d1e52365d8d5af699f04581ca191112e1d1220a9ce4386b57d807124d8b55e6"}, + {file = "matplotlib-3.7.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c869b646489c6a94375714032e5cec08e3aa8d3f7d4e8ef2b0fb50a52b317ce6"}, + {file = "matplotlib-3.7.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f4ddac5f59e78d04b20469bc43853a8e619bb6505c7eac8ffb343ff2c516d72f"}, + {file = "matplotlib-3.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fb0304c1cd802e9a25743414c887e8a7cd51d96c9ec96d388625d2cd1c137ae3"}, + {file = "matplotlib-3.7.0-cp39-cp39-win32.whl", hash = "sha256:a06a6c9822e80f323549c6bc9da96d4f233178212ad9a5f4ab87fd153077a507"}, + {file = "matplotlib-3.7.0-cp39-cp39-win_amd64.whl", hash = "sha256:cb52aa97b92acdee090edfb65d1cb84ea60ab38e871ba8321a10bbcebc2a3540"}, + {file = "matplotlib-3.7.0-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:3493b48e56468c39bd9c1532566dff3b8062952721b7521e1f394eb6791495f4"}, + {file = "matplotlib-3.7.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7d0dcd1a0bf8d56551e8617d6dc3881d8a1c7fb37d14e5ec12cbb293f3e6170a"}, + {file = "matplotlib-3.7.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:51fb664c37714cbaac69c16d6b3719f517a13c96c3f76f4caadd5a0aa7ed0329"}, + {file = "matplotlib-3.7.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:4497d88c559b76da320b7759d64db442178beeea06a52dc0c629086982082dcd"}, + {file = "matplotlib-3.7.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:9d85355c48ef8b9994293eb7c00f44aa8a43cad7a297fbf0770a25cdb2244b91"}, + {file = "matplotlib-3.7.0-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:03eb2c8ff8d85da679b71e14c7c95d16d014c48e0c0bfa14db85f6cdc5c92aad"}, + {file = "matplotlib-3.7.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:71b751d06b2ed1fd017de512d7439c0259822864ea16731522b251a27c0b2ede"}, + {file = "matplotlib-3.7.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:b51ab8a5d5d3bbd4527af633a638325f492e09e45e78afdf816ef55217a09664"}, + {file = "matplotlib-3.7.0.tar.gz", hash = "sha256:8f6efd313430d7ef70a38a3276281cb2e8646b3a22b3b21eb227da20e15e6813"}, ] [package.dependencies] contourpy = ">=1.0.1" cycler = ">=0.10" fonttools = ">=4.22.0" -kiwisolver = ">=1.3.1" -numpy = ">=1.21,<2" +kiwisolver = ">=1.0.1" +numpy = ">=1.20" packaging = ">=20.0" -pillow = ">=8" +pillow = ">=6.2.0" pyparsing = ">=2.3.1" python-dateutil = ">=2.7" @@ -1796,20 +1809,20 @@ test = ["enum34", "ipaddress", "mock", "pywin32", "wmi"] [[package]] name = "pyam-iamc" -version = "1.7.0" +version = "1.9.0" description = "Analysis & visualization of integrated-assessment scenarios" optional = false -python-versions = "<3.11,>=3.7.1" +python-versions = "<3.12,>=3.7.1" files = [ - {file = "pyam-iamc-1.7.0.tar.gz", hash = "sha256:0af22a23585ed30363e8755a7e2ac4a646df71c5375f57b3a9124fb567cd32e4"}, - {file = "pyam_iamc-1.7.0-py3-none-any.whl", hash = "sha256:512a67ea145a09ab7db34b49ca70e81800f602ee46ad75a179c51f0a95cafb9b"}, + {file = "pyam-iamc-1.9.0.tar.gz", hash = "sha256:a37f853b4e563628e78ff79a639d5636e25cdc2b5db35d13b5ac7c27ccdf6333"}, + {file = "pyam_iamc-1.9.0-py3-none-any.whl", hash = "sha256:91f6841326197c5b32a511c33198e7dcf32cd47e02bb105bb3b0764bf7419acd"}, ] [package.dependencies] httpx = {version = "*", extras = ["http2"]} iam-units = ">=2020.4.21" importlib-metadata = "*" -matplotlib = ">=3.2.0" +matplotlib = ">=3.5.0,<3.7.1" numpy = ">=1.19.0,<1.24" openpyxl = "*" pandas = ">=1.2.0" @@ -1826,11 +1839,11 @@ wquantiles = "*" xlsxwriter = "*" [package.extras] -docs = ["autodocsumm", "kaleido", "nbsphinx", "numpydoc", "pillow", "sphinx", "sphinx-gallery", "sphinxcontrib-bibtex (<2.0)", "sphinxcontrib-programoutput"] +docs = ["autodocsumm", "kaleido", "nbsphinx", "numpydoc", "pillow", "sphinx", "sphinx-gallery"] optional-io-formats = ["datapackage", "pandas-datareader", "unfccc-di-api (>=3.0.1)", "xlrd"] optional-plotting = ["plotly"] tests = ["coverage", "coveralls", "pytest", "pytest-cov", "pytest-mpl"] -tutorials = ["ipykernel", "jupyter-client", "nbconvert", "nbformat", "pypandoc"] +tutorials = ["ipykernel", "jupyter-client", "nbconvert (>=7.3)", "nbformat", "pypandoc"] [[package]] name = "pybtex" @@ -2918,4 +2931,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.10, <3.11" -content-hash = "24b78587cb44cf03d5d2a74b5599ba9824a78fcfa04b127f70cf5a98220ca3b0" +content-hash = "a07d3ecb9ec6479240718b42fec57b544c2fc7f14fdacad466050d3ac6ae72a3" diff --git a/pyproject.toml b/pyproject.toml index 83a478f..e9f5114 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,10 +17,10 @@ dask = "^2024.2.0" distributed = "^2024.2.0" holoviews = "^1.18.3" hvplot = "^0.9.2" -matplotlib = "^3.8.3" +matplotlib = "^3.6" numpy = "^1.23" pandas = "^2.2.0" -pyam-iamc = "^1.7" +pyam-iamc = "^1.8" pyyaml = "^6.0.1" rich = "^13.7.0" scipy = "^1.12.0" diff --git a/rime/rime_functions.py b/rime/rime_functions.py index e778677..4ce439b 100644 --- a/rime/rime_functions.py +++ b/rime/rime_functions.py @@ -145,16 +145,16 @@ def table_impacts_gwl( tgt_g = xr.DataArray(tt[years].values, dims="points") # Do selection (lookup) of datapoints in dsd ix along the years & gwl points. - try: - agh = dsd.sel(year=tgt_y, gwl=tgt_g, method="nearest").to_dataframe( - name=indicator - ) - agh = agh.reset_index() - aghp = agh.pivot_table(index="region", columns="year", values=indicator) - edf = edf.join(aghp, on="region") + # try: + agh = dsd.sel(year=tgt_y, gwl=tgt_g, method="nearest").to_dataframe( + name=indicator + ) + agh = agh.reset_index() + aghp = agh.pivot_table(index="region", columns="year", values=indicator) + edf = edf.join(aghp, on="region") - except Exception as e: - print(f"skip {model} {scenario}") + # except Exception as e: + # print(f"skip {model} {scenario}") idf = pd.concat([idf, edf]).reset_index(drop=True) @@ -222,8 +222,8 @@ def map_transform_gwl( """ - if len(df1.variable) > 1: - raise Exception("Error: more than 1 variable in DataFrame") + # if len(df1.variable) > 1: + # raise Exception("Error: more than 1 variable in DataFrame") if len(df1.meta) > 1: raise Exception("Error: more than 1 model-scenario in DataFrame") diff --git a/rime/utils.py b/rime/utils.py index 8e18a11..08a5b3c 100644 --- a/rime/utils.py +++ b/rime/utils.py @@ -119,6 +119,8 @@ def tidy_mapdata(mapdata): dvs = mapdata.data_vars if "threshold" in mapdata.coords: mapdata = mapdata.rename({"threshold": "gwl"}) + if "gmt" in mapdata.coords: + mapdata = mapdata.rename({"gmt": "gwl"}) mapdata = mapdata.set_index( {"lon": "lon", "lat": "lat", "gwl": "gwl"} ).reset_coords()