Skip to content

Commit

Permalink
fixed #71
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Apr 27, 2022
1 parent 4cbd739 commit de70cb7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion herbie/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def get_localFilePath(self, searchString=None):
hash_label = hashlib.sha1(all_grib_msg.encode()).hexdigest()

# Append the filename to distinguish it from the full file.
outFile = outFile.with_suffix(f".grib2.subset_{hash_label}")
outFile = outFile.parent / f"subset_{hash_label}__{outFile.name}"

return outFile

Expand Down
22 changes: 18 additions & 4 deletions herbie/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ def fast_Herbie(DATES, fxx=[0], *, max_threads=50, **kwargs):


def fast_Herbie_download(
DATES, *, searchString=None, fxx=[0], max_threads=20, **kwargs
DATES,
*,
searchString=None,
fxx=[0],
max_threads=20,
download_kw={},
**kwargs,
):
"""
Use multithreading to download many Herbie objects
Expand Down Expand Up @@ -155,7 +161,7 @@ def fast_Herbie_download(
log.info(f"🧵 Working on {tasks} tasks with {threads} threads.")

with ThreadPoolExecutor(max_threads) as exe:
futures = [exe.submit(H.download, searchString) for H in passed]
futures = [exe.submit(H.download, searchString, **download_kw) for H in passed]

# Return list of Herbie objects in order completed
_ = [future.result() for future in as_completed(futures)]
Expand All @@ -168,7 +174,15 @@ def fast_Herbie_download(
return dict(passed=passed, failed=failed)


def fast_Herbie_xarray(DATES, *, searchString=None, fxx=[0], max_threads=5, **kwargs):
def fast_Herbie_xarray(
DATES,
*,
searchString=None,
fxx=[0],
max_threads=5,
xarray_kw={},
**kwargs,
):
"""
Use multithreading to download many Herbie objects
Expand Down Expand Up @@ -204,7 +218,7 @@ def fast_Herbie_xarray(DATES, *, searchString=None, fxx=[0], max_threads=5, **kw
log.info(f"🧵 Working on {tasks} tasks with {threads} threads.")

with ThreadPoolExecutor(max_threads) as exe:
futures = [exe.submit(H.xarray, searchString) for H in passed]
futures = [exe.submit(H.xarray, searchString, **xarray_kw) for H in passed]

# Return list of Herbie objects in order completed
ds_list = [future.result() for future in as_completed(futures)]
Expand Down

1 comment on commit de70cb7

@blaylockbk
Copy link
Owner Author

@blaylockbk blaylockbk commented on de70cb7 Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the naming convention for the subset files. The previous method caused problem like #71 when the GRIB filename didn't have a suffix like .grib2!

Old subset filename

  • <filename>.subset_<hashlabel>
  • gfs.t00z.pgrb2.0p25.grib2.subset_446869af0dd2e2b03740017fe2cb9b9c5be27d91

New subset filename

  • subset_<hashlabel>__<filename>
  • subset_f2fb0f4a1156e83d8bfed6997737af210e4bc2eb__gfs.t00z.pgrb2.0p25.f000

The added benefit of this, too, is that the files will be sorted by subset type rather than file 😃

Please sign in to comment.