Skip to content

Instantly share code, notes, and snippets.

View smutch's full-sized avatar

Simon Mutch smutch

View GitHub Profile
@smutch
smutch / jlab.janet
Created June 11, 2024 07:46
janet: Launch a jupyterlab session on Spartan
#!/usr/bin/env janet
(use sh)
(import cmd)
# terminal formatting
(defn format [v]
(def t {:green "\e[0;32m"
:red "\e[0;31m"
:yellow "\e[0;33m"
@smutch
smutch / mps-wrapper
Created May 15, 2023 23:24
sh: MPS SLURM wrapper script
#!/bin/bash
# Author: Simon Mutch <smutch.astro@gmail.com>
# Date: 2018-08-14
set -e # error on exit
get_log_dir() {
echo "$JOBFS/log_mps-$1"
}
@smutch
smutch / plot.py
Created August 3, 2022 03:11
py: Plot tree image example
import numpy as np
import h5py as h5
import matplotlib.pyplot as plt
from pathlib import Path
DATA_PATH = Path("tree_images.h5")
ID = "619000000001104"
with h5.File(DATA_PATH, "r") as fp:
image = fp[f"{ID}/mass"][:]
@smutch
smutch / readme.md
Last active July 11, 2022 23:25
Spartan tips and tricks
@smutch
smutch / coverage-badge.json
Last active January 23, 2023 23:49
ci: Snakedoc coverage badge
{"schemaVersion":1,"label":"coverage","message":"84%","color":"green"}
@smutch
smutch / battery_status.sh
Created July 8, 2021 01:18
sh: battery status for tmux
#!/usr/bin/env bash
bstat=( $(pmset -g batt | grep -Eo '[0-9]+%.*' | awk '{print($1,$2)}' | tr -d ";") )
percentage=$(echo "${bstat[0]}" | tr -d "%")
case $((
(percentage >= 0 && percentage < 25) ? 1 :
(percentage >= 25 && percentage < 50) ? 2 :
(percentage >= 50 && percentage < 75) ? 3 :
@smutch
smutch / mass_resolution.py
Created July 5, 2021 01:58
py:mass resolution
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.11.3
# kernelspec:
@smutch
smutch / read_grids.py
Last active July 27, 2020 00:19
py: Read in a Genesis grid directly with xarray
import numpy as np
import xarray as xa
import h5py as h5
from pathlib import Path
from tqdm import tqdm
GRIDS_DIR = Path("PATH_GOES_HERE")
def grid_path(snapshot: int, sub: int):
return GRIDS_DIR / f"snapshot_{snapshot:03d}.den.{sub}"
@smutch
smutch / read_grid.py
Created July 8, 2020 09:24
py: read postprocess grid
import numpy as np
import xarray as xa
import h5py as h5
PATH_IN = "/fred/oz078/smutch/intensity_mapping/baseline/imapping_testrun/HIMass_grids.h5"
SNAPSHOT = 250 # z=0
with h5.File(PATH_IN, "r") as fp:
ds = fp[f"Snap{SNAPSHOT:03d}"]
box_size = ds.attrs["box_size"][:]
@smutch
smutch / check_density_totals.py
Created March 18, 2020 02:45
py: check VELOCIraptor density grids totals against theory
#!/usr/bin/env python
"""Test the Genesis grids totals against cosmology. This is to help K Ren (see email 2020-03-17)."""
__author__ = "Simon Mutch"
__date__ = "2020-03-18"
from pathlib import Path
import logging