Skip to content

Instantly share code, notes, and snippets.

View DaniJonesOcean's full-sized avatar

Dani Jones DaniJonesOcean

  • CIGLR, University of Michigan
  • Ann Arbor, MI
View GitHub Profile
@cbur24
cbur24 / random_sampling.py
Last active January 11, 2023 00:35
Python function for generating random samples across an xarray.DataArray
def random_sampling(da,
n,
sampling='stratified_random',
manual_class_ratios=None,
out_fname=None
):
"""
Creates randomly sampled points for post-classification
accuracy assessment.
@MuhsinFatih
MuhsinFatih / fix-macos-python.md
Last active July 26, 2024 03:50
How to recover from messed up python installation on mac, and never have to mess with apple's shitty python confusion factory

I am assuming you are here because like me, you installed a bazillion different python interpreters on mac and the whole thing is a spagetti. Today, I finally fixed my python installation. Whatever I install for python2 or python3 using pip JUST.WORKS.. My god! finally.

What the hell?

Here is what I had messed up, which you also probably did:

  • I had too many different python interpreters
  • Too many different symlinks which I lost track of
  • almost no package I installed with pip worked without a headache
  • any attempt to fix using online resources made it worse.
@Kukanani
Kukanani / save_and_load_sklearn_gmm
Created April 10, 2018 22:49
Save and load a Scikit-learn GMM to file using np.save
import numpy as np
from sklearn import mixture
# make a GMM
gmm = mixture.GaussianMixture(n_components=n_components, covariance_type=cv_type)
# fit the GMM however you'd like
# save to file
gmm_name = 'new_gmm'
np.save(gmm_name + '_weights', gmm.weights_, allow_pickle=False)
@braaannigan
braaannigan / interactive_plot.py
Last active March 23, 2018 01:41
Interactive plots with holoviews in a jupyter notebook - needs to be in two separate code cells, see text for details
# The following must be executed in a jupyter notebook rather than a shell environment.
# Use numpy to work with arrays
import numpy as np
# Use scipy.stats to do plot some statistical data
import scipy.stats as stats
import holoviews as hv
# Holoviews builds on top of either the Matplotlib or Bokeh plotting library. Choose to use Bokeh
# in these plots as interactive plots work very well with Bokeh
hv.notebook_extension('bokeh')
@anttilipp
anttilipp / oceanTemperatureAnomalies.py
Created August 20, 2017 18:41
Python / matplotlib code & data to construct the sea surface temperature anomaly visualization
#
# Hi,
# this is the Python code I used to make the sea surface temperature anomaly
# visualization https://twitter.com/anttilip/status/899005930141921280.
# This is a version in which the AREA of the circle represents the temperature
# anomaly (not radius).
# The data is included in this file but I plan to write some kind of tutorial
# in the near future how the average temperatures were computed (using GDAL
# and suitable masks).
# Feel free to improve, modify, do whatever you want with this code. If you decide