Commit 732d8334 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

added photometry routine from Hu Zou

parent 9978aeeb
Loading
Loading
Loading
Loading
+0 −0

Empty file added.

+890 −0

File added.

Preview size limit exceeded, changes collapsed.

+63 −0
Original line number Diff line number Diff line
# author zouhu
import numpy as np


def fluxerr2magerr(flux, fluxerr, asinh=False, filter='u', zp=22.5):
    """
    convert flux and flux error to mag and mag error (in pogson or asinh form)

    Parameters:
    flux, fluxerr in nanamaggie

    return mag and magerr
    """
    flux = np.array(flux)
    fluxerr = np.array(fluxerr)
    # f0=1.0e9
    f0 = 10 ** (zp / 2.5)
    nn = flux.size
    mag = np.array(np.ones_like(flux) * 99.0)
    magerr = np.array(np.ones_like(flux) * 99.0)
    if not asinh:
        mask = flux > 0
        if mask.any():
            mag[mask] = -2.5 * np.log10(flux[mask] / f0)
            magerr[mask] = 2.5 / np.log(10.0) * fluxerr[mask] / flux[mask]
    else:
        bs = {'u': 1.4e-10, 'g': 0.9e-10, 'r': 1.2e-10, 'i': 1.8e-10, 'z': 7.4e-10}
        b = bs[filter]
        mag = -(2.5 / np.log(10.0)) * (np.arcsinh((flux / f0) / (2.0 * b)) + np.log(b))
        magerr = 2.5 / np.log(10.0) * (fluxerr / f0) / (2.0 * b) / np.sqrt(1.0 + ((flux / f0) / (2.0 * b)) ** 2)
    return mag, magerr


def magerr2fluxerr(mag, magerr, asinh=False, filter='u', zp=22.5):
    """
    convert mag and mag error to flux and flux error (in pogson or asinh form)

    Parameters:
        mag,magerr ndarray

    return
        flux, fluxerr in nanamaggie
    """
    # f0=1.0e9
    f0 = 10 ** (zp / 2.5)
    if not asinh:
        flux = 10.0 ** (mag / (-2.5)) * f0
        fluxerr = flux * magerr * np.log(10.0) / 2.5
    else:
        bs = {'u': 1.4e-10, 'g': 0.9e-10, 'r': 1.2e-10, 'i': 1.8e-10, 'z': 7.4e-10}
        b = bs[filter]
        flux = np.sinh(mag / (-2.5 / np.log(10.0)) - np.log(b)) * 2.0 * b * f0
        fluxerr = magerr * np.log(10.0) / 2.5 * (2.0 * b) * np.sqrt(1.0 + ((flux / f0) / (2.0 * b)) ** 2) * f0
    return flux, fluxerr


def asinhpogson(mag1, magerr1, asinh2pogson=False, filter='u', zp=22.5):
    """
    convert magnitude form between asinh and pogson
    """
    flux, fluxerr = magerr2fluxerr(mag1, magerr1, asinh=asinh2pogson, filter=filter, zp=zp)
    mag2, magerr2 = fluxerr2magerr(flux, fluxerr, asinh=(not asinh2pogson), filter=filter, zp=zp)
    return mag2, magerr2
+9 −0
Original line number Diff line number Diff line
how to use csst photometry pipeline
Package dependencies: latest versions of "SExtrator" and "PSFEx"
1. python3.8 csst_photometry.py csst_image  -o output_path 
2. use the API in a pipeline
   from csst_photometry  import do_phot
   imagefile='/line17/csst/simulation_new/MSC_MS_210525121500_100000001_01_img.fits' 
   outdir='./'
   do_phot(imagefile,outdir=outdir) 
 
+18 −0
Original line number Diff line number Diff line
import os
import time

import numpy as np

from csst_photometry import do_phot

ccds = np.arange(6, 26, 1)
indir = '/line17/zouhu/csst/simulation_new'
outdir = '/line17/zouhu/csst/simulation_new/cat_tan/'

for i in range(len(ccds)):
    iccdstr = '%2.2d' % ccds[i]
    start = time.time()
    ifits = os.path.join(indir, 'MSC_MS_210525121500_100000001_' + iccdstr + '_img.fits')
    print(ifits)
    if not os.path.isfile(ifits): continue
    do_phot(ifits, outdir=outdir, stage="phot")
Loading