In [1]:
import numpy as np
import os
import pysynphot as s
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
jpas_filters_path = '/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Filters/JPAS_filters'
jplus_filters_path = '/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Filters/JPLUS_SDSS_filters'
test_specs = '/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Sanity_Check/Specs'
results_path = '/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Sanity_Check/Results'
jpas_filters_list = np.loadtxt('/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Filters/jpas_filters_list.txt', dtype=str)
jplus_filters_list = np.loadtxt('/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Filters/jplus_filters_list.txt', dtype=str)
specs_list = np.loadtxt('/home/mldantas/Dropbox/DoutoradoIAG/Challenge/Sanity_Check/specslist2.txt', dtype=str)
In [3]:
# Constants --------------------------------------------------------------------------------------------------------
c = 2.99792458E18 # Light Speed in Angstrom s^-1
In [4]:
# Setting the T80 M1 effective area in cm^2 ------------------------------------------------------------------------
s.setref(area=4400)
In [5]:
# JPLUS -------------------------------------------------------------------------------------------------------------
all_jplus = []
for each_spectrum in specs_list:
# Transforming the specs from f_lambda to f_nu -----------------------------------------------------------------
wavelength = np.loadtxt(os.path.join(test_specs, each_spectrum), usecols=[0])
f_lambda = np.loadtxt(os.path.join(test_specs, each_spectrum), usecols=[1])
# Simulating the photometry for each J-PAS band ----------------------------------------------------------------
print each_spectrum
filter_name = []
photometry = []
photometry_flam = []
lambda_eff = []
for jplus_filters in jplus_filters_list:
try:
filter_name_i = jplus_filters.split('.')[0]
filter_name.append(filter_name_i)
jplus_filter_bandpass = s.FileBandpass(os.path.join(jplus_filters_path, jplus_filters))
sdss_spectrum = s.FileSpectrum(os.path.join(test_specs, each_spectrum))
index = np.where(sdss_spectrum.flux > 0)
sdss_spectrum2 = s.ArraySpectrum(wave=sdss_spectrum.wave[index], flux=sdss_spectrum.flux[index],
fluxunits=sdss_spectrum.fluxunits, waveunits=sdss_spectrum.waveunits)
binset = jplus_filter_bandpass.wave
photometry_i = s.Observation(sdss_spectrum2, jplus_filter_bandpass, binset=binset,
force='extrap')
photometry.append(photometry_i.effstim('abmag'))
lambda_eff_i = photometry_i.efflam()
lambda_eff.append(lambda_eff_i)
photometry_flam_i = photometry_i.effstim('flam')
photometry_flam.append(photometry_flam_i)
except ValueError:
print ("Photometry with problems")
# fmax = sdss_spectrum.flux.max()
# plt.plot(jplus_filter_bandpass.wave, jplus_filter_bandpass.throughput * fmax, label='%s' % each_spectrum, color='red')
filter_name = np.array(filter_name)
photometry = np.array(photometry)
lambda_eff = np.array(lambda_eff)
photometry_flam = np.array(photometry_flam)
photometry_fnu = 10**(-0.4*(photometry + 48.60))
# numerator_sum = 0
# denominator_sum = 0
# ratio = []
# for j in range(lambda_eff.size):
# index = np.abs(lambda_eff[j] - wavelength).argmin()
# numerator_sum = numerator_sum + (photometry_flam[j] * f_lambda[index])
# denominator_sum = denominator_sum + (photometry_flam[j] ** 2.)
# correction_factor = (numerator_sum / denominator_sum)
# ratio_i = photometry_flam[j]/f_lambda[index]
# ratio.append(ratio_i)
# photometry_flam = photometry_flam * correction_factor
plot01 = plt.plot(wavelength, f_lambda, '-')
plot02 = plt.plot(lambda_eff, photometry_flam, 'o')
# plt.legend([plot01], [r"{0:s}".format(str(each_spectrum))])
plt.savefig(os.path.join(results_path, os.path.split(each_spectrum)[-1][0:14]+'_JPLUS.png'), dpi = 100)
plt.show()
galaxy_simulation_abmag = np.vstack((filter_name, photometry))
galaxy_simulation_abmag = pd.DataFrame(galaxy_simulation_abmag)
galaxy_simulation_abmag.to_csv(os.path.join(results_path, os.path.split(each_spectrum)[-1][0:14]+'_JPLUS_abmag.csv'),
sep=',', header=None, index=False)
galaxy_simulation_fnu = np.vstack((filter_name, photometry_fnu))
galaxy_simulation_fnu = pd.DataFrame(galaxy_simulation_fnu)
galaxy_simulation_fnu.to_csv(os.path.join(results_path, os.path.split(each_spectrum)[-1][0:14]+'_JPLUS_fnu.csv'),
sep=',', header=None, index=False)
In [ ]:
In [ ]: