Commit 37274446 authored by Lana B's avatar Lana B
Browse files

start with nan-filled array and decide whether to create a new amoc_index-file...

start with nan-filled array and decide whether to create a new amoc_index-file or to fill the existing one)
parent 3a90c5bb
...@@ -16,6 +16,11 @@ import xarray as xr ...@@ -16,6 +16,11 @@ import xarray as xr
from get_subpolar_gyre_functions import * from get_subpolar_gyre_functions import *
# file where to save results
output_file = "CMIP6_amoc_index.nc"
# should the output file be overwritten or should the values be filled in the exisitng one
overwrite_output_file = False
# Regional variables # Regional variables
latitude_maximum = 61 latitude_maximum = 61
latitude_minimum = 46 latitude_minimum = 46
...@@ -45,7 +50,9 @@ get_values() ...@@ -45,7 +50,9 @@ get_values()
paths_all_models = get_paths_dict() paths_all_models = get_paths_dict()
# Load shared amoc index file # Load shared amoc index file
amoc_index = xr.open_dataarray("CMIP6_amoc_index.nc") if overwrite_output_file:
create_new_amoc_index_file(output_file)
amoc_index = xr.open_dataarray(output_file)
amoc_index = time_to_year_month(amoc_index) amoc_index = time_to_year_month(amoc_index)
...@@ -70,6 +77,6 @@ for model, emembers in paths_all_models.items(): ...@@ -70,6 +77,6 @@ for model, emembers in paths_all_models.items():
# Save the amoc index file with its new values # Save the amoc index file with its new values
amoc_index.to_netcdf('CMIP6_amoc_index.nc') amoc_index.to_netcdf(output_file)
...@@ -13,7 +13,7 @@ import glob ...@@ -13,7 +13,7 @@ import glob
import xarray as xr import xarray as xr
# Global variables # GLOBAL VARIABLES
# Region # Region
lat_max = 61 lat_max = 61
lat_min = 46 lat_min = 46
...@@ -27,7 +27,7 @@ lat_keys = ['lat', 'latitude', 'nav_lat'] ...@@ -27,7 +27,7 @@ lat_keys = ['lat', 'latitude', 'nav_lat']
lon_keys = ['lon', 'longitude', 'nav_lon'] lon_keys = ['lon', 'longitude', 'nav_lon']
# Functions to specify/edit the global variables ## FUNCTIONS TO SPECIFY/EDIT THE GLOBAL VARIABLES
# set parameters # set parameters
def set_boundaries( def set_boundaries(
longitude_maximum = 360-20, longitude_maximum = 360-20,
...@@ -59,6 +59,8 @@ def get_values(): ...@@ -59,6 +59,8 @@ def get_values():
print("lon_keys: "+str(lon_keys)) print("lon_keys: "+str(lon_keys))
print("lat_keys: "+str(lat_keys)) print("lat_keys: "+str(lat_keys))
## FILL THE AMOC_INDEX-FILE WITH THE SUBPOLAR GYRE OF THE CMIP6 MODELS
# function to get the longitude / latitude keys from the model # function to get the longitude / latitude keys from the model
def get_lon_lat_keys(data, location_keys): def get_lon_lat_keys(data, location_keys):
str_loc = [key for key in data.coords.keys() if key in location_keys] str_loc = [key for key in data.coords.keys() if key in location_keys]
...@@ -124,6 +126,39 @@ def get_subpolar_gyre(model, emember, print_info=False, paths_all_models=None): ...@@ -124,6 +126,39 @@ def get_subpolar_gyre(model, emember, print_info=False, paths_all_models=None):
return spg return spg
## CREATE NEW OUTPUT FILE
def create_new_amoc_index_file(output_file):
nparray = np.empty((34, 10, 165*12))
nparray.fill(np.nan)
dims = ('models', 'ensemble_members', 'time')
models = ['AWI-CM-1-1-MR', 'BCC-CSM2-MR', 'BCC-ESM1', 'CAMS-CSM1-0',
'FGOALS-f3-L', 'FGOALS-g3', 'IITM-ESM', 'CanESM5', 'CNRM-CM6-1',
'CNRM-CM6-1-HR', 'CNRM-ESM2-1', 'E3SM-1-1', 'EC-Earth3',
'EC-Earth3-Veg', 'FIO-ESM-2-0', 'INM-CM4-8', 'INM-CM5-0',
'IPSL-CM6A-LR', 'MIROC6', 'HadGEM3-GC31-LL', 'HadGEM3-GC31-MM',
'UKESM1-0-LL', 'MPI-ESM1-2-HR', 'MRI-ESM2-0', 'GISS-E2-1-G', 'CESM2',
'CESM2-WACCM', 'NorESM1-F', 'NorESM2-LM', 'GFDL-AM4', 'GFDL-CM4',
'GFDL-ESM4', 'NESM3', 'SAM0-UNICON']
ensemble_members = ['r1i1p1f1', 'r2i1p1f1', 'r3i1p1f1', 'r4i1p1f1', 'r5i1p1f1', 'r6i1p1f1',
'r7i1p1f1', 'r8i1p1f1', 'r9i1p1f1', 'r10i1p1f1']
time = np.arange(np.datetime64('1850-01'), np.datetime64('2015-01'))
amoc_index = xr.DataArray(
nparray,
dims = dims,
coords = dict(
models = xr.DataArray(models, dims="models", coords=dict(models=("models", models))),
time = xr.DataArray(time, dims="time", coords=dict(time=("time", time))),
ensemble_members = xr.DataArray(ensemble_members, dims="ensemble_members", coords=dict(ensemble_members=("ensemble_members", ensemble_members))),
)
)
amoc_index.to_netcdf(output_file)
## PLOTS
# make plots of world # make plots of world
def make_nice_plot(ds, str_lon, str_lat): def make_nice_plot(ds, str_lon, str_lat):
fig, axis = plt.subplots( fig, axis = plt.subplots(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment