Skip to content

Commit

Permalink
Merge pull request #49 from JGCRI/acs-gridded-enriched
Browse files Browse the repository at this point in the history
Acs gridded enriched
  • Loading branch information
abigailsnyder authored Apr 7, 2022
2 parents a570463 + c1cc59e commit c44b4a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
24 changes: 21 additions & 3 deletions modules/tas_psl_stitching_paper1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
OUTPUT_DIR = pkg_resources.resource_filename('stitches', 'data')

# Stitch one realization per target ensemble, match in specified tolerance.
filter_future = True
Nmatches = 1
tolerance = 0.075
# #####################################################
Expand Down Expand Up @@ -103,7 +104,7 @@ def get_orig_GSAT_data(target_df):
del(i2)

# #####################################################
model_list = ["CAMS-CSM1-0", "MIROC6"]
model_list = [ "CAMS-CSM1-0", "MIROC6"]

# model_list = ["ACCESS-CM2", "ACCESS-ESM1-5", "AWI-CM-1-1-MR", "CAMS-CSM1-0", "CanESM5", "CAS-ESM2-0",
# "CESM2", "CESM2-WACCM", "FGOALS-g3", "FIO-ESM-2-0", "GISS-E2-1-G", "GISS-E2-1-H",
Expand Down Expand Up @@ -165,7 +166,7 @@ def get_orig_GSAT_data(target_df):
reproducible=True)

# Save the recipe
rp.to_csv(OUTPUT_DIR + "/tas_psl_pr/" + model_to_use + "_ssp245_rp.csv")
rp.to_csv(OUTPUT_DIR + "/tas_psl_pr/" + model_to_use + "_ssp245_rp.csv",index=False)

# Stitch save the stitched GSATs for quality assurance:
gsat_245 = stitches.gmat_stitching(rp)
Expand Down Expand Up @@ -227,7 +228,7 @@ def get_orig_GSAT_data(target_df):
reproducible=True)

# Save the recipe
rp.to_csv(OUTPUT_DIR + "/tas_psl_pr/" + model_to_use + "_ssp370_rp.csv")
rp.to_csv(OUTPUT_DIR + "/tas_psl_pr/" + model_to_use + "_ssp370_rp.csv", index=False)

# Stitch save the stitched GSATs for quality assurance:
gsat_370 = stitches.gmat_stitching(rp)
Expand Down Expand Up @@ -286,3 +287,20 @@ def get_orig_GSAT_data(target_df):
model_to_use+ '.csv'), index=False)

# end for loop over ESMs


# Filter generated files to future if needed
if filter_future:
from pathlib import Path
# read in each stitched realization, subset to 2015
entries = Path((OUTPUT_DIR + '/tas_psl_pr/stitched/'))
for entry in entries.iterdir():
print(entry.name)
ds = xr.open_dataset((OUTPUT_DIR + '/tas_psl_pr/stitched/') + entry.name)
ds = ds.sel(time = slice('2015-01-31', '2100-12-31')).copy()
ds.to_netcdf((OUTPUT_DIR + '/tas_psl_pr/stitched_future/') + entry.name)
del(ds)




1 change: 1 addition & 0 deletions stitches/fx_recepie.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ def make_recipe(target_data, archive_data, N_matches, res="mon", tol=0.1, non_ta
else:
out = recipe.copy()

out = out.sort_values(by=['stitching_id', 'target_start_yr']).reset_index(drop=True).copy()
return out


4 changes: 4 additions & 0 deletions stitches/fx_stitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def gridded_stitching(out_dir, rp):
'archive_variable', 'archive_model', 'archive_ensemble', 'stitching_id',
'archive_start_yr', 'archive_end_yr'})

rp = rp.sort_values(by=['stitching_id', 'target_start_yr']).reset_index(drop=True).copy()

# Determine which variables will be downloaded.
variables = find_var_cols(rp)
if not (len(variables) >= 1):
Expand Down Expand Up @@ -331,6 +333,8 @@ def gmat_stitching(rp):
'archive_variable', 'archive_model', 'archive_ensemble', 'stitching_id',
'archive_start_yr', 'archive_end_yr', 'tas_file'})

rp = rp.sort_values(by=['stitching_id', 'target_start_yr']).reset_index(drop=True).copy()

# One the assumptions of this function is that it only works with tas, so
# we can safely add tas as the variable column.
rp['variable'] = 'tas'
Expand Down

0 comments on commit c44b4a9

Please sign in to comment.