Page MenuHomec4science

mockimgs_fits_compute_area
No OneTemporary

File Metadata

Created
Fri, Jan 24, 18:30

mockimgs_fits_compute_area

#!/usr/bin/env python3
import numpy as np
from astropy.io import fits
from astropy import constants as cte
from astropy import units as u
import argparse
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from pNbody import *
from pNbody import ic
import pickle
####################################################################
# option parser
####################################################################
description=""
epilog =""""""
parser = argparse.ArgumentParser(description=description,epilog=epilog,formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(action="store",
dest="files",
metavar='FILE',
type=str,
default=None,
nargs='*',
help='a file name')
parser.add_argument("-o",
action="store",
type=str,
dest="outputfilename",
default=None,
help="Name of the output file")
####################################################################
# main
####################################################################
cs = plt.cm.get_cmap('jet')
nmagbins = 50
magmin = 26
magmax = 33
magbins = np.linspace(magmin,magmax,nmagbins)
if __name__ == '__main__':
opt = parser.parse_args()
n = len(opt.files)
for j,f in enumerate(opt.files):
hdu = fits.open(f)
data = np.ravel(hdu[0].data)
data = np.compress(data<100,data)
data0 = data
Npix = np.zeros(nmagbins)
for i in tqdm(range(nmagbins)):
data = np.where(data0<magbins[i],1,0)
Npix[i] = np.ravel(data).sum()
label = os.path.basename(f)
label = label[label.find("_")+1:]
label = label[:-4]
plt.plot(magbins,Npix,color=cs(int(255*j/n)),label=r"$%s$"%label,lw=2)
plt.legend()
plt.xlabel(r"$\rm{VIS}\,\,\rm{magnitude}$")
plt.ylabel(r"$\rm{Area\,\,\rm{pixels}}$")
if opt.outputfilename is None:
plt.show()
else:
plt.savefig(opt.outputfilename)

Event Timeline