Skip to content

Instantly share code, notes, and snippets.

@blaylockbk
blaylockbk / standard_atmosphere.py
Last active January 12, 2026 21:11
U.S. Standard Atmosphere (1976)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
from matplotlib.patches import Rectangle
# Replicate Figure 1.9 (page 10) in Wallace and Hobbs 2nd Edition
# Standard atmosphere data (U.S. Standard Atmosphere 1976)
# https://en.wikipedia.org/wiki/U.S._Standard_Atmosphere
LEVELS_M = np.array([0, 11000, 20000, 32000, 47000, 51000, 71000, 84852, 90000, 120000])
@blaylockbk
blaylockbk / download_vscode_server.sh
Created October 15, 2025 19:22 — forked from cvcore/download_vscode_server.sh
Manual download vscode-server
#!/bin/bash
# This script downloads and installs a specific version of VSCode Server for Linux.
# The version is specified by the first argument to the script.
# You can find the git commit id in the output of Remote - SSH plugin in VSCode.
# The output looks like this:
# ...
# Using commit id "af28b32d7e553898b2a91af498b1fb666fdebe0c" and quality "stable" for server
# ...
@blaylockbk
blaylockbk / numpy_datetime_to_datetime.py
Last active September 4, 2025 07:05
Convert numpy.datetime64 to datetime.datetime
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
@blaylockbk
blaylockbk / download_GOES_AWS.py
Created August 30, 2019 17:31
View and download GOES data on AWS with s3fs
# Brian Blaylock
# Requres `s3fs`
# Website: https://s3fs.readthedocs.io/en/latest/
# In Anaconda, download via conda-forge.
import s3fs
# Use the anonymous credentials to access public data
fs = s3fs.S3FileSystem(anon=True)
@blaylockbk
blaylockbk / loop_dates.sh
Created July 27, 2021 19:15
Loop over dates in a Bash script
#!/bin/bash
#=======================================================================
# Specify the "start" and "end" time.
#=======================================================================
# Use format "HH:MM YYYY-MM-DD"
start="00:00 2021-04-01"
end="00:00 2021-04-02"
increment="+1 hours"
#=======================================================================
@blaylockbk
blaylockbk / multipro_template.py
Last active January 5, 2025 12:08
Template for Python multiprocessing and multithreading
import multiprocessing
from multiprocessing.dummy import Pool as ThreadPool
import numpy as np
def my_multipro(items, func, max_cpus=12):
"""Do an embarrassingly parallel task using multiprocessing.
Use this for CPU bound tasks.
@blaylockbk
blaylockbk / pluck_points.py
Created October 8, 2021 22:45
get points nearest latitude/longitude point in xarray
'''
Brian Blaylock
Most recent function is located here:
https://github.com/blaylockbk/Carpenter_Workshop/blob/main/toolbox/gridded_data.py
But you should consider using the nearest_points() function instead, found here:
https://github.com/blaylockbk/Herbie/blob/master/herbie/tools.py
'''
@blaylockbk
blaylockbk / border.py
Created January 31, 2020 22:49
python function to extract the values around the border of an array
def border(array, corner=0, direction='cw'):
"""
Extract the values arround the border of a 2d array.
Default settings start from top left corner and move clockwise.
Corners are only used once.
Parameters
----------
array : array_like
@blaylockbk
blaylockbk / IWWG16-participants.geojson
Created May 13, 2023 00:16
16th IWWG Workshop Participants
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@blaylockbk
blaylockbk / nearest_latlon_index.py
Created July 27, 2020 20:28
I often have xarray datasets with latitude and longitude coordinates (not as xarray dimensions). When I need to pluck values from a point nearest to a specific lat/lon coordinate (like a weather station), this is what I use...
import numpy as np
import xarray as xr
def to_180(lon):
"""
Wrap longitude from degrees [0, 360] to degrees [-180, 180].
An alternative method is
lon[lon>180] -= 360