From a98778b31513724593d436e1cd8afb2d645b2a8f Mon Sep 17 00:00:00 2001 From: Lisa Bock Date: Wed, 6 Dec 2023 14:17:58 +0100 Subject: [PATCH] add LTS --- .../diag_scripts/causal_clouds_timeseries.py | 52 +++++++--- .../recipes/recipe_preprocess_cloud.yml | 95 ++++++++++--------- esmvaltool/recipes/recipe_preprocess_era5.yml | 32 ++++--- 3 files changed, 114 insertions(+), 65 deletions(-) diff --git a/esmvaltool/diag_scripts/causal_clouds_timeseries.py b/esmvaltool/diag_scripts/causal_clouds_timeseries.py index 396486da7d..fbd200b442 100644 --- a/esmvaltool/diag_scripts/causal_clouds_timeseries.py +++ b/esmvaltool/diag_scripts/causal_clouds_timeseries.py @@ -20,14 +20,12 @@ logger = logging.getLogger(Path(__file__).stem) -def get_provenance_record(attributes, ancestor_files): +def get_provenance_record(caption, ancestor_files): """Create a provenance record describing the diagnostic data and plot.""" - caption = attributes['caption'].format(**attributes) - record = { 'caption': caption, 'statistics': ['mean'], - 'domains': ['regional'], + 'domains': ['reg'], 'plot_types': ['times'], 'authors': ['bock_lisa'], 'references': ['cmug'], @@ -104,11 +102,13 @@ def potential_temperature(temperature, plev): def calculate_theta(var, input_data, cfg): # This function calculates the potential temperature for one level. - t_data = select_metadata(input_data, short_name = 'ta'+var[-3:]) + print(input_data) + t_data = select_metadata(input_data, short_name='ta'+var[5:]) + print(t_data) t_file = t_data[0]['filename'] temperature = read_data(t_file) - pressure = float(var[-3:]) + pressure = float(var[5:]) theta_x = potential_temperature(temperature, pressure) @@ -118,10 +118,32 @@ def calculate_theta(var, input_data, cfg): if "caption" not in t_data[0]: t_data[0]['caption'] = t_file provenance_record = get_provenance_record( - t_data[0], ancestor_files=[t_file]) + t_data[0]['caption'], ancestor_files=[t_file]) save_data(basename, provenance_record, cfg, theta_x) - return theta_x + return theta_x, t_file + + +def calculate_lts(var, input_data, cfg): + # This function calculates the potential temperature for one level. + + theta_700, file_1 = calculate_theta('theta700', input_data, cfg) + + theta_1000, file_2 = calculate_theta('theta1000', input_data, cfg) + + lts = theta_700 - theta_1000 + + lts.long_name = 'lower tropospheric stability' + + # Write output + logger.info("Saving data.") + basename = var + caption = 'lower_tropospheric_stability' + provenance_record = get_provenance_record( + caption, ancestor_files=[file_1, file_2]) + save_data(basename, provenance_record, cfg, lts) + + return lts def main(cfg): @@ -145,7 +167,7 @@ def main(cfg): # "the recipe:\n%s", pformat(grouped_input_data)) ## Example of how to loop over variables/datasets in alphabetical order - #groups = group_metadata(input_data, 'variable_group', sort='dataset') + groups = group_metadata(input_data, 'variable_group', sort='dataset') #for group_name in groups: # logger.info("Processing variable %s", group_name) # for attributes in groups[group_name]: @@ -166,10 +188,18 @@ def main(cfg): if cfg.get('compute'): for var in cfg['compute']: print(var) - if var not in ['theta700', 'theta850']: + if var not in ['LTS', 'theta700', 'theta850']: logger.error('Computation of %s is not available...', var) if 'theta' in var: - theta = calculate_theta(var, input_data, cfg) + theta, file_theta = calculate_theta(var, input_data, cfg) + if var == 'LTS': + print('groups') + print(groups) + for ivar in ['ta700', 'ta1000']: + if ivar not in groups: + logger.error('Variable %s is needed to calculate LTS but is not available', ivar) + lts = calculate_lts(var, input_data, cfg) + #lts = calculate_lts(var, groups, cfg) diff --git a/esmvaltool/recipes/recipe_preprocess_cloud.yml b/esmvaltool/recipes/recipe_preprocess_cloud.yml index e255809bd6..426f37ad8e 100644 --- a/esmvaltool/recipes/recipe_preprocess_cloud.yml +++ b/esmvaltool/recipes/recipe_preprocess_cloud.yml @@ -18,10 +18,16 @@ documentation: - cmug +years: &years + #start_year: 2000 + #end_year: 2004 + timerange: 200001/200412 + + ESACCI_CLOUD_datasets: &esacci - - {dataset: ESACCI-CLOUD, project: OBS6, type: sat, version: v3.0, tier: 2, start_year: 2000, end_year: 2004} + - {dataset: ESACCI-CLOUD, project: OBS6, type: sat, version: v3.0, tier: 2} ERA5_datasets: &era5 - - {dataset: ERA5, project: OBS6, type: reanaly, version: v1, tier: 3, start_year: 2000, end_year: 2004} + - {dataset: ERA5, project: OBS6, type: reanaly, version: v1, tier: 3} #- {dataset: ESACCI-CLOUD, project: OBS6, type: sat, version: v3.0, tier: 2, timerange: 200001/200008} @@ -39,13 +45,13 @@ preprocessors: end_longitude: 285. mask_landsea: &mask_land mask_out: land - anomalies: - period: daily + #anomalies: + # period: daily area_statistics: &area_mean operator: mean #regrid: # scheme: area_weighted - # target_grid: 1x1 + # target_grid: 5x5 diagnostics: @@ -53,59 +59,62 @@ diagnostics: south_east_pacific_clouds: description: Create timeseries. variables: - #clt: &var - # preprocessor: south_east_pacific - # mip: day - # frequency: day - # additional_datasets: *esacci - #clwvi: - # <<: *var - # mip: CFday - #cod: - # <<: *var - # mip: AERday - #ctp: - # <<: *var - # mip: day - #reff: - # <<: *var - # mip: day - #rlut: - # <<: *var - # mip: day - #psl: &var2 - # preprocessor: south_east_pacific - # frequency: day - # mip: day - # additional_datasets: *era5 + clt: &var + preprocessor: south_east_pacific + mip: day + frequency: day + additional_datasets: *esacci + clwvi: + <<: *var + mip: CFday + cod: + <<: *var + mip: AERday + ctp: + <<: *var + mip: day + reff: + <<: *var + mip: day + #rlut: + # <<: *var + # mip: day + psl: &var2 + preprocessor: south_east_pacific + frequency: day + mip: day + additional_datasets: *era5 ta700: preprocessor: south_east_pacific frequency: day mip: CFday + <<: *years additional_datasets: *era5 - ta850: + ta1000: preprocessor: south_east_pacific frequency: day - mip: Eday + mip: day + <<: *years additional_datasets: *era5 - #tos: - # <<: *var2 - # mip: day - #wap500: - # <<: *var2 - # mip: CFday + tos: + <<: *var2 + mip: day + wap700: + <<: *var2 + mip: day #zg500: # <<: *var2 # mip: day - #prw: - # <<: *var2 - # mip: Eday + prw: + <<: *var2 + mip: Eday scripts: timeseries: script: causal_clouds_timeseries.py compute: - - theta700 - - theta850 + #- theta700 + #- theta850 + - LTS diff --git a/esmvaltool/recipes/recipe_preprocess_era5.yml b/esmvaltool/recipes/recipe_preprocess_era5.yml index 4b11fd2d2d..1e7adaeb0f 100644 --- a/esmvaltool/recipes/recipe_preprocess_era5.yml +++ b/esmvaltool/recipes/recipe_preprocess_era5.yml @@ -30,7 +30,7 @@ datasets: preprocessors: add_one_day: &add_one_day extract_time: - start_year: 2000 + start_year: 2004 start_month: 1 start_day: 1 end_year: 2005 @@ -68,16 +68,21 @@ diagnostics: # era5_name: mean_sea_level_pressure # era5_freq: hourly # preprocessor: daily_mean - ta700: - mip: E1hr - era5_name: temperature - era5_freq: hourly - preprocessor: daily_mean - ta850: - mip: E1hr - era5_name: temperature - era5_freq: hourly - preprocessor: daily_mean + #ta700: + # mip: E1hr + # era5_name: temperature + # era5_freq: hourly + # preprocessor: daily_mean + #ta850: + # mip: E1hr + # era5_name: temperature + # era5_freq: hourly + # preprocessor: daily_mean + #ta1000: + # mip: E1hr + # era5_name: temperature + # era5_freq: hourly + # preprocessor: daily_mean #tos: # mip: E1hr # era5_name: sea_surface_temperature @@ -88,6 +93,11 @@ diagnostics: # era5_name: vertical_velocity # era5_freq: hourly # preprocessor: daily_mean + wap700: + mip: E1hr + era5_name: vertical_velocity + era5_freq: hourly + preprocessor: daily_mean #zg500: # mip: E1hr # era5_name: geopotential