Skip to content

Instantly share code, notes, and snippets.

View jthielen's full-sized avatar

JT Thielen jthielen

View GitHub Profile
@jthielen
jthielen / wrf_run_post_cf_loop.py
Created August 15, 2021 03:17
WRF Post-Process to CF Example
#!/usr/bin/env python
from itertools import product
from multiprocessing import Pool, Process
import numpy as np
import xarray as xr
import metpy.calc as mpcalc
from datetime import datetime
@jthielen
jthielen / metpy_test_thermo_lcl_mpconsts.txt
Created October 17, 2019 01:33
Tests from MetPy Analytic LCL calculations
============================= test session starts ==============================
platform linux -- Python 3.7.3, pytest-4.6.2, py-1.8.0, pluggy-0.12.0
Matplotlib: 3.0.2
Freetype: 2.6.1
Dependencies: Matplotlib (3.0.2), NumPy (1.17.0), Pandas (0.24.2), Pint (0.10.dev0), SciPy (1.3.0), Xarray (0.14.0+5.g408807c6)
rootdir: /home/jon/dev/MetPy, inifile: setup.cfg
plugins: flake8-1.0.4, cov-2.7.1, mpl-0.10
collected 123 items
tests/calc/test_thermo.py ..............FF............FFFFFFFFFFFFF..... [ 37%]
@jthielen
jthielen / StringPreprocessor.py
Last active September 4, 2019 18:46
Idea for extensible unit string preprocessor for pint
class StringPreprocessor(object):
"""Constructor for a extensible unit expression string preprocessor."""
# List of default replacement pairs
_default_replacements = [(",", ""),
(" per ", "/"),
("^", "**")]
# List of default regex substitution pairs.
_default_subs_re = [('\N{DEGREE SIGN}', " degree"),
@jthielen
jthielen / constant_change.diff
Created September 3, 2019 21:37
MetPy Constants change from Pint v0.9 to Pint v0.10
diff --git a/metpy_constants_pint_0_9.txt b/metpy_constants_pint_0_10.txt
index e9af145..0558c33 100644
--- a/metpy_constants_pint_0_9.txt
+++ b/metpy_constants_pint_0_10.txt
@@ -11,10 +11,10 @@ earth_avg_radius
6371200.0 meter
G
-6.673840000000001e-11 meter ** 3 / kilogram / second ** 2
+6.6743e-11 meter ** 3 / kilogram / second ** 2
@jthielen
jthielen / metpy_test_with_pint_master_20190726.txt
Created July 27, 2019 02:28
Results of a run of pytest with the current master branches of MetPy and pint (as of 2019-07-26)
============================= test session starts ==============================
platform linux -- Python 3.7.3, pytest-4.6.2, py-1.8.0, pluggy-0.12.0
Matplotlib: 3.0.2
Freetype: 2.6.1
Dependencies: Matplotlib (3.0.2), NumPy (1.16.4), Pint (0.10.dev0), SciPy (1.3.0)
rootdir: /home/jon/dev/MetPy, inifile: setup.cfg
plugins: flake8-1.0.4, cov-2.7.1, mpl-0.10
collected 878 items
metpy/calc/tests/test_basic.py ............................FF.F.....F... [ 4%]
@jthielen
jthielen / wrf_python_extraction.py
Created May 3, 2019 18:44
Use wrf-python, xarray, and pyproj to post-process WRF output
from wrf import getvar
from netCDF4 import Dataset
import xarray as xr
import pyproj
# Extract the variables of interest at time index 17
ds = Dataset('../wrfout_d02_2015-07-12_1200.nc')
variables = [getvar(ds, var, 17) for var in ('z', 'dbz', 'pressure', 'ter', 'ua',
'va', 'wa', 'temp', 'rh')]
data = xr.merge(variables)
import numpy as np
import pyproj
import xarray as xr
# Generate LCC Grid
def generate_lcc_grid(nx = 532, ny = 532, dx = 3000., dy = 3000.,
central_latitude = 39.05, central_longitude = -95.68,
standard_parallels = 39.05,
globe_kwargs = {'a': 6370000, 'b': 6370000}):
# Inputs default to Squiteri and Gallus (2016) WRF grid