-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data_pl_short_length.py
98 lines (73 loc) · 3.65 KB
/
get_data_pl_short_length.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import cdsapi
from datetime import datetime, timedelta
import cdstoolbox as ct
import logging, sys, os
import yaml
with open('/scratch/gilbreth/gupt1075/FourCastNet_gil/.cdsapirc', 'r') as f:
credentials = yaml.safe_load(f)
c = cdsapi.Client(url=credentials['url'], key=credentials['key'])
start_time = datetime(2020, 1, 1, 0, 0, 0)
end_time = datetime(2021, 1, 1, 0, 0, 0)
# timedelta = timedelta(hours=6)
@ct.application(title='Retrieve Data')
@ct.output.download()
def retrieve_sample_data():
"""
Application main steps:
- retrieve a variable from CDS Catalogue
- produce a link to download it.
"""
data = ct.catalogue.retrieve(
'reanalysis-era5-single-levels',
{
'variable': '2m_temperature',
'product_type': 'reanalysis',
'year': '2017',
'month': '01',
'day': '02',
'time': '12:00',
}
)
return data
c.retrieve(
'reanalysis-era5-pressure-levels',
{
'date' : f"{start_time.strftime('%Y-%m-%d')}/to/{end_time.strftime('%Y-%m-%d')}",
'pressure_level': [ '50', '500', '850','1000',],
'product_type': 'reanalysis',
'variable': [
'geopotential', 'relative_humidity', 'temperature',
'u_component_of_wind', 'v_component_of_wind',
],
'time': [ '00:00', '06:00', '12:00','18:00',],
'area' : 'global',
'format': 'netcdf',
},
'/scratch/gilbreth/gupt1075/copernicus_data/2020_pl.nc')
c.retrieve('reanalysis-era5-complete', {
# Removed obsolete comments and streamlined the explanation
'date' : f"{start_time.strftime('%Y-%m-%d')}/to/{end_time.strftime('%Y-%m-%d')}", # Specify the range of dates to download
'levelist': '500', # pressure Levels
'levtype' : 'pl', # Model levels
'param' : '137', # Parameter code for geopotential
'stream' : 'oper', # Operational data stream
'time' : '00/06/12/18', # Times of day (in shorthand notation)
'type' : 'an', # Analysis type
'area' : 'global', # Geographical subarea: North/West/South/East
'grid' : '0.25/0.25', # Grid resolution: latitude/longitude
'format' : 'netcdf', # Output format, requires 'grid' to be specified
}, f"{output_path}" + f"tcwv_{start_time.strftime('%Y-%m-%d')}_to_{end_time.strftime('%Y-%m-%d')}_" + "ERA5-pl-z500.25.nc") # Output filename
# c.retrieve('reanalysis-era5-complete', {
# # Removed obsolete comments and streamlined the explanation
# 'date' : f"{start_time.strftime('%Y-%m-%d')}/to/{end_time.strftime('%Y-%m-%d')}", # Specify the range of dates to download
# 'levelist': '500', # pressure Levels
# 'levtype' : 'pl', # Model levels
# 'param' : '129', # Parameter code for geopotential
# 'stream' : 'oper', # Operational data stream
# 'time' : '00/06/12/18', # Times of day (in shorthand notation)
# 'type' : 'an', # Analysis type
# 'area' : 'global', # Geographical subarea: North/West/South/East
# 'grid' : '0.25/0.25', # Grid resolution: latitude/longitude
# 'format' : 'netcdf', # Output format, requires 'grid' to be specified
# }, f"{output_path}" + f"NETCDF_{start_time.strftime('%Y-%m-%d')}_to_{end_time.strftime('%Y-%m-%d')}_" + "ERA5-pl-z500.25.nc") # Output filename