Skip to content

Instantly share code, notes, and snippets.

View tommylees112's full-sized avatar
🐘

Tommy Lees tommylees112

🐘
  • University of Oxford
  • Oxford
View GitHub Profile
@tommylees112
tommylees112 / demo_sonde_data.py
Last active April 6, 2021 17:01
example script for loading in pandas csv file and a very basic SkewT plot
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
# make sure the data is loaded
data_dir = Path("/Users/tommylees/Downloads")
df = pd.read_csv(data_dir / "demo_sonde.csv", index_col=0)
# initialise plot
f, ax = plt.subplots()
@tommylees112
tommylees112 / environment_xarray.sh
Last active April 6, 2021 12:38
Simple xarray python environment
conda create -n py
conda activate py
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray black mypy pandas --yes
# test
ipython -c "import xarray; import numpy; import pandas; import matplotlib; print('Everything Worked!')"
@tommylees112
tommylees112 / metpy_env.sh
Created April 5, 2021 08:50
working metpy conda environment
# metpy_env.sh
conda create -n metpy --yes
conda activate metpy
conda install -c conda-forge metpy --yes
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray descartes black mypy --yes
# NOTE: can only install geopandas with conda if python=3.7
# conda install -c conda-forge geopandas --yes
# pip install geopandas
@tommylees112
tommylees112 / run_camera.py
Created April 4, 2021 12:50
Take camera image
"""
append to bottom of `/home/pi/.bashrc`
nohup python3 /home/pi/REACH_tjx/scripts/run_camera.py
"""
from datetime import datetime
from time import sleep
from picamera import PiCamera
@tommylees112
tommylees112 / antonia_plot_code.py
Created April 3, 2021 14:01
initial plotting code for antonia
import xarray as xr
import matplotlib.pyplot as plt
import seaborn as sns
preds = xr.open_dataset("test_predictions_E030.nc")
preds = preds.drop(["horizon", "easting", "northing"])
f, ax = plt.subplots(figsize=(12, 4))
preds.isel(pixel=0).sel(time="2007").obs.plot(ax=ax, color="k")
preds.isel(pixel=0).sel(time="2007").sim.plot(ax=ax)
@tommylees112
tommylees112 / clinton_environment.sh
Last active May 25, 2021 14:47
Environment for Clinton with Spyder
# environment_rioxarray.sh
conda create -n rioxarray --yes
conda activate rioxarray
conda install -c conda-forge geopandas --yes
conda install -c conda-forge rioxarray rasterio --yes
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray descartes black mypy --yes
conda install -c anaconda spyder
# test it has worked
ipython -c "import geopandas; import rioxarray; import xarray"
@tommylees112
tommylees112 / environment_rioxarray.sh
Last active February 1, 2023 09:50
Working environment for rioxarray + tools
# environment_rioxarray.sh
conda create -n rioxarray --yes
conda activate rioxarray
conda install -c conda-forge geopandas --yes
conda install -c conda-forge rioxarray rasterio --yes
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray descartes statsmodels scikit-learn black mypy --yes
# test it has worked
ipython -c "import geopandas; import rioxarray; import xarray"
@tommylees112
tommylees112 / clip_netcdf_to_shapefile.py
Created March 28, 2021 09:33
chopping a shapefile from netcdf files
"""
Mask xarray dataset using a shapefile [closed]
https://stackoverflow.com/a/64587946/9940782
"""
from typing import Tuple
import geopandas as gpd
import xarray as xr
import rasterio as rio
from pathlib import Path
import numpy as np
@tommylees112
tommylees112 / run_cumulusMX.sh
Created March 27, 2021 18:13
Shell to run cumulusMX
mono /home/pi/CumulusMX/CumulusMX.exe &
@tommylees112
tommylees112 / run_cumulusMX.py
Created March 27, 2021 18:04
script to run CumulusMX in the background (has to work on python2.7)
# outF = open("run_cumulusMX.sh", "w")
# line = “mono /home/pi/CumulusMX/CumulusMX.exe &”
# outF.write(line)
# outF.close()
import os
os.system("mono /home/pi/CumulusMX/CumulusMX.exe &")