Last active
November 1, 2017 20:27
-
-
Save blaylockbk/4632bfec251a85dc10dd76826af4c662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fast download of HRRR grib2 files (single variable) with multithreading | |
# import some additional modules | |
from queue import Queue | |
from threading import Thread | |
def worker(): | |
# This is where the main download function is run. | |
# Change the hour and fxx parameters here if needed. | |
while True: | |
item = q.get() | |
# Unpack the date and variable from the item sent to this worker | |
iDATE, ivar = item | |
download_HRRR_variable_from_pando(iDATE, ivar, | |
hours=range(0, 24), fxx=[0], | |
model='hrrr', field='sfc', | |
outdir='./') | |
q.task_done() | |
# ===== User Modify the Variables and date range ========================== | |
variables = ['TMP:2 m', 'DPT:2 m'] # List of variable strings | |
sDATE = date(2017, 3, 10) # Start date | |
eDATE = date(2017, 3, 13) # End date (exclusive) | |
# ========================================================================= | |
# Create list of dates to request | |
days = (eDATE-sDATE).days | |
DATES = [sDATE + timedelta(days=d) for d in range(days)] | |
# Make a list of inputs to send to the worker | |
input_list = [[d, v] for d in DATES for v in variables] | |
# Multithreadding using the worker | |
num_of_threads = 8 | |
q = Queue() | |
for i in range(num_of_threads): | |
t = Thread(target=worker) | |
t.daemon = True | |
t.start() | |
# Run each item through the threads | |
for item in input_list: | |
q.put(item) | |
q.join() # block until all tasks are done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment