66
77"""
88
9+ import multiprocessing as mp
910import os
11+ import subprocess
1012from glob import glob
13+ from pathlib import Path
1114
1215import xarray as xr
1316import zarr
1821 EU_VAR2D_LIST ,
1922 EU_VAR3D_LIST ,
2023)
21- import subprocess
2224
23- from pathlib import Path
24- import multiprocessing as mp
2525
2626def decompress (full_bzip_filename : Path , temp_pth : Path ) -> str :
2727 """
@@ -38,7 +38,7 @@ def decompress(full_bzip_filename: Path, temp_pth: Path) -> str:
3838 base_nat_filename = os .path .splitext (base_bzip_filename )[0 ]
3939 full_nat_filename = os .path .join (temp_pth , base_nat_filename )
4040 if os .path .exists (full_nat_filename ):
41- return full_nat_filename # Don't decompress a second time
41+ return full_nat_filename # Don't decompress a second time
4242 with open (full_nat_filename , "wb" ) as nat_file_handler :
4343 process = subprocess .run (
4444 ["pbzip2" , "--decompress" , "--keep" , "--stdout" , full_bzip_filename ],
@@ -179,8 +179,8 @@ def upload_to_hf(dataset_xr, folder, model="eu", run="00", token=None):
179179 encoding = {var : {"compressor" : Blosc2 ("zstd" , clevel = 9 )} for var in dataset_xr .data_vars }
180180 encoding ["time" ] = {"units" : "nanoseconds since 1970-01-01" }
181181 with zarr .ZipStore (
182- zarr_path ,
183- mode = "w" ,
182+ zarr_path ,
183+ mode = "w" ,
184184 ) as store :
185185 dataset_xr .chunk (chunking ).to_zarr (store , encoding = encoding , compute = True )
186186 done = False
@@ -189,10 +189,10 @@ def upload_to_hf(dataset_xr, folder, model="eu", run="00", token=None):
189189 api .upload_file (
190190 path_or_fileobj = zarr_path ,
191191 path_in_repo = f"data/{ dataset_xr .time .dt .year .values } /"
192- f"{ dataset_xr .time .dt .month .values } /"
193- f"{ dataset_xr .time .dt .day .values } /"
194- f"{ dataset_xr .time .dt .year .values } { str (dataset_xr .time .dt .month .values ).zfill (2 )} { str (dataset_xr .time .dt .day .values ).zfill (2 )} "
195- f"_{ str (dataset_xr .time .dt .hour .values ).zfill (2 )} .zarr.zip" ,
192+ f"{ dataset_xr .time .dt .month .values } /"
193+ f"{ dataset_xr .time .dt .day .values } /"
194+ f"{ dataset_xr .time .dt .year .values } { str (dataset_xr .time .dt .month .values ).zfill (2 )} { str (dataset_xr .time .dt .day .values ).zfill (2 )} "
195+ f"_{ str (dataset_xr .time .dt .hour .values ).zfill (2 )} .zarr.zip" ,
196196 repo_id = "openclimatefix/dwd-icon-global"
197197 if model == "global"
198198 else "openclimatefix/dwd-icon-eu" ,
0 commit comments