Skip to content

Commit 7c5f801

Browse files
download script works with hydra config and snakemake sbatch
1 parent 79f0399 commit 7c5f801

File tree

12 files changed

+37
-19
lines changed

12 files changed

+37
-19
lines changed
File renamed without changes.
File renamed without changes.

conf/config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ development_mode: false
77
CDS_API_KEY:
88
path: "$HOME/.cdsapirc"
99

10+
gadm_file: "https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg/gadm41_MDG.gpkg"
11+
1012
query:
1113
product_type: reanalysis
12-
gadm_file: "https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg/gadm41_MDG.gpkg"
1314
# check precipitation
1415
# variable: ["2m_dewpoint_temperature", "2m_temperature", "skin_temperature", "total_precipitation"]
1516
variable: ["2m_dewpoint_temperature", "2m_temperature"]
16-
year: [2010, 2011]
17+
year: [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024]
1718
month: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
1819
day: [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]
1920
time: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

notes/01_download_raw_data.ipynb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
"import hydra\n",
4848
"import cdsapi\n",
4949
"import geopandas as gpd\n",
50-
"from core import _expand_path\n",
5150
"from pyprojroot import here\n",
52-
"from omegaconf import DictConfig, ListConfig, OmegaConf"
51+
"from omegaconf import DictConfig, ListConfig, OmegaConf\n",
52+
"\n",
53+
"try: from era5_sandbox.core import _expand_path\n",
54+
"except: from core import _expand_path"
5355
]
5456
},
5557
{
@@ -144,7 +146,8 @@
144146
" bbox[2] = round(bbox[2], round_to) + buffer\n",
145147
" bbox[3] = round(bbox[3], round_to) + buffer\n",
146148
" \n",
147-
" bbox = [bbox[0], bbox[2], bbox[1], bbox[3]]\n",
149+
" # The bounding box from total_bounds ([min_x, min_y, max_x, max_y]) differs from the CDS API area format ([North, West, South, East]). The CDS API area format is used to specify the area of interest for the data download. The bounding box from total_bounds is in the format ([min_x, min_y, max_x, max_y]). To convert the bounding box to the CDS API area format, we need to rearrange the values as follows:\n",
150+
" bbox = [bbox[3], bbox[0], bbox[1], bbox[2]]\n",
148151
"\n",
149152
" return bbox\n"
150153
]
@@ -168,16 +171,17 @@
168171
" testing = cfg.development_mode # for testing\n",
169172
" output_dir = here(\"data/input\") # output directory\n",
170173
" \n",
174+
" target =os.path.join(_expand_path(output_dir), \"{}_{}.nc\".format(cfg.query['year'], cfg.query['month']))\n",
175+
" \n",
171176
" client = cdsapi.Client()\n",
172177
" \n",
173178
" query = _validate_query(cfg.query)\n",
174179
" \n",
175180
" # Send the query to the client\n",
176181
" if not testing:\n",
177-
" bounds = create_bounding_box(cfg.query['gadm_file'])\n",
182+
" bounds = create_bounding_box(cfg['gadm_file'])\n",
178183
" query['area'] = bounds\n",
179-
" del query['gadm_file']\n",
180-
" client.retrieve(dataset, query).download(os.path.join(_expand_path(output_dir), \"{}_{}.nc\".format(query['year'], query['month'])))\n",
184+
" client.retrieve(dataset, query).download(target)\n",
181185
" else:\n",
182186
" print(f\"Testing mode. Not downloading data. Query is {query}\")\n",
183187
"\n",
@@ -237,7 +241,7 @@
237241
"\n",
238242
"if __name__ == \"__main__\" and not IN_NOTEBOOK:\n",
239243
" print('Running from __main__ ...')\n",
240-
"\n",
244+
" \n",
241245
" main()"
242246
]
243247
},

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,3 @@
6161
'nbdev': [f'{cfg.get("lib_name")}={cfg.get("lib_name")}._modidx:d']
6262
},
6363
**setup_cfg)
64-
65-

snakemake.sbatch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#SBATCH -p test # partition (queue)
44
#SBATCH -c 12 # number of cores
55
#SBATCH --mem 90GB # memory
6-
#SBATCH -t 0-02:00 # time (D-HH:MM)
6+
#SBATCH -t 0-10:00 # time (D-HH:MM)
77

88
snakemake --cores 6

src/era5_sandbox.egg-info/PKG-INFO

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Metadata-Version: 2.2
1+
Metadata-Version: 2.4
22
Name: era5_sandbox
33
Version: 0.0.1
44
Summary: Sandbox environment for era5 development
@@ -27,6 +27,11 @@ Requires-Dist: nbdev
2727
Requires-Dist: cdsapi
2828
Requires-Dist: hydra-core
2929
Requires-Dist: ipykernel
30+
Requires-Dist: snakemake
31+
Requires-Dist: geopandas
32+
Requires-Dist: xarray
33+
Requires-Dist: matplotlib
34+
Requires-Dist: cartopy
3035
Provides-Extra: dev
3136
Dynamic: author
3237
Dynamic: author-email
@@ -36,6 +41,7 @@ Dynamic: description-content-type
3641
Dynamic: home-page
3742
Dynamic: keywords
3843
Dynamic: license
44+
Dynamic: license-file
3945
Dynamic: provides-extra
4046
Dynamic: requires-dist
4147
Dynamic: requires-python

src/era5_sandbox.egg-info/requires.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ nbdev
55
cdsapi
66
hydra-core
77
ipykernel
8+
snakemake
9+
geopandas
10+
xarray
11+
matplotlib
12+
cartopy
813

914
[dev]
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)