This file contains 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 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 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 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 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 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 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 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) |
This file contains 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.pyplot as plt | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |
data1 = np.random.random([5,5]) | |
data2 = np.random.random([5,5]) | |
fig = plt.figure(1, figsize=[16, 4]) | |
ax1 = fig.add_subplot(121) | |
ax2 = fig.add_subplot(122) | |
this_plot = ax1.pcolormesh(data1, cmap='magma') |
This file contains 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
# Method 1: when you are using plt | |
from matplotlib.dates import DateFormatter | |
formatter = DateFormatter('%Y-%m-%d %H:%M:%S') | |
plt.gcf().axes[0].xaxis.set_major_formatter(formatter) | |
# Method 2: when you have already axessed the axes | |
from matplotlib.dates import DateFormatter | |
formatter = DateFormatter('%Y-%m-%d %H:%M:%S') | |
ax1.xaxis.set_major_formatter(formatter) |