Skip to content

Instantly share code, notes, and snippets.

@blaylockbk
blaylockbk / simple_basemap_example.py
Created January 5, 2017 18:52
A quick demonstration of creating a basemap and plotting or drawing objects
# Brian Blaylock
# January 5, 2017 It's snowing outside
"""
Simple Basemap examples
Example gallery: http://matplotlib.org/basemap/users/examples.html
Documentation: https://basemaptutorial.readthedocs.io/en/latest/
"""
@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 / netcdf_basics.py
Last active December 3, 2021 08:43
Basics of opening NetCDF files with Python
#from netCDF4 import Dataset # use scipy instead
from scipy.io import netcdf #### <--- This is the library to import.
# Open file in a netCDF reader
directory = './'
wrf_file_name = directory+'filename'
nc = netcdf.netcdf_file(wrf_file_name,'r')
#Look at the variables available
@blaylockbk
blaylockbk / mkdir_if_none.py
Last active September 20, 2018 21:18
make a directory if it doesn't exist, like a save dir, with os.path
import os
DIR = '/this/is/the/directory/name/'
if not os.path.exists(DIR):
os.makedirs(DIR)
@blaylockbk
blaylockbk / range_of_datetimes.py
Last active February 8, 2018 21:52
Range of Datetimes
from datetime import datetime, timedelta
# create a list of dates from a starting date for a certian number of hours
base = datetime(2017, 5, 10)
hours = 36
DATES = np.array([base + timedelta(hours=x) for x in range(0, hours)])
# create a list of datetimes between two dates for each hour
sDATE = datetime(2017, 5, 10)
eDATE = datetime(2017, 5, 12)
@blaylockbk
blaylockbk / special_string_labels.py
Last active March 9, 2021 18:31
Special String Formating and Characters
# Greek Letters
plt.title(r'$\theta$')
plt.title(r'$\alpha$')
plt.title(r'$\Delta$')
# Superscript (wind speed m/s)
plt.ylabel(r'Wind Speed (m s$\mathregular{^{-1}}$)')
# Subscript (CO_2, theta_surface)
plt.ylabel(r'CO$_2$ (ppm)')
@blaylockbk
blaylockbk / legends.py
Last active April 12, 2018 16:12
Python Legends
# More here: http://matplotlib.org/api/legend_api.html
# No boarder, transparent frame
legend = ax1.legend(frameon=True, framealpha=.5)
legend.get_frame().set_linewidth(0)
# Limit scatterpoints in legend
plt.legend(scatterpoints=1)
@blaylockbk
blaylockbk / download_HRRR_full_grib2.py
Last active December 10, 2018 17:01
Download a range of files from the MesoWest Pando HRRR archive
# Brian Blaylock
# February 13, 2018
# Updated December 10, 2018 for Python 3
"""
Download archived HRRR files from MesoWest Pando S3 archive system.
Please register before downloading from our HRRR archive:
http://hrrr.chpc.utah.edu/hrrr_download_register.html
@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
@blaylockbk
blaylockbk / HRRR_S3.py
Last active November 28, 2018 03:00
Get data from the Mesowest HRRR S3 Archive
# Brian Blaylock
# March 14, 2017 It's Pi Day!! (3.14)
"""
Get data from a HRRR grib2 file on the MesoWest HRRR S3 Archive
Requires cURL on your linux system
"""
import os