Skip to content

Instantly share code, notes, and snippets.

View ysBach's full-sized avatar
🎯
Focusing

Yoonsoo P. Bach ysBach

🎯
Focusing
View GitHub Profile
@ysBach
ysBach / SkyBoT+SBID.ipynb
Last active December 6, 2023 13:01
SkyBoT and JPL SBID comparison
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ysBach
ysBach / energy_vs_lst.py
Last active March 28, 2022 05:54
Energy vs LST plot
%config InlineBackend.figure_format = 'retina'
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import rcParams
from sklearn.cluster import DBSCAN
from astroquery.jplhorizons import Horizons
from astropy.table import vstack
# We need to do it in a separate cell. See:
@ysBach
ysBach / watch.py
Created January 8, 2022 15:50
Seat allocation watcher (SNU Astro, 2022)
import datetime
import time
import pandas as pd
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from collections import namedtuple
GradStudent = namedtuple("GradStudent", ["name", "passcode", "email"])
@ysBach
ysBach / is_list_like.py
Last active December 14, 2021 05:27
Check if a number of python objects is/are list-like
def is_list_like(*objs, allow_sets=True, func=all):
''' Check if inputs are list-like
Parameters
----------
*objs : object
Objects to check.
allow_sets : bool, optional.
If this parameter is `False`, sets will not be considered list-like.
@ysBach
ysBach / astropy_vs_fitsio.py
Last active December 13, 2021 00:51
FITS io speed test astropy & fitsio
# %%
import argparse
import datetime
import tempfile
import time
from pathlib import Path
import astropy
import fitsio
import numpy as np
@ysBach
ysBach / SNU-SAO_M15_radialplot.py
Created November 12, 2021 02:02
M15 radial profile from SNU-SAO 2021-11-01 observation
# %%
import ysfitsutilpy as yfu
import ysphotutilpy as ypu
import ysvisutilpy as yvu
from astropy.stats import sigma_clipped_stats
from photutils.aperture import CircularAperture, CircularAnnulus
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import rcParams
@ysBach
ysBach / load_ccd.py
Last active July 7, 2021 07:07
ccdproc does not support LTV/LTM for the "physical" coordinate in IRAF/DS9. `trim_ccd` supports it. Then `trim_ccd` is used in `load_ccd` to load fits files. Note that astropy has several issues so I had to write this messy workarounds. It also tries to use `fitsio` to boost the time to read a fits file (boosted by factor of up to ~100)
import numpy as np
from astropy.nddata import CCDData
import ccdproc
from astropy.io import fits
from trim_ccd import trim_ccd
try:
import fitsio
HAS_FITSIO = True
except ImportError:
@ysBach
ysBach / circular_mask.py
Created July 7, 2021 06:41
In some cases, you want to mask an object in the image (or ndarray). This function makes a general N-dimensional circular/spherical/... mask.
import numpy as np
def circular_mask(shape, center=None, radius=None, center_xyz=True):
''' Creates an N-D circular (circular, sphereical, ...) mask.
Parameters
----------
shape : tuple
The pythonic shape (not xyz order).
center : tuple, None, optional.
@ysBach
ysBach / change_to_quantity.py
Created July 7, 2021 06:38
astropy Quantity is very useful but very annoying as it introduces some overhead to codes (code gets longer, readability is degraded, time is increased, difficult to manage if non-Quantity and Quantity are used in mixed way by the user, e.g., when dealing with header information). This function is one that I used for ~5 years now to force a numb…
from astropy import units as u
def change_to_quantity(x, desired='', to_value=False):
''' Change the non-Quantity object to astropy Quantity or vice versa.
Parameters
----------
x : object changable to astropy Quantity
The input to be changed to a Quantity. If a Quantity is given, `x` is changed to the
`desired`, i.e., ``x.to(desired)``.
@ysBach
ysBach / binning.py
Last active July 7, 2021 06:34
Binning a given ndarray with a given binnig function (``ysfitsutilpy.misc.binning``)
import numpy as np
def binning(arr, factor_x=None, factor_y=None, factors=None, order_xyz=True, binfunc=np.mean, trim_end=False):
''' Bins the given arr frame.
Paramters
---------
arr: 2d array
The array to be binned