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
| import matplotlib | |
| # Generate a list of colors | |
| cmap = matplotlib.cm.get_cmap('Spectral') | |
| # Retrieve 19 colors from the colormap | |
| colors = cmap(np.arange(19)/19) |
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
| # Print a progress bar for a loop completion | |
| from time import sleep | |
| F = range(10) | |
| num = len(F) | |
| for i in F: | |
| sleep(1) | |
| sys.stdout.write('\r%.1f%% Complete (%s of %s)' % (i/num*100, i, num)) |
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
| masked = H['value'] | |
| masked = np.ma.array(masked) | |
| masked[masked == -10] = np.ma.masked |
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
| from datetime import datetime | |
| import numpy as np | |
| def to_datetime(date): | |
| """ | |
| Converts a numpy datetime64 object to a python datetime object | |
| Input: | |
| date - a np.datetime64 object | |
| Output: | |
| DATE - a python datetime object |
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
| # Download single variable from single day | |
| DATE = date(2017, 3, 10) # Model run date | |
| variable = 'HGT:500 mb' # Must be part of a line in the .idx file | |
| download_HRRR_variable_from_pando(DATE, variable, | |
| hours=range(0, 24), fxx=[0], | |
| model='hrrr', field='sfc', | |
| more_vars=4, | |
| outdir='./') |
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() |
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
| # === User change these parameters ================================ | |
| # date range | |
| sDATE = date(2017, 3, 10) # Start date | |
| eDATE = date(2017, 3, 13) # End date (exclusive) | |
| # list of variables | |
| variables = ['TMP:2 m', 'DPT:2 m', 'UGRD:10 m', 'VGRD:10 m'] | |
| # ================================================================= | |
| days = (eDATE-sDATE).days | |
| DATES = [sDATE + timedelta(days=d) for d in range(days)] |
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
| # === User change these parameters ============================ | |
| # date range | |
| sDATE = date(2017, 3, 10) # Start date | |
| eDATE = date(2017, 3, 13) # End date (exclusive) | |
| # variable string | |
| variable = 'TMP:2 m' # Must be part of a line in the .idx file | |
| # ============================================================= | |
| days = (eDATE-sDATE).days | |
| DATES = [sDATE + timedelta(days=d) for d in range(days)] |
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
| # Download single variable from single day | |
| DATE = date(2017, 3, 10) # Model run date | |
| variable = 'TMP:2 m' # Must be part of a line in the .idx file | |
| download_HRRR_variable_from_pando(DATE, variable, | |
| hours=range(0, 24), fxx=[0], | |
| model='hrrr', field='sfc', | |
| outdir='./') |
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
| ######################################### | |
| # ✨ Use the new Herbie Package instead: | |
| # https://github.com/blaylockbk/Herbie | |
| ######################################### | |
| # Brian Blaylock | |
| # February 13, 2018 | |
| # Updated December 10, 2018 for Python 3 (Thanks J.Matt for sharing) |