Skip to content

Instantly share code, notes, and snippets.

View JBorrow's full-sized avatar

Josh Borrow JBorrow

View GitHub Profile
@JBorrow
JBorrow / extract_lightcone_properties.py
Created May 8, 2025 22:22
Improved SOAP-ified version of the lightcone halo catalog creation tool based on https://gist.github.com/robjmcgibbon/e91ca85838f84401214a51ba7ed7cb7f
"""
Loads in one of John's lightcone halo catalogues and collates
a separate property in a separate file.
Example config.json:
{
"lightcone_cat_base": "/cosma8/data/dp004/flamingo/Runs/L1000N1800/HYDRO_FIDUCIAL/hbt_lightcone_halos/lightcone0/lightcone_halos_SNAPNUM.hdf5",
"soap_cat_base": "/cosma8/data/dp004/flamingo/Runs/L1000N1800/HYDRO_FIDUCIAL/SOAP-HBT/halo_properties_SNAPNUM.hdf5",
"snap_start": 0,
@JBorrow
JBorrow / tdp_flow.py
Created September 6, 2024 17:32
SO-TDP Example Pipeline
"""
An example script showing how a prefect flow for the TDP pipeline.
"""
import prefect
import pixell
from pathlib import Path
from pydantic import BaseModel
import datetime
import numpy as np
@JBorrow
JBorrow / setup_link.py
Last active August 28, 2024 14:49
Script for creating two librarians together
@JBorrow
JBorrow / main.c
Created July 31, 2024 18:11
Coadd map (C using apple Accelerate/LAPACK)
#include <stdio.h>
#include <Accelerate/Accelerate.h>
#define N_MAPS 3
#define N_X 32
#define N_Y 32
#define N_RUNS 1024
@JBorrow
JBorrow / custom_handle.py
Created May 26, 2024 15:01
Custom handles for matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.lines import Line2D
from matplotlib.collections import LineCollection
from matplotlib.legend_handler import HandlerLineCollection
class HandlerStackedLines(HandlerLineCollection):
"""
Custom Handler for LineCollection instances.
@JBorrow
JBorrow / extract_lightcone_properties.py
Created May 22, 2024 15:10
Quick python script to read in ancillary variables for jch's lightcone halo catalogues.
"""
Loads in one of John's lightcone halo catalogues and collates
a separate property in a separate file.
Example config.json:
{
"lightcone_cat_base": "/cosma8/data/dp004/jch/FLAMINGO/lightcone_halos/HYDRO_FIDUCIAL/lightcone_halos/lightcone0/lightcone_halos_SHELLID.hdf5",
"vr_cat_base": "/cosma8/data/dp004/flamingo/Runs/L1000N1800/HYDRO_FIDUCIAL/VR/catalogue_SNAPNUM/vr_catalogue_SNAPNUM.properties.0",
"shell_start": 0,
@JBorrow
JBorrow / schema.py
Created March 28, 2024 08:38
Beanie Schema Evolution
"""
Schema evolution with MongoDB.
This explains and demonstrates why we need to use a
Mongo database instead of a SQL database for this project,
aside from other concerns about scalability, distribution,
etc.
The output of this script is:
@JBorrow
JBorrow / demo.py
Created March 27, 2024 15:41
Beanie Example
"""
This is a simple demo file to show you how to use beanie and how
it can help us represent our data in a structured and searchable way.
"""
from pydantic import Field
from beanie import Document, init_beanie, BackLink, Link
from motor.motor_asyncio import AsyncIOMotorClient
# We should probably come up with a better name than 'collection'
@JBorrow
JBorrow / plot_events.py
Last active February 1, 2024 16:12
Parses a globus events.csv file and produces a plot using python
"""
Plots transfer rate from globus log.
"""
#%%
from csv import reader
import matplotlib.pyplot as plt
import json
import datetime
from dateutil import parser as dateparser
@JBorrow
JBorrow / calculate_cost_per_particle.py
Last active August 24, 2023 18:26
Calculate cost of a Gadget snapshot from its contents.
import h5py
import numpy as np
import sys
PARTICLE_TYPES = [0, 1, 2, 3, 4, 5]
data = h5py.File(sys.argv[1], "r")
for particle_type in PARTICLE_TYPES:
nbytes = 0