In [1]:
import numpy as np
import os
import pysynphot as s
import pandas as pd


/usr/local/lib/python2.7/dist-packages/pysynphot/locations.py:44: UserWarning: PYSYN_CDBS is undefined; functionality will be SEVERELY crippled.
  warnings.warn("PYSYN_CDBS is undefined; functionality will be SEVERELY "
/usr/local/lib/python2.7/dist-packages/pysynphot/locations.py:119: UserWarning: Extinction files should be moved to $PYSYN_CDBS/extinction for compatibility with future versions of pysynphot.
  warnings.warn('Extinction files should be moved to '
/usr/local/lib/python2.7/dist-packages/pysynphot/locations.py:155: UserWarning: Extinction files not found in grid/extinction
  warnings.warn('Extinction files not found in %s' % (extdir,))
/usr/local/lib/python2.7/dist-packages/pysynphot/locations.py:133: UserWarning: PYSYN_CDBS is undefined; cannot find mtab/*_tmg.fits file
  warnings.warn("PYSYN_CDBS is undefined; cannot find %s file" % template)
/usr/local/lib/python2.7/dist-packages/pysynphot/locations.py:133: UserWarning: PYSYN_CDBS is undefined; cannot find mtab/*_tmc.fits file
  warnings.warn("PYSYN_CDBS is undefined; cannot find %s file" % template)
/usr/local/lib/python2.7/dist-packages/pysynphot/locations.py:133: UserWarning: PYSYN_CDBS is undefined; cannot find mtab/*_tmt.fits file
  warnings.warn("PYSYN_CDBS is undefined; cannot find %s file" % template)

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]:
# # JPAS -------------------------------------------------------------------------------------------------------------
all_jpas = []
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 ----------------------------------------------------------------
    filter_name = []
    photometry  = []
    for jpas_filters in jpas_filters_list:
        filter_name_i          = jpas_filters.split('.')[0]
        filter_name.append(filter_name_i)
        jpas_filter_bandpass = s.FileBandpass(os.path.join(jpas_filters_path, jpas_filters))        
#         print jpas_filter_bandpass.throughput
        sdss_spectrum        = s.FileSpectrum(os.path.join(test_specs, each_spectrum))
        photometry_i         = s.Observation(sdss_spectrum, jpas_filter_bandpass, binset=np.arange(3000, 11000), 
                                             force='extrap')
        photometry.append(photometry_i.effstim('abmag'))
        print photometry_i.efflam()

    filter_name       = np.array(filter_name)
    photometry        = np.array(photometry)
    photometry_fnu    = 10**(photometry + 48.60)/(-2.5)
    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]+'_JPAS_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]+'_JPAS_fnu.csv'), 
                                 sep=',', header=None, index=False)

 # 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 ----------------------------------------------------------------
    filter_name2 = []
    photometry2  = []
    for jplus_filters in jplus_filters_list:
        filter_name2_i          = jplus_filters.split('.')[0]
        filter_name2.append(filter_name2_i)
        jplus_filter_bandpass = s.FileBandpass(os.path.join(jplus_filters_path, jplus_filters))        
#         print jplus_filter_bandpass.throughput
        sdss_spectrum        = s.FileSpectrum(os.path.join(test_specs, each_spectrum))
        photometry2_i       = s.Observation(sdss_spectrum, jplus_filter_bandpass, binset=np.arange(3000, 11000), 
                                             force='extrap')
        print photometry_i.efflam()
        photometry2.append(photometry_i.effstim('abmag'))

    filter_name2    = np.array(filter_name2)
    photometry2     = np.array(photometry2)
    photometry2_fnu = 10**(photometry2 + 48.60)/(-2.5)
    galaxy_simulation_abmag = np.vstack((filter_name2, photometry2))
    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_name2, photometry2_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)


4905.34101521
3837.61010648
4221.75551905
4362.88650308
4279.25783714
4287.87496604
4417.59870952
4517.67232884
4534.27927617
4596.92121962
4690.006436
4805.05057508
4870.59481076
4956.80487682
5081.59692476
5154.67081166
5272.0814665
5346.59497317
5453.34568873
5533.81488158
5634.67686696
5725.92983774
5809.54704369
5917.43295446
6020.86046725
6108.83666686
6197.9379151
6312.64178784
6400.71856214
6501.21109375
6594.68169088
6684.12795388
6786.89700545
6879.85766522
6982.9755472
7074.95149054
7171.64804469
7272.26869865
7371.73215583
7476.00787787
7544.35055137
7672.00974404
7761.68957011
7864.3493576
7955.16919304
7907.19483545
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6338.27249816
6296.16965429
3930.53402901
4793.61939263
5565.1553177
4033.61865011
4054.86321092
4128.91319378
4202.69548747
4327.75863179
4439.413336
4496.44631543
4583.78349722
4687.46615795
4806.70568177
4875.33527225
4953.55936083
5083.22922336
5166.2857984
5285.21678122
5363.59703749
5480.16820567
5549.8440391
5655.38192649
5744.14918122
5819.76146893
5934.02385817
6041.38475557
6124.5665514
6205.38304983
6331.12887021
6408.28999965
6525.98373007
6592.48024122
6688.44203073
6788.2525226
6872.59402762
6977.21278212
7067.57924154
7158.15476301
7258.72114377
7356.55833807
7464.65246144
7513.60780917
7660.06697062
7741.34698818
7844.68959523
7936.3274055
8028.35318463
8137.52313722
8216.21538149
8309.28935847
8404.60202419
8499.24038427
8595.21462628
8702.16398646
8779.93220744
8880.94630722
8948.70631967
8423.25831641
6289.58174334
3970.77389945
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4396.72441373
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3558.48126185
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3810.18688858
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3922.01152699
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4022.62745705
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4038.77764152
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4198.8201317
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4285.34079479
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4378.51094391
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4474.51789613
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4575.07871236
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4668.46008176
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4735.00512119
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4838.08505134
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4946.67797706
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
5025.89963006
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
5126.53061531
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
5223.07503177
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
5384.90231023
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
5447.47459469
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
4144.68762416
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
5423.52000131
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3937.25759732
4909.90864252
5976.94783992
4603.10812983
4612.79270357
4420.43521941
4396.75993682
4548.3068723
4634.07795836
4606.84533808
4652.70532383
4743.81803959
4872.55331536
4919.12732858
4996.89472304
5144.48319381
5205.35973048
5331.86731749
5387.99669995
5501.95325661
5569.48632633
5679.03519219
5765.11350404
5836.29043102
5951.67658286
6058.53204731
6142.73051138
6222.93353891
6347.15790644
6425.14657605
6532.54747579
6621.67461301
6701.50684521
6812.74272117
6895.09439253
6994.94716479
7086.57562897
7182.37335692
7282.28270442
7380.43622645
7484.77708454
7552.22382241
7683.76243357
7768.96132268
7869.83968484
7965.05726627
8059.99231249
8164.26117608
8252.33555033
8345.98617849
8441.48880067
8538.45132208
8635.59178346
8739.55450685
8823.91212179
8909.73442606
8807.60252439
7082.40219764
6286.96063812
4206.84911172
4805.36836949
3670.44774387
3882.19267596
4010.27749079
4092.57925802
4175.23573918
4290.92525347
4397.64756484
4465.39120127
4553.81672199
4655.85662737
4768.21994599
4843.31764045
4933.02386424
5054.4314898
5132.32943325
5242.07035741
5328.40496872
5439.08161478
5517.57614837
5615.69092378
5707.88788625
5793.69130871
5904.70002669
6005.65734278
6090.9984143
6181.11352403
6299.02610118
6383.37869678
6485.86772707
6576.42225184
6661.17327807
6764.16804536
6851.45762813
6959.28048358
7050.57618489
7141.15406816
7239.70830165
7339.26510027
7448.65971941
7492.43316285
7641.23150259
7724.30316512
7829.98760901
7921.77040619
8010.92915222
8125.30760058
8181.08786269
7924.85576511
5956.76826699
5956.76826699
5956.76826699
5956.76826699
5956.76826699
5956.76826699
5956.76826699
5956.76826699
6257.57620675
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
Warning, 9 of 6001 bins contained negative fluxes; they have been set to zero.
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879
3816.31149879

In [ ]: