Skip to content

Instantly share code, notes, and snippets.

View Sunmish's full-sized avatar

Stefan Duchesne Sunmish

View GitHub Profile
@Sunmish
Sunmish / mnras_coords.py
Last active August 17, 2017 06:24
Print a string of coordinates in sexagesimal format for use in MNRAS LaTeX articles.
def mnras_coords(ra, dec):
'''Convert coordinates to MNRAS LaTeX friendly strings.
ra, dec must be in the format hh:mm:ss.s, dd:mm:ss, and will only return
the precision shown there.
'''
ra_hms, dec_dms = ra, dec
if '+' in dec_dms:
@Sunmish
Sunmish / hms_dms_dd.py
Last active October 31, 2017 01:51
Convert sky coordinates from hh:mm:ss and dd:mm:ss to decimal degrees.
def hms_dms_dd(ra, dec, delimiter=" "):
"""Convert from HMS; DMS to DD.
Examples:
>>> ra, dec = hms_dms_dd("00h59m59.3s", "-00d00m01.01s")
>>> ra, dec
(14.997083333333332, -0.00028055555555555554)
>>> ra, dec = hms_dms_dd("23 59 59", "+56 00 00")
>>> ra, dec
(359.99583333333334, 56.0)
@Sunmish
Sunmish / strip_naxis.py
Created January 16, 2018 03:06
Strip extra axes from FITS file.
import numpy as np
from astropy.io import fits
def strip_naxis(fitsimage, outname=None, strip_wcs=True):
"""Strip additional axes from FITS file.
Strips axes 3 and/or 4 if present.
Parameters
# ---------------------------------------------------------------------------- #
#
# Perform radial basis function interpolation on a sparse grid provided a
# reference array/image is available.
# Alternatively, perform nearest neighbout interpolation.
# Generalisation of code present in https://github.com/nhurleywalker/fits_warp
#
# ---------------------------------------------------------------------------- #
from __future__ import print_function, division
#! /usr/bin/env python
from __future__ import print_function, division
import numpy as np
from argparse import ArgumentParser
from astropy.io.votable import parse_single_table
def open_xml(xml):
@Sunmish
Sunmish / brats_prep.py
Last active May 20, 2019 08:23
Prepare a set of file for use with BRATS. Requires MIRIAD.
#! /usr/bin/env python
from __future__ import print_function, division
import os
import shutil
from subprocess import Popen
from argparse import ArgumentParser
from astropy.io import fits
@Sunmish
Sunmish / fluxtools.py
Last active April 7, 2024 16:59
Measure integrated flux densities in images.
# TODO:
# Add precision options. Currently values are returned at arbitrary precision.
# Add `strip_extra_axes` function for use when reading in FITS images.
# Clean up read_fits and associated FITS file handling functions.
# Fix up documentation.
# This code is years worth of additions and changes that represent my own 'journey' in learning python
# and studying radio astronomy - so some (a lot) of it is horribly ineffecient.
import numpy as np
#! /usr/bin/env python
from argparse import ArgumentParser
import numpy as np
from scipy.optimize import curve_fit
from matplotlib import pyplot as plt
def powerlaw(x, a, b):
return a*(x**b)
def powerlaw_amplitude(x0, y0, b):
@Sunmish
Sunmish / ms_uvcoverage.py
Created August 31, 2020 14:05
UV coverage and plot. Takes a while. Needs a lot of RAM.
#! /usr/bin/env python
from __future__ import print_function, division
import numpy as np
import sys
from astropy.constants import c; c = c.value
import matplotlib as mpl
@Sunmish
Sunmish / clip_image.py
Created June 14, 2021 09:23
Clip a FITS image using a different FITS image (e.g. of RMS noise or sensitivity).
#! /usr/bin/env python
from astropy.io import fits
import numpy as np
from argparse import ArgumentParser
def clip(image, clip_image, clip_level, outname,
fill_value=0):
"""
"""