Skip to content

Instantly share code, notes, and snippets.

View christopherlovell's full-sized avatar
🍊

Chris Lovell christopherlovell

🍊
View GitHub Profile
@christopherlovell
christopherlovell / heic_convert.sh
Created July 8, 2024 17:20
Convert heic files and resize
for filename in IMG_38*; do heif-convert $filename ${filename}.png; done
for filename in IMG_38*.png; do mogrify -resize 50% $filename; done
@christopherlovell
christopherlovell / filter_test.py
Created January 11, 2024 16:15
Synthesizer load filter test
import numpy as np
import matplotlib.pyplot as plt
from synthesizer.filters import Filter, FilterCollection
filter_codes = ["JWST/NIRCam.F444W", "JWST/NIRCam.F480M"]
filtcoll = FilterCollection(filter_codes=filter_codes)
fig, ax = filtcoll.plot_transmission_curves(show=False, linestyle='solid')
@christopherlovell
christopherlovell / pca.py
Created October 4, 2023 19:33
PCA example
"""
PCA visualisation based on the example here:
https://gist.github.com/anonymous/7d888663c6ec679ea65428715b99bfdd
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
plt.style.use('dark_background')
from swiftsimio import Writer
from swiftsimio.units import cosmo_units
import unyt
import numpy as np
import h5py
import glob
files = glob.glob('ics*.hdf5')
@christopherlovell
christopherlovell / train_rnn_test.py
Created March 14, 2022 23:48
train rnn example
import sys
import os
import numpy as np
import matplotlib
# matplotlib.use('agg')
from matplotlib import pyplot as plt
# from IPython.display import clear_output
import tensorflow as tf
# physical_devices = tf.config.experimental.list_physical_devices('GPU')
# assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
@christopherlovell
christopherlovell / weighted_percentile.py
Last active January 17, 2020 13:26
Calculate the binned, weighted percentile
def weighted_quantile(values, quantiles, sample_weight=None,
values_sorted=False, old_style=False):
"""
Taken from From https://stackoverflow.com/a/29677616/1718096
Very close to numpy.percentile, but supports weights.
NOTE: quantiles should be in [0, 1]!
:param values: numpy.array with data
:param quantiles: array-like with many quantiles needed
"""
Script for creating subsets of particles from gizmo sims
Authors:
- Sydney Lower
- Chris Lovell
"""
import h5py
import caesar
@christopherlovell
christopherlovell / 0_schwimmbad_demo.py
Last active September 4, 2019 21:01
Example Schwimmbad usage
"""
A tutorial introduction to Schwimmbad
https://github.com/adrn/schwimmbad
To install the requirements:
> cat requirements.txt | xargs pip install
"""
@christopherlovell
christopherlovell / read_snaps.py
Created March 25, 2019 17:39
Read hdf5 snaps and concatenate
import numpy as np
import h5py
import glob
files = glob.glob('snap*')
coods = [None] * len(files)
ages = [None] * len(files)
metals = [None] * len(files)
@christopherlovell
christopherlovell / einsum_demo.py
Created March 6, 2019 17:37
Demo of numpy einsum matrix multiplication / summation functionality
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))