Skip to content

Instantly share code, notes, and snippets.

View mathause's full-sized avatar

Mathias Hauser mathause

  • IAC @ ETH Zurich
  • Zurich, Switzerland
  • 07:44 (UTC +02:00)
View GitHub Profile
@mathause
mathause / stats.py
Last active February 20, 2024 15:41
Mann-Whitney U rank test for xarray with Benjamini and Hochberg correction
import scipy as sp
import xarray as xr
import statsmodels as sm
import numpy as np
import statsmodels.stats.multitest
def mannwhitney(da1, da2, dim="time", global_alpha=0.05):
"""xarray wrapper for Mann-Whitney U test
@mathause
mathause / wrap_lon.py
Created August 2, 2023 12:10
wrap longitude to 180/ 360
import numpy as np
def wrap360(obj, lon='lon'):
"""
wrap longitude coordinates to 0..360
Parameters
----------
obj : xr.Dataset or xr.DataArray
@mathause
mathause / grid.py
Last active November 15, 2022 14:23
roll coords
def lon_to_180(ds, lon_coords="lon"):
# https://git.iac.ethz.ch/utility_functions/utility_functions_python/-/blob/master/xarray.py#L149
lon_orig = ds[lon_coords]
if lon_orig.ndim != 1:
raise ValueError("Currently only handels 1D grids")
with xr.set_options(keep_attrs=True):
import scipy as sp
import xarray as xr
ds = xr.tutorial.open_dataset('air_temperature').load()
ds = ds.air
xr.__version__
def mannwhitney_(v1, v2):
@mathause
mathause / startup
Last active December 10, 2019 15:22
IACETH conda startup file
#!/bin/bash
# configuration
dest_env=iacpy3_2019
# change to true to show which packages are installed with 'pip -e'
check_devel=false
# maybe print hostname
@mathause
mathause / time_middle_of_month.py
Last active October 16, 2018 12:39
python date in the middle of the month
def time_middle_of_month(beg, end=None, periods=None):
""" create vector with timestamps in the middle of the month
Parameters
----------
beg : date or date vector
Start date. If end is not given and beg is a vector, uses first
entry a start date and last entry as end date.
end : date
If given used as end date.