Commit bc9d5935 authored by Clément Haëck's avatar Clément Haëck
Browse files

Add HF average over grid and data

add download ERA5 script
parent 8b07db06
"""Compute heat fluxes timeseries over grid boxes."""
import lib
import lib.box
import lib.data.heat_fluxes
import lib.data.HF_TS
def main():
args = lib.get_args(['region', 'grid_file', 'days', 'fixes', 'year'])
grid_file = lib.box.IndexBox.GetGridFile(args)
boxes = lib.box.IndexBox.ReadGridText(grid_file)
args['fixes']['Y'] = args['year']
ds = lib.data.heat_fluxes.get_data(args)
for box in lib.progressbar(boxes):
args['fixes']['idx'] = box.idx
ofile = lib.data.HF_TS.get_filename(args['fixes'])
lib.check_output_dir(ofile, file=True)
dst = box.extract(ds)
dst = dst.hf.mean(['lat', 'lon'])
dst.to_netcdf(ofile)
if __name__ == '__main__':
main()
"""Download land mask for ERA5 GLOBAL_025 grid.
First to download the land/sea fraction the code below can be used in the
Copernicus Climate Data Store toolbox at
<https://cds.climate.copernicus.eu/toolbox-editor>.
Place the file in
`${SUBMESO_COLOR_DATA_DIR}/{region}/zones/ERA5_land_area_fraction.nc`.
Then /Compute/make_land.py can be run.
"""
import cdstoolbox as ct
@ct.application(title='Download data')
@ct.output.download()
def download_application():
data = ct.catalogue.retrieve(
'reanalysis-era5-single-levels',
{
'product_type': 'reanalysis',
'variable': 'land_sea_mask',
'year': '2000',
'month': '01',
'day': '01',
'time': '00:00',
'area': [
60, -85, 0, 0, # Same as /Download/integrate_daily_sf.sh
],
}
)
return data
"""Time series of heat fluxes in grided boxes."""
from os import path
import lib
import lib.data
ARGS_DIR = {'region', 'days'}
pregex = '%(idx:fmt=04d)/HF_TS_%(Y).nc'
def get_root(args=None, **kwargs):
args = lib.data.process_args(ARGS_DIR, args, **kwargs)
root = path.join(lib.root_data, args['region'], 'HF_TS',
lib.data.get_time_folder(args))
return root
def add_idx_dim(ds, filename, finder):
idx = finder.get_matches(filename)['idx'].match_str
ds = ds.expand_dims({'idx': [idx]})
return ds
lib.data.create_data(__name__, pregex, get_root, ARGS_DIR,
open_mf_kw=dict(preprocess_finder=add_idx_dim))
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