aboutsummaryrefslogtreecommitdiff
path: root/aggregator/dwd_icon.py
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-11-22 17:28:47 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-11-22 17:28:47 +0100
commit293b33715c3656fc54bab70ec49c04912655444f (patch)
treefabe2edfe3c4a0a778104e0631b3234583913a7e /aggregator/dwd_icon.py
parentd37ab408c9449c9602467cea2690cd21728e1e91 (diff)
downloadmeteo_toolbox-293b33715c3656fc54bab70ec49c04912655444f.tar.gz
dwd_icon: allow for clearing of old data
Diffstat (limited to 'aggregator/dwd_icon.py')
-rwxr-xr-xaggregator/dwd_icon.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/aggregator/dwd_icon.py b/aggregator/dwd_icon.py
index 2bd3a61..88288f3 100755
--- a/aggregator/dwd_icon.py
+++ b/aggregator/dwd_icon.py
@@ -89,15 +89,27 @@ def download_dwd_gribs(
if res.returncode != 0:
print('rm failed with: ', res.stderr)
-def load_data(name, output, description = None, **kwargs):
+def clean_output_dir(directory, target):
+ to_delete = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
+ if target in to_delete:
+ del to_delete[to_delete.index(target)]
+
+ for f in to_delete:
+ os.unlink(os.path.join(directory, f))
+
+def load_data(name, output, description = None, clean = False, **kwargs):
run, date = get_current_run()
- target = os.path.join(output, f'{name}_{date}_{run}.grib2')
+ filename = f'{name}_{date}_{run}.grib2'
+ target = os.path.join(output, filename)
if not os.path.exists(target):
download_dwd_gribs(date, run, target, output, **kwargs)
else:
print(f'{target} alreasy exists. Using the cached version.')
+ if clean:
+ clean_output_dir(output, filename)
+
ds = xr.load_dataset(target, engine='cfgrib')
if description is not None:
ds.attrs['_description'] = description
@@ -108,6 +120,7 @@ debug_config = {
'output':'dwd_icon-eu',
'model':'icon-eu',
'model_long':'icon-eu_europe',
+ 'clean': True,
'parameter_caps_in_filename':True,
'pressure_level_parameters': [
't',