Skip to content

Instantly share code, notes, and snippets.

View iancze's full-sized avatar

Ian Czekala iancze

View GitHub Profile
@iancze
iancze / convert-frames.py
Created April 16, 2024 15:43
Use astropy to convert from LSRK to BARY reference frame.
from astropy.coordinates import SkyCoord, ICRS, LSR
import astropy.units as u
import numpy as np
from numpy.linalg import norm
# convert from degrees to radian
deg = np.pi / 180.0
# coordinates of AK Sco
# 16 54 44.8497760618 -36 53 18.560813962
import numpy as np
from matplotlib import pyplot as plt
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, WhiteKernel
plt.style.use("seaborn-v0_8-white")
# Training data is y values representing the brightness profile
y_train = np.array(
@iancze
iancze / FITS-example.py
Created January 23, 2024 12:06
Example snippets for reading a FITS image
import numpy as np
from astropy.io import fits
def get_extent(header):
"""Get extent (in RA and Dec, units of [arcsec]) of image"""
# get the coordinate labels
nx = header["NAXIS1"]
ny = header["NAXIS2"]
@iancze
iancze / datasets.py
Created December 23, 2023 15:43
Old MPoL Spheroidal Gridding Routines Deprecated by NuFFT
# custom dataset loader
class UVDataset(torch_ud.Dataset):
r"""
Container for loose interferometric visibilities.
Args:
uu (2d numpy array): (nchan, nvis) length array of u spatial frequency coordinates. Units of [:math:`\mathrm{k}\lambda`]
vv (2d numpy array): (nchan, nvis) length array of v spatial frequency coordinates. Units of [:math:`\mathrm{k}\lambda`]
@iancze
iancze / example_plate.py
Last active February 16, 2023 23:59
Pyro: using latent variables with a plate
import torch
from torch import nn
import numpy as np
import pyro
import pyro.distributions as dist
from torch.distributions import constraints
from pyro.nn import PyroModule, PyroParam, PyroSample
from pyro.infer import Predictive, MCMC, NUTS
@iancze
iancze / plot.py
Created October 12, 2020 11:41
Matplotlib rasterized=True demonstration.
import matplotlib.pyplot as plt
import numpy as np
n = 100000
x = np.random.normal(size=n)
y = np.random.normal(size=n)
pkw = {"marker": "o", "alpha": 0.1, "mew": 0, "ms": 2, "ls": ""}
fig, ax = plt.subplots(nrows=1)
(finufft_install) ➜ finufft git:(master) ✗ make python3
g++ -c -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp src/spreadinterp.cpp -o src/spreadinterp.o
g++ -c -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp src/utils.cpp -o src/utils.o
g++ -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp -c -o src/finufft1d.o src/finufft1d.cpp
g++ -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp -c -o src/finufft2d.o src/finufft2d.cpp
g++ -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp -c -o src/finufft3d.o src/finufft3d.cpp
g++ -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp -c -o src/dirft1d.o src/dirft1d.cpp
g++ -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp -c -o src/dirft2d.o src/dirft2d.cpp
g++ -fPIC -O3 -I src -Xpreprocessor -fopenmp -DNEED_EXTERN_C -Xpreprocessor -fopenmp -c -
@iancze
iancze / read_idl_sav.py
Created November 22, 2019 19:40
Read and plot the APF spectra
import numpy as np
from scipy.io import readsav
from matplotlib import pyplot as plt
w_idl = readsav("w_rl23.2142")
w = w_idl["w"] # wavelengths in AA
fl_idl = readsav("rl23.2127")
f = fl_idl["sp"] # fluxes in arbitrary units
import numpy as np
c_kms = 2.99792458e5 # km/s
dv = 0.5 # km/s
wl_start = 5000.0
wl_end = 5100.0
CDELT1 = np.log10(dv/c_kms + 1.)
@iancze
iancze / astro.txt
Created April 1, 2019 16:45
Astrometric and radial velocity data from Hartkopf et al. 1996 and Tokovinin 1993.
date, PA, PA_err, rho, rho_err
1949.650 , 160. , . , . , .
1952.86 , . , . , 0.119 , .
1952.88 , . , . , 0.107 , .
1953.89 , . , . , 0.119 , .
1955.99 , . , . , 0.110 , .
1959.98 , 341.9, . , 0.111 , .
1962.01 , 344.3, . , 0.117 , .
1963.03 , . , . , 0.113 , .
1964.016 , 161.2, . , 0.280 , .