Apply t-SNE to galaxy spectra from two different simulations.
First import some modules
import numpy as np
%matplotlib inline
| import numpy as np | |
| import h5py | |
| import glob | |
| files = glob.glob('snap*') | |
| coods = [None] * len(files) | |
| ages = [None] * len(files) | |
| metals = [None] * len(files) |
| import numpy as np | |
| # dimensions (age,metallicity,wavelength) | |
| a = 2 | |
| Z = 3 | |
| wl = 4 | |
| weights = np.random.rand(a,Z,1) | |
| grid = np.random.randint(1,10,(a,Z,wl)) |
| """ | |
| Taken from https://stackoverflow.com/questions/22840092/unpickling-data-from-python-2-with-unicode-strings-in-python-3 | |
| Updated for numpy bytes_ object | |
| """ | |
| import numpy as np | |
| def bytes_to_unicode(ob): | |
| t = type(ob) |
| #!/bin/bash | |
| # Clear output file | |
| > out.csv | |
| while read f; do | |
| # read in line to array, comma delimited | |
| arrIn=(${f//,/ }) |
| from scipy.stats import binned_statistic | |
| import random | |
| def resample_distribution(x, y, k=300, bin_limits=None): | |
| """ | |
| Resample y to fit distribution of x | |
| Args: | |
| x, y (array) distributions | |
| k (int) number of samples |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <title>Mondrian Generator</title> | |
| <script src="https://d3js.org/d3.v4.js" charset="utf-8"></script> | |
| <style> | |
| </style> | |
| </head> | |
| <body> |
| $ git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch filename' --prune-empty -f -- --all | |
| $ rm -rf .git/refs/original/ | |
| $ git reflog expire --expire=now --all | |
| $ git gc --prune=now | |
| $ git gc --aggressive --prune=now | |
| $ git push origin --force --all | |
| $ git push origin --force --tags |
To use this stylesheet, you need to put it inside your mplconfig_dir. By default, mpl_configdir should be ~/.config/matplotlib, but you can check where yours is with matplotlib.get_configdir(). You can then import it with styleuse('sm').
Based on work by Monica L. Turner, http://space.mit.edu/~turnerm/python.html (accessed 5/7/2016)
| library(MASS) | |
| # generate a million lognormal samples | |
| n <- 1000000 | |
| dat <- rlnorm(n, meanlog = 0, sdlog = 1) | |
| # add some noise (optional) | |
| dat <- dat + runif(n, 0, 1) | |
| # create a vector of histogram breaks |