Skip to content

Instantly share code, notes, and snippets.

View j08lue's full-sized avatar

Jonas j08lue

View GitHub Profile
import numpy as np
from scipy.spatial import cKDTree as KDTree
import xarray as xr
def grid_to_points(grid, points, coord_names):
"""Index a gridded dataset with a Pandas DataFrame of station coordinates
grid : xr.Dataset or xr.DataArray
gridded source data
points : pd.Dataframe
@j08lue
j08lue / xray_irregular_slice_before_load.ipynb
Last active October 12, 2015 13:57
This is to illustrate an issue with the Python xray package, where slicing with unsorted indices works on a loaded DataArray but not on an unloaded one. (Issue https://github.com/xray/xray/issues/623)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j08lue
j08lue / KU_gender.ipynb
Created August 4, 2015 09:41
University of Copenhagen faculties gender distribution 2015
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j08lue
j08lue / PHC30_ASCII_to_netCDF.py
Created July 28, 2015 11:09
Convert Polar science center Hydrographic Climatology (PHC) 3.0 data from Levitus ASCII to netCDF
"""
Convert PHC 3.0 data from Levitus ASCII to netCDF
Polar science center Hydrographic Climatology (PHC)
A Global Ocean Hydrography with a High Quality Arctic Ocean
http://psc.apl.washington.edu/nonwp_projects/PHC/Climatology.html
Citation:
PHC 3.0, updated from:
Steele, M., R. Morley, and W. Ermold, PHC: A global
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j08lue
j08lue / xray_mfdataset_pop.ipynb
Last active August 29, 2015 14:23
xray.open_mfdataset concatenating static variables - example from POP model output
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j08lue
j08lue / lt_archive.sh
Created June 17, 2015 14:56
CESM 1.2.2 data archiving scripts
#!/bin/bash
msls () {
rd=$1
ssh_loc=$2
scp_loc=$3
if [ "${ssh_loc}" != "" ] && [ "${scp_loc}" != "" ]; then
ssh -q ${ssh_loc} "ssh -q ${scp_loc} ls -l ${rd}"
fi
@j08lue
j08lue / findadds.py
Created June 16, 2015 09:46
Find email addresses in some text (e.g. html) file
import re
with open('cic.html', 'r') as f:
raw = f.read()
r = r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
add = re.findall(r, raw)
unique = sorted(set(add))
@j08lue
j08lue / struct.py
Last active July 2, 2023 04:10
Struct class
class Struct():
"""Create a custom class from a dictionary
Usage
-----
Initialize empty, with a dictionary, and/or
with any number of key=value pairs
Note
----
@j08lue
j08lue / extradds.py
Created November 6, 2014 09:04
extract email addresses from some string
import re
def extract_email_addresses(adds):
adds = ''.join(adds.split())
adds = re.sub(r'(\"|\,)', ' ', adds)
adds = re.split(r'\<(.*?\@.*?)\>', adds)
#adds = re.findall(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", ''.join(adds))
adds = [a for a in adds if '@' in a]
return adds