Skip to content

Instantly share code, notes, and snippets.

from datetime import datetime, timedelta
base = datetime.today()
numdays = 5
date_list = [base - timedelta(days=x) for x in range(0,numdays)]
DATES = np.array([])
for i in dates:
DATES = np.append(DATES,datetime.strptime(i,'%m/%d/%Y %H%M'))
@blaylockbk
blaylockbk / date strings list to python datetime objects
Created November 1, 2016 16:30
this method uses numpy vectorized function, which is slightly faster than using a list generator
import numpy as np
import datetime
def datestr_to_datetime(x):
return datetime.datetime.strptime(x,'%Y-%m-%dT%H:%M:%SZ')
# where dates is some list of dates as a string...
# vectorize the function
converttime = np.vectorize(datestr_to_datetime)
DATES = converttime(dates)
@blaylockbk
blaylockbk / list of Epoch times to python datetimes
Last active November 3, 2016 21:49
Takes a list of Epoch times and converts it to a list of python datetime objects
# where dates is a list or numpy array of epoch dates...
DATE = [datetime.utcfromtimestamp(x) for x in dates]
@blaylockbk
blaylockbk / untar HRRR
Created November 10, 2016 15:30
untar select HRRR files from the compressed MesoWest archive
# To untar just about everything
tar -xzvf models.tar.gz 20160101/models/hrrr/
# To untar just the HRRR pressure fields for analysis hours
tar -zxvf models.tar.gz --wildcards --no-anchored 'hrrr.t*z.wrfprsf00.grib2'
$ to untar just the HRRR surface fields for analysis hours
tar -zxvf models.tar.gz --wildcards --no-anchored 'hrrr.t*z.wrfsfcf00.grib2'
@blaylockbk
blaylockbk / verify_GFS_pygrib.py
Last active November 11, 2016 22:35
Verify GFS dewpoint with MesoWest observation for class assignment
# Brian Blaylock
# ATMOS 6910 Homework
# 10 November 2016
# Look at the figures here:
# http://kbkb-wx-python.blogspot.com/2016/11/verifying-gfs-dewpoint-data-with.html
"""
[X] Reads a GRiB forecast file from the GFS (15%)
[X] Extracts Temperature and Relative Humidity from ingest (5%)
@blaylockbk
blaylockbk / create_dir.py
Created November 29, 2016 16:08
Create directory if it doesn't exits
import os
OUTDIR = '/this/path/will/be/created/'
if not os.path.exists(OUTDIR):
os.makedirs(OUTDIR)
@blaylockbk
blaylockbk / netcdf_basics.py
Created January 19, 2017 21:54
Basics: NetCDF with Python
import sys,getopt
#from netCDF4 import Dataset # use scipy instead
from scipy.io import netcdf #### <--- This is the library to import.
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import os
from datetime import datetime, timedelta
import coltbls as coltbls
from mpl_toolkits.basemap import Basemap
@blaylockbk
blaylockbk / HRRR_S3_fastDwnld.py
Last active March 24, 2017 18:15
Fast download of grib2 files from HRRR S3
# Brian Blaylock
# March 24, 2017 Yesterday Salt Lake had lots of rain
"""
Fast download of HRRR grib2 files with threading
"""
from queue import Queue
from threading import Thread
from datetime import datetime, timedelta
@blaylockbk
blaylockbk / download_HRRR_variable_with_curl.py
Last active July 26, 2017 17:06
Download a single HRRR variable with cURL
# Brian Blaylock
# March 10, 2017
# updated: July 26, 2017
"""
Download a single variable from the HRRR archive using cURL
Steps:
1) Read the lines from the Metadata .idx file
2) Identify the byte range for the variable of interest