Skip to content

Commit

Permalink
Merge pull request #10 from iiasa/exampledata
Browse files Browse the repository at this point in the history
Exampledata
  • Loading branch information
byersiiasa authored Feb 28, 2024
2 parents 38341d9 + 5a22ebf commit 019beb9
Show file tree
Hide file tree
Showing 68 changed files with 44,885 additions and 302 deletions.
10 changes: 5 additions & 5 deletions rime/generate_aggregated_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
df = df.timeseries().reset_index()
df.dropna(how="all", inplace=True)

df[["SSP", "GMT"]] = df.scenario.str.split("_", expand=True)
df["GMT"] = df["GMT"].str.replace("p", ".").astype("float")
df[["SSP", "GWL"]] = df.scenario.str.split("_", expand=True)
df["GWL"] = df["GWL"].str.replace("p", ".").astype("float")

# df.drop(columns=['model', 'scenario'], inplace=True)

Expand All @@ -129,7 +129,7 @@
print("alive bar present")
# Apply function here
for vari in small_vars:
df_ind = loop_interpolate_gmt(
df_ind = loop_interpolate_gwl(
df.loc[df.variable.str.startswith(vari)], yr_start, yr_end
)
# dfbig = pd.concat([dfbig, df_ind])
Expand All @@ -146,7 +146,7 @@
"region",
"unit",
"SSP",
"GMT",
"GWL",
],
value_vars=years,
var_name="year",
Expand All @@ -160,7 +160,7 @@
print(indicator)
dx = (
dfp.loc[dfp.variable == indicator]
.set_index(["gmt", "year", "ssp", "region"])
.set_index(["gwl", "year", "ssp", "region"])
.to_xarray()
)
# dx.attrs['unit'] = dx.assign_coords({'unit':dx.unit.values[0,0,0,0]})
Expand Down
3,411 changes: 3,258 additions & 153 deletions rime/pp_combined_example.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions rime/process_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
fname_input_scenarios = f"emissions_temp_AR6_small.xlsx"

# Directory of map files to read as input
# impact_data_dir = f"{wd}\\data\\4_split_files_for_geoserver"
impact_data_dir = f"{wd_input}split_files"
impact_data_dir = f"{wd}\\data\\4_split_files_for_geoserver"
# impact_data_dir = f"{wd_input}split_files"


# =============================================================================
# %% From process-iamc_scenarios_gmt.py
# %% From process-iamc_scenarios_gwl.py
# =============================================================================

year_resols = [5]
Expand Down
12 changes: 6 additions & 6 deletions rime/process_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@
# Test multiple scenarios, 1 indicator
files = glob.glob(os.path.join(impact_data_dir, ind, f"*{short}_{ssp}*{ftype}.nc4"))
mapdata = xr.open_mfdataset(
files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gmt"
files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gwl"
)

mapdata = tidy_mapdata(mapdata)


df = dft.filter(model="POLES GE*")

map_out_MS = map_transform_gmt_wrapper(
map_out_MS = map_transform_gwl_wrapper(
df,
mapdata,
years,
use_dask=True,
gmt_name="gmt",
gwl_name="gwl",
interpolation=interpolation,
)

Expand Down Expand Up @@ -123,18 +123,18 @@
os.path.join(impact_data_dir, ind, f"*{short}_{ssp}*{ftype}.nc4")
)
mapdata[short] = xr.open_mfdataset(
files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gmt"
files, preprocess=remove_ssp_from_ds, combine="nested", concat_dim="gwl"
)[short]

mapdata = tidy_mapdata(mapdata)


map_out_MI = map_transform_gmt_wrapper(
map_out_MI = map_transform_gwl_wrapper(
dft.filter(model="AIM*", scenario="SSP1-34"),
mapdata,
years=years,
use_dask=False,
gmt_name="gmt",
gwl_name="gwl",
)

comp = dict(zlib=True, complevel=5)
Expand Down
16 changes: 8 additions & 8 deletions rime/process_tabledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"CO2 mode: Global mean temperatures will be derived from response \
to cumulative CO2 emissions."
)
elif mode == "GMT":
print("GMT mode: Global mean temperatures provided as input.")
elif mode == "GWL":
print("GWL mode: Global mean temperatures provided as input.")

if parallel:
dask.config.set(
Expand Down Expand Up @@ -99,11 +99,11 @@
# SCENARIO DATA PRE-PROCESSING
# Filter for temperature variable

if mode == "GMT":
if mode == "GWL":
dfp = df_scens_in.filter(variable=temp_variable)
elif mode == "CO2":
dfp = prepare_cumulative(df_scens_in, years=years, use_dask=True)
ts = dfp.timeseries().apply(co2togmt_simple)
ts = dfp.timeseries().apply(co2togwl_simple)
ts = pyam.IamDataFrame(ts)
ts.rename(
{
Expand All @@ -113,7 +113,7 @@
inplace=True,
)
# Export data to check error and relationships
# ts.append(dfp).to_csv('c://users//byers//downloads//tcre_gmt_output.csv')
# ts.append(dfp).to_csv('c://users//byers//downloads//tcre_gwl_output.csv')
dfp = ts
dfp.meta = df_scens_in.meta.copy()
dfp = dfp.filter(year=years)
Expand Down Expand Up @@ -146,9 +146,9 @@

# dfx = dft.iloc[0].squeeze() # FOR DEBUIGGING THE FUNCTION
outd = ddf.apply(
table_impacts_gmt, dsi=dsi, axis=1, meta=("result", None)
table_impacts_gwl, dsi=dsi, axis=1, meta=("result", None)
)
# outdd = client.map(ddf.apply(table_impacts_gmt, dsi=dsi, axis=1))
# outdd = client.map(ddf.apply(table_impacts_gwl, dsi=dsi, axis=1))

with ProgressBar():
# try:
Expand All @@ -157,7 +157,7 @@
# except(InvalidIndexError):
# print(f'PROBLEM {f}')
else:
df_new = dft.apply(table_impacts_gmt, dsi=dsi, axis=1)
df_new = dft.apply(table_impacts_gwl, dsi=dsi, axis=1)

expandedd = pd.concat([df_new[x] for x in df_new.index])
print(f" Done: {time.time()-start}")
Expand Down
Loading

0 comments on commit 019beb9

Please sign in to comment.