Skip to content

Commit

Permalink
add LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
LisaBock committed Dec 6, 2023
1 parent d4c1b45 commit a98778b
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 65 deletions.
52 changes: 41 additions & 11 deletions esmvaltool/diag_scripts/causal_clouds_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -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]:
Expand All @@ -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)



Expand Down
95 changes: 52 additions & 43 deletions esmvaltool/recipes/recipe_preprocess_cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}


Expand All @@ -39,73 +45,76 @@ 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:

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



Expand Down
32 changes: 21 additions & 11 deletions esmvaltool/recipes/recipe_preprocess_era5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a98778b

Please sign in to comment.