#!/usr/bin/python
from numpy import searchsorted, median, concatenate
from dazer_methods import Dazer

#Create class object
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_dataframe(catalogue_dict['dataframe'])

#Set figure format
dz.FigConf('night')
 
#Loop through the objects
for i in range(len(catalogue_df.index)):
     
    #Object
    objName = catalogue_df.iloc[i].name
     
    #Joining pointing
    joining_wavelength = catalogue_df.iloc[i].join_wavelength
 
    #Treat each arm file    
    blue_fits_file = catalogue_df.iloc[i]['zBlue_file'] 
    red_fits_file = catalogue_df.iloc[i]['zRed_file'] 
 
    CodeName_Blue, FileName_Blue, FileFolder_Blue = dz.Analyze_Address(blue_fits_file)
    CodeName_Red, FileName_Red, FileFolder_Red = dz.Analyze_Address(red_fits_file)
 
import pandas       as pd
from os             import makedirs
from astropy.io     import fits
from os.path        import isdir
from dazer_methods  import Dazer
from shutil         import rmtree, copy
from collections    import OrderedDict
  
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
   
dz = Dazer()
 
#Input and output locations
input_folders = [
    '/home/vital/Astrodata/WHT_2008_01/Night2/',
    '/home/vital/Astrodata/WHT_2009_07/Night1/',
    '/home/vital/Astrodata/WHT_2009_07/Night2/',
    '/home/vital/Astrodata/WHT_2011_11/Night1/',
    '/home/vital/Astrodata/WHT_2011_11/Night2/',
    '/home/vital/Astrodata/WHT_2016_04/Night1/',
    '/home/vital/Astrodata/WHT_2016_04/Night2/']
output_folder = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/'

#Delete the folder contents
if isdir(output_folder):
    rmtree(output_folder)
 
catalogue_df        = pd.DataFrame()
catalogue_colums    = ['codename', 'objCode', 'folder_address', 'file_name', 'folder_code','night', 'time_obs', 'arm_color', 'aperture', 'parent_file_address', 'reduc_tag', 'telluric_star', 'telluric_file', 'chemistry_valid', ]
   
Exemple #3
0
     
    indmin, indmax      = searchsorted(PartialWavelength, (Bot, Top))
     
    LineHeight          = max(PartialIntensity[indmin:indmax])
    LineExpLoc          = median(PartialWavelength[where(PartialIntensity == LineHeight)])
           
    return PartialWavelength, PartialIntensity, LineHeight, LineExpLoc
 
def region_indeces(wave_min, wave_max, wavenlength_range):
     
    low_trim, up_trim   = searchsorted(wavenlength_range, [wave_min, wave_max])
    indeces_array       = array(range(low_trim, up_trim))
     
    return indeces_array

dz = Dazer()
dz_reduc = spectra_reduction()

script_code = dz.get_script_code()
lickIndcs_extension = '_lick_indeces.txt'
 
#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx')
image_address = '/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/images/telluric_correction_detail'

SIII_theo = 2.469
H7_H8_ratio_theo = 1.98

#Set figure format
size_dict = {'figure.figsize': (16, 10), 'axes.labelsize':20, 'legend.fontsize':20, 'font.family':'Times New Roman', 'mathtext.default':'regular', 'xtick.labelsize':20, 'ytick.labelsize':20}
Exemple #4
0
from dazer_methods import Dazer
from numpy import nanmean, nanstd, mean, nan as np_nan
from uncertainties import ufloat, unumpy, umath
import pandas as pd

#Generate dazer object
dz = Dazer()

#Declare figure format
size_dict = {
    'figure.figsize': (14, 6),
    'axes.labelsize': 20,
    'legend.fontsize': 20,
    'font.family': 'Times New Roman',
    'mathtext.default': 'regular',
    'xtick.labelsize': 20,
    'ytick.labelsize': 20
}
dz.FigConf(plotSize=size_dict)

#Declare data location
folder_data = '/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/teporingos/Grid_data_vital/'
file_name_list_S = [
    'TGrid_Mass100000.0_age5.48_zStar-2.1_zGas0.008.ele_S',
    'TGrid_Mass200000.0_age5.48_zStar-2.1_zGas0.008.ele_S'
]
file_name_list_O = [
    'TGrid_Mass100000.0_age5.48_zStar-2.1_zGas0.008.ele_O',
    'TGrid_Mass200000.0_age5.48_zStar-2.1_zGas0.008.ele_O'
]
z_list = ['100000', '200000']
Exemple #5
0
#!/usr/bin/env python
import lineid_plot
from collections import OrderedDict
from dazer_methods import Dazer
from numpy import linspace, zeros, hstack
from scipy.interpolate import interp1d
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from matplotlib import pyplot as plt

#Declare code classes
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
cHbeta_type = 'cHbeta_reduc'
nebular_exten = '_NebularContinuum.fits'
Stellar_ext = '_StellarContinuum.fits'
emitting_ext = '_Emission.fits'

#Define plot frame and colors
size_dict = {
    'axes.labelsize': 20,
    'legend.fontsize': 18,
    'font.family': 'Times New Roman',
    'mathtext.default': 'regular',
import uncertainties.unumpy as unumpy
from dazer_methods import Dazer
from libraries.Math_Libraries.fitting_methods import LinfitLinearRegression
from pandas import set_option
set_option('display.max_rows', None)
set_option('display.max_columns', None)

#Declare coding classes
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
lineslog_extension = '_' + catalogue_dict[
    'Datatype'] + '_linesLog_reduc.txt'  #First data log for reduced spectra

#Reddening properties
R_v = 3.4
red_curve = 'G03'

#Set figure format
dz.FigConf()

# Loop through files
for i in range(len(catalogue_df.index)):

    #try:
Exemple #7
0
#!/usr/bin/env python

from dazer_methods import Dazer
from numpy import loadtxt
from os.path import basename

#Declare dazer object
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
mask_extension = '_Mask.lineslog'
dz.RootFolder = '/home/vital/'

#Define plot frame and colors
dz.FigConf()
'''
MRK36_A1
MRK36_A2
MAR1324
MAR2071
4_n2
MAR1324
MAR2071
52319-521
51991-224
52235-602 SI
import pandas as pd
from numpy import loadtxt
from dazer_methods import Dazer
from collections import OrderedDict

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)

#Generate dazer object
dz = Dazer()

format_file = '/home/vital/git/Dazer/Dazer/dazer/bin/catalogue_dataframe_format.dz'

#We load the export dataframe
objects_folder  = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/'
export_df       = pd.read_pickle('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/transition_df')


key_codes, description, latex_format = loadtxt(format_file, dtype=str, delimiter=';', unpack=True)

#Rows indeces and columns from the dataframe
list_exported   = list(OrderedDict.fromkeys(export_df.folder_code.values)) #trick to keep the order
catalogue_df    = pd.DataFrame(columns = key_codes)

print list_exported

for objcode in list_exported:
    
    #Data from arm
    for color in ['Blue', 'Red']:
     
#!/usr/bin/python
from numpy import searchsorted, median
from dazer_methods import Dazer

#Create class object
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_dataframe(catalogue_dict['dataframe'])

#Set figure format
dz.FigConf()

color_dict = {'Blue':dz.colorVector['dark blue'],'Red':dz.colorVector['orangish']}

#Loop through the objects
for i in range(len(catalogue_df.index)):
    
    #Object
    objName = catalogue_df.iloc[i].name
    
    #Joining pointing
    joining_wavelength = catalogue_df.iloc[i].join_wavelength

    #Treat each arm file
    for color in ['Blue', 'Red']:
    
        fits_file = catalogue_df.iloc[i]['z{}_file'.format(color)] 
        
#!/usr/bin/python
from time import time
from os import remove
from dazer_methods import Dazer
from DZ_observation_reduction import spectra_reduction

#Create class object
dz = Dazer()
 
FilesList = dz.Folder_Explorer('',  '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/', CheckComputer=False, verbose=False, Sort_Output='alphabetically')
 
files_to_keep   = []
files_to_delete = []

for file_address in FilesList:
      
    CodeName, FileName, FolderName = dz.Analyze_Address(file_address, verbose=False)
      
    if (FileName in ['WHT_Galaxies_properties.txt']) or ('run' in FileName) or ('_lick_indeces.txt' in FileName):
        files_to_keep.append(FolderName + FileName)
    else:
        files_to_delete.append(FolderName + FileName)
 
print '\n--These files will be deleted:'
for file_address in files_to_delete:
    print file_address, ' -> X'
 
print '\n--These files will be preserved:'
for file_address in files_to_keep:
    print file_address, ' -> V'
 
    X = sm.add_constant(column_stack((x[0], empty_ones)))
    for ele in x[1:]:
        X = sm.add_constant(column_stack((ele, X)))
    results = sm.OLS(y, X).fit()
    return results

Oxygen_rejected     = ['51959-092', 'SDSS2', 'SHOC575v1', '04v2', 'SHOC593', '11', 'SHOC588']  
Nitrogen_rejected   = ['04v1', 'SDSS2',  'SHOC575v1', '04v2', 'SHOC593', '11', '52319-521', 'SHOC588', '70']   
Sulfur_rejected     = ['04v1', '51959-092',  'SHOC575v1', '04v2', 'SHOC593', '51991-224', '52319-521', '11', '52319-521', 'SHOC588', '27', '03'] 

rejected = list(set(Oxygen_rejected + Nitrogen_rejected + Sulfur_rejected))

print rejected, type(rejected)


dz = Dazer()
 
#Define data type and location
Catalogue_Dic  = dz.import_catalogue()
log_extension  = '_log.txt'

#Regression configuration
Method_index    = 3
MC_iterations   = 5000
 
#Locate files on hard drive
FilesList = dz.Folder_Explorer(log_extension, Catalogue_Dic['Obj_Folder'], CheckComputer=False)

#Load catalogue properties frame
catalogue_frame = dz.load_catalogue_frame(FilesList)
Exemple #12
0
import pymc
import pyneb as pn
import numpy as np
from dazer_methods import Dazer
from scipy.interpolate import interp1d
from libraries.Astro_Libraries.Nebular_Continuum import Nebular_Bayesian
from lmfit.models import LinearModel

H1 = pn.RecAtom('H', 1)

print H1.getEmissivity(tem=10000, den=100, wave=6563) / H1.getEmissivity(tem=10000, den=100, wave=4861)


#Declare code classes
dz = Dazer()
nb = Nebular_Bayesian()
 
#Define plot frame and colors
dz.FigConf(n_colors=5)
 
nb.ObjectData_dict = {}
nb.ObjectData_dict['nHeII_HII']             = 0.075
nb.ObjectData_dict['TOIII']                 = 10000
nb.ObjectData_dict['TOIII_error']           = 500.0
nb.ObjectData_dict['Flux_Hbeta_Normalize']  = 2.86  * 1e-14  / 1e-14
nb.ObjectData_dict['Error_Hbeta_Normalize'] = 0.05   * 1e-14  / 1e-14
 
wave = np.linspace(3500, 7000, 7000 - 3500 - 1)
nebular_flux_n = nb.Calculate_Nebular_gamma(nb.ObjectData_dict['TOIII'], nb.ObjectData_dict['Flux_Hbeta_Normalize'], nb.ObjectData_dict['nHeII_HII'] , 0.00, wave)
dz.data_plot(wave, nebular_flux_n, 'Nebular flux normalized', dz.ColorVector[2][1])
                self.Fitting_dict['FluxG' + index]  = ufloat(mean(self.Fitting_dict['FluxG' + index + '_norm']),     std(self.Fitting_dict['FluxG' + index + '_norm'])) * y_scale
                self.Fitting_dict['FluxI']          = ufloat(flux_I_N, std(self.Fitting_dict['FluxI_N_vector'])) * y_scale
        
        #Calculate the gaussian curve for plotting
        self.Fitting_dict['x_resample']             = linspace(line_wave[0], line_wave[-1], 50 * Ncomps)
        self.Fitting_dict['zerolev_resample']       = self.Fitting_dict['m_Continuum'] * self.Fitting_dict['x_resample'] + self.Fitting_dict['n_Continuum']
        self.Fitting_dict['y_resample']             = [self.gaussian_curve_SingleMixture_from_dict(self.Fitting_dict, self.Fitting_dict['x_resample'], self.Fitting_dict['zerolev_resample'], Ncomps = map(str, range(Ncomps)))]

        #We store all the gaussians for plotting alongside the big component
        for j in range(Ncomps):
            Comp = [str(j)]
            self.Fitting_dict['y_resample'].append(self.gaussian_curve_SingleMixture_from_dict(self.Fitting_dict, self.Fitting_dict['x_resample'], self.Fitting_dict['zerolev_resample'], Ncomps = Comp))

        return

dz = Dazer()
fg = Fitting_Gaussians()

#Define operation
Catalogue_Dic   = dz.import_catalogue()
Pattern         = 'SHOC579_WHT.fits'

#Locate files on hard drive
FilesList = dz.Folder_Explorer(Pattern, Catalogue_Dic['Obj_Folder'], CheckComputer=False)

#Generate plot frame and colors
dz.FigConf(n_colors=10)

for i in range(len(FilesList)):

    CodeName, FileName, FileFolder  = dz.Analyze_Address(FilesList[i])
from numpy import empty, random, median, percentile, array, linspace
from scipy import stats
from uncertainties import ufloat
from uncertainties.unumpy import nominal_values, std_devs
from libraries.Math_Libraries.sigfig    import round_sig

def forbidden_objects():
    
    oxygen_list     = ['coso', '71']
    nitrogen_list   = ['coso', '71']
    sulfur_list     = ['coso', '71', '70', '24', 'MRK36_A1', '52703-612']
    
    return [oxygen_list, nitrogen_list, sulfur_list]

#Create class object
dz = Dazer()
script_code = dz.get_script_code()

#Plot configuration
dz.FigConf()

#Load catalogue dataframe
catalogue_dict      = dz.import_catalogue()
catalogue_df        = dz.load_dataframe(catalogue_dict['dataframe'])

#Regressions properties
MC_iterations   = 100
WMAP_coordinates = array([ufloat(0.0, 0.0), ufloat(0.24709, 0.00025)])

#Generate the indeces
Regresions_dict = OrderedDict()
Exemple #15
0
from dazer_methods import Dazer
import matplotlib

# Generate dazer object
dz = Dazer()

# Choose plots configuration
dz.FigConf()

# Import catalogue
Catalogue = dz.import_catalogue()

# Perform operations

x = [1, 2, 3, 4, 5, 6]
y = [1, 2, 3, 4, 5, 6]

# Plot the data
dz.data_plot(x, y, markerstyle="o")

# Generate the figure
dz.display_fig()


# from DZ_DataExplorer                import Plots_Manager
#
# # We declare the folder and log file to drop the lines data
# pv = Plots_Manager()
#
# # Forcing the remake of new files
# pv.RemakeFiles = True
import pandas as pd
from dazer_methods import Dazer
from numpy import isnan

#Create class object
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict      = dz.import_catalogue()
catalogue_df        = dz.load_dataframe(catalogue_dict['dataframe'])
lineslog_extension  = '_' + catalogue_dict['Datatype'] + '_linesLog_emission.txt'#First data log for reduced spectra
lickIndcs_extension = '_lick_indeces.txt'

# Forcing the remake of new files
dz.RemakeFiles = True

n_objects = len(catalogue_df.index)

#Loop through the objects
for i in range(n_objects):

    #Object
    objName             = catalogue_df.iloc[i].name
    fits_file           = catalogue_df.iloc[i].stellar_fits
    ouput_folder        = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) 
    
    if isinstance(fits_file, str):

        #Output lines log dataframe
        lineslog_df         = pd.DataFrame(columns=dz.saving_parameters_list)
#!/usr/bin/python

from dazer_methods import Dazer

#Create class object
dz = Dazer()
script_code     = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict  = dz.import_catalogue()
catalogue_df    = dz.load_dataframe(catalogue_dict['dataframe'])
log_exension    = '_' + catalogue_dict['Datatype'] + '_linesLog_reduc.txt'

#Define operation
Catalogue_Dic           = dz.import_catalogue()
Pattern                 =  '_' + Catalogue_Dic['Datatype'] + '_linesLog_reduc.txt'

#Define table shape
Width                   = "%" + str(50+2) + "s"
HeaderSize              = 2
LickIndexesHeader       = ['Ion', 'lambda_theo', 'group_label','Wave1', 'Wave2', 'Wave3', 'Wave4', 'Wave5', 'Wave6', 'add_wide_component']
columns_format          = ['%11.6f', '%11.6f', '%11.6f','%11.6f', '%11.6f', '%11.6f', '%11.6f', '%11.6f', '%11.6f', '%11.6f']

#Loop through the objects
for i in range(len(catalogue_df.index)):

    #Object
    objName             = catalogue_df.iloc[i].name
    fits_file           = catalogue_df.iloc[i].reduction_fits
    ouput_folder        = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) 
    lineslog_address    = '{objfolder}{codeName}_WHT_linesLog_reduc.txt'.format(objfolder = ouput_folder, codeName=objName)
#!/usr/bin/python

from numpy import median, searchsorted, full, array, empty
from dazer_methods import Dazer

dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_dataframe(catalogue_dict['dataframe'])

#Set figure format
dz.FigConf()

#Calcium triplet location
lambda_CaII     = array([8498.0, 8542.0, 8662.0])

#Limits for the plot
lambda_limits   = array([8300, 8900])  

#Loop through the objects
for i in range(len(catalogue_df.index)):
       
    #Object
    objName     = catalogue_df.iloc[i].name
    fits_file   = catalogue_df.iloc[i].reduction_fits
    
    if objName == '8':

        print '-- Treating {} @ {}'.format(objName, fits_file)
'''
Created on May 18, 2015

@author: vital
'''

from dazer_methods import Dazer

dz = Dazer()

dz.FigConf(n_colors=5)

Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extblueG191fl.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/fcx2PHLblue.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/fcPHL-g191.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/fcPHLyes.fits'

Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/fcPHLyes.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extblueG191fl.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extblueG191fl.fits'

Fileaddress = '/home/vital/Astrodata/WHT_HIIGalaxies_FluxCalibration/2011_12_Night1/Blue/obj70_s_c_cr_f_a_bg.0001.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extPHL70blue.fits'
Fileaddress =  '/home/vital/Astrodata/WHT_HIIGalaxies_FluxCalibration/2011_12_Night1/Blue/obj70_s_c_cr_f_a_bg.0001_fxW.fits'
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/fcx2PHLblue.fits'

Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extblueBD17fl.fits'


# Fileaddress = '/home/vital/Desktop/Testing_reduction/stdG191v1_bg_Blue.fits'
from dazer_methods import Dazer
from numpy import empty, min, max, zeros, array
# from collections                            import OrderedDict
# from ManageFlow                             import DataToTreat
# from CodeTools.PlottingManager              import myPickle
# from Plotting_Libraries.dazer_plotter       import Plot_Conf
# from astropy.coordinates                    import EarthLocation
# from astropy.coordinates                    import SkyCoord
# from astropy.time                           import Time

# favoured_objects = ['72', '60', '61', '12', '29', '36', 'Mar1987', 'Mar2232', 'Mar2474', 'Mar88', 'Mar1315', 'Mar1390', 'Mar652', 'Mar2018', 'Mar1715', 'Mar2260', 'Mar1342', 'Mar87']

favoured_objects = ['02', '03', '05', '09', 'Mar2232']

#Generate dazer object
dz = Dazer()

#Define figure format
dz.FigConf(n_colors = 2)
cmap = dz.cmap_pallete()

#Define operation
Catalogue_Dic   = dz.import_catalogue()
Pattern         = '_log'

FilesList = dz.Folder_Explorer(Pattern,  Catalogue_Dic['Obj_Folder'], CheckComputer=False)
Hbeta_values, Flux_values, names, sn_values, z_values = [], [], [], [], []
g_mags, r_mags = [], []
Declination_values  = []

for i in range(len(FilesList)):
Exemple #21
0
#!/usr/bin/env python
from dazer_methods import Dazer
from numpy import linspace, zeros, hstack, array
from scipy.interpolate import interp1d
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes

#Declare code classes
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
cHbeta_type = 'cHbeta_reduc'
nebular_exten = '_NebularContinuum.fits'
Stellar_ext = '_StellarContinuum.fits'
emitting_ext = '_Emission.fits'

#Define plot frame and colors
size_dict = {
    'figure.figsize': (36, 10),
    'axes.labelsize': 25,
    'legend.fontsize': 25,
    'font.family': 'Times New Roman',
    'mathtext.default': 'regular',
    'xtick.labelsize': 25,
    'ytick.labelsize': 25
}
    # Set titles and legend
    plot_Title  = 'Galaxy ' + CodeName + ' SSP synthesis ' + r'$log(M_{T})$ = ' + r'$'+str(round(LogMass,2))+'$'
    plot_xlabel = r'$log(Age)$'
    plot_ylabel = r'Mass fraction % $(Mcor)$'
     
    dz.FigWording(plot_xlabel, plot_ylabel, plot_Title, loc = 'lower right')
        
    #Save the data to the Catalogue folder
    output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=script_code, objCode=CodeName, ext='MassFraction')
    dz.save_manager(output_pickle, save_pickle = True)
      
    return

#Declare objects

dz = Dazer()
script_code = dz.get_script_code()

#Define data type and location
Catalogue_Dic   = dz.import_catalogue()
catalogue_dict  = dz.import_catalogue()
catalogue_df    = dz.load_dataframe(catalogue_dict['dataframe'])
Stellar_ext     = '_StellarContinuum.fits'
Sl_OutputFolder = '/home/vital/Starlight/Output/'

#Define plot frame and colors
dz.FigConf()
colorVector = {
            'dark blue':'#0072B2',
            'green':'#009E73', 
            'orangish':'#D55E00',
import numpy as np
import pyneb as pn
import pyCloudy as pc
from dazer_methods import Dazer

import matplotlib.pyplot as plt
dz = Dazer()
dz.FigConf()

#Remove these pregenerated files
components_remove = [  #['radius', '.rad'],
    #['continuum', '.cont'],
    #['physical conditions', '.phy'],
    ['overview', '.ovr'],
    ['heating', '.heat'],
    ['cooling', '.cool'],
    ['optical depth', '.opd']
]

for item in components_remove:
    pc.config.SAVE_LIST.remove(item)

elements_remove = [['hydrogen', '.ele_H'], ['helium', '.ele_He'],
                   ['carbon', '.ele_C'], ['nitrogen', '.ele_N'],
                   ['oxygen', '.ele_O'], ['argon', '.ele_Ar'],
                   ['neon', '.ele_Ne'], ['sulphur', '.ele_S'],
                   ['chlorin', '.ele_Cl'], ['iron', '.ele_Fe'],
                   ['silicon', '.ele_Si']]

for item in elements_remove:
    pc.config.SAVE_LIST_ELEMS.remove(item)
from dazer_methods import Dazer
from pandas import set_option

set_option('display.max_rows', None)
set_option('display.max_columns', None)

#Create class object
dz = Dazer()

#Define operation
catalogue_dict = dz.import_catalogue()

#Load catalogue dataframe
catalogue_df = dz.load_dataframe(catalogue_dict['dataframe'])

sciData_table = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.txt'

Scientific_ObjectList   = dz.get_TableColumn(['Objects'], TableAddress = sciData_table, datatype = str)
EBV_List, z_blue, z_red, lambda_joining = dz.get_TableColumn(['E(B-V)_SF_Mean', 'zBlue_LinePondered', 'zRed_LinePondered', 'WHT_Joining'], TableAddress = sciData_table, datatype = float)
telluric_star = dz.get_TableColumn(['telluric_star'], TableAddress = sciData_table, datatype = str)

h_gamma_validity = dz.get_TableColumn(['h_gamma_valid'], TableAddress = sciData_table, datatype = str)

for i in range(len(Scientific_ObjectList)):
     
    if Scientific_ObjectList[i] in catalogue_df.index:
        
        catalogue_df.loc[Scientific_ObjectList[i], 'EBV_galactic']      = EBV_List[i]
        catalogue_df.loc[Scientific_ObjectList[i], 'z_Blue']            = z_blue[i]
        catalogue_df.loc[Scientific_ObjectList[i], 'z_Red']             = z_red[i]
        catalogue_df.loc[Scientific_ObjectList[i], 'join_wavelength']   = lambda_joining[i]
Exemple #25
0
from dazer_methods import Dazer

#Headers
plotting_Keys = [
    'SDSS_reference', 'SDSS_Web', 'z_Blue', 'RA', 'DEC', 'Dichroic'
]

headers = [
    'Local reference', 'SDSS reference', 'z',
    'RA (hh:{arcmin}:{arcsec})'.format(arcmin="'", arcsec='"'),
    'DEC (deg:{arcmin}:{arcsec})'.format(arcmin="'",
                                         arcsec='"'), 'ISIS configuration'
]

#Import library object
dz = Dazer()

#Load observational data
catalogue_df = dz.load_excel_DF(
    'E:\\Dropbox\\Astrophysics\\Data\\WHT_observations\\WHT_Galaxies_properties.xlsx'
)

#Define data to load
pdf_address = 'E:\\Dropbox\\Astrophysics\\Papers\\Yp_BayesianMethodology\\source files\\tables\\reference_table_noPreamble'

#Generate pdf
#dz.create_pdfDoc(pdf_address, pdf_type='table')
dz.pdf_insert_table(headers)

#Quick indexing
dz.quick_indexing(catalogue_df)
from libraries.Math_Libraries.sigfig    import round_sig
import statsmodels.formula.api as smf
from pandas import DataFrame
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
 
def forbidden_objects():
     
    oxygen_list     = ['coso', '71']
    nitrogen_list   = ['coso', '71']
    sulfur_list     = ['coso', '71', '70', '24', 'MRK36_A1', '52703-612']
     
    return [oxygen_list, nitrogen_list, sulfur_list]
 
#Create class object
dz = Dazer()
script_code = dz.get_script_code()
 
#Plot configuration
# dz.FigConf()
 
#Load catalogue dataframe
catalogue_dict      = dz.import_catalogue()
catalogue_df        = dz.load_dataframe(catalogue_dict['dataframe'])
 
#Regressions properties
MC_iterations   = 1000
WMAP_coordinates = array([ufloat(0.0, 0.0), ufloat(0.24709, 0.00025)])
 
#Generate the indeces
Regresions_dict = OrderedDict()
    dz.Axis.set_xticklabels(valid_objects, rotation='80')
    plt.subplots_adjust(bottom=0.30)
     
    dz.FigWording('HII galaxies', 'Helium abundance', 'HeI abundance from each line'.format(element=element), sort_legend=True)  #, XLabelPad = 20
               
    output_pickle = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/data/{element}_lineRatio'.format(element = element)
    dz.save_manager(output_pickle, save_pickle = True) 
    
    return

# random.normal(mean(HeII_HII_array), mean(HeII_HII_error), size = self.MC_array_len)


#Create class object

dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx')

#Set figure format
dz.FigConf()

marker_dict = {
'He1_3889A':dz.colorVector['iron'],
'He1_4026A':dz.colorVector['silver'],
'He1_4388A':dz.colorVector['skin'],
'He1_4438A':dz.colorVector['cyan'],
'He1_4472A':dz.colorVector['olive'],
from matplotlib import pyplot as plt
from dazer_methods import Dazer
from uncertainties import ufloat
from numpy import searchsorted, ceil as np_ceil, interp, random,  nanmean, nanstd, median
from pylatex import Math, NoEscape, Section
from os.path import isfile

#Create class object
dz = Dazer()

#Load catalogue dataframe
catalogue_dict  = dz.import_catalogue()
catalogue_df    = dz.load_dataframe(catalogue_dict['dataframe'])

#Grid configuration
n_columns = 4.0
sizing_dict = {'xtick.labelsize' : 8, 'ytick.labelsize' : 10, 'axes.titlesize':14}

#Declare data for the analisis
AbundancesFileExtension = '_' + catalogue_dict['Datatype'] + '_linesLog_emission.txt'
cHbeta_type = 'cHbeta_reduc'

#Atoms for the abundances
MC_length = 500
dz.load_elements()
oxygen_emision = ['O2_3726A', 'O3_4363A', 'O3_4959A', 'O3_5007A', 'O2_7330A'] 
nitrogen_emision = ['N2_6548A', 'N2_6584A'] 
sulfur_emision = ['S2_6716A', 'S3_6312A', 'S3_9069A', 'S3_9531A'] 

Te = random.normal(10000, 2000, size = MC_length)
ne = random.normal(100, 20, size = MC_length)
#!/usr/bin/env python

import pymc
import numpy as np
from dazer_methods import Dazer
from scipy.interpolate import interp1d
from libraries.Astro_Libraries.Nebular_Continuum import Nebular_Bayesian
from lmfit.models import LinearModel

#Declare code classes
dz = Dazer()
nb = Nebular_Bayesian()

#Declare data to treat
Catalogue_Dic       = dz.import_catalogue()
nebular_exten       = '_NebularContinuum.fits'
Stellar_ext         = '_StellarContinuum.fits'
emitting_ext        = '_Emission.fits'
cHbeta_type         = 'cHBeta_red'
AbundancesFileExtension = '_' + Catalogue_Dic['Datatype'] + '_emission_LinesLog_v3.txt'    #First data log for reduced spectra

#Find and organize files from terminal command or .py file
FilesList           = dz.Folder_Explorer(Stellar_ext,  Catalogue_Dic['Obj_Folder'], CheckComputer=False)
catalogue_frame     = dz.load_catalogue_frame(FilesList)
# 
# print catalogue_frame
# 
# #Define plot frame and colors
dz.FigConf(n_colors=5, fontsize=30)
# 
# lineal_mod = LinearModel(prefix='lineal_')
#!/usr/bin/env python

from dazer_methods import Dazer
from numpy import loadtxt

#Declare code classes
dz = Dazer()

#Declare data to treat
Catalogue_Dic  = dz.import_catalogue()
pattern        = Catalogue_Dic['Datatype'] + '.fits'

#Find and organize files from terminal command or .py file
FilesList      = dz.Folder_Explorer(pattern,  Catalogue_Dic['Obj_Folder'], CheckComputer=False)

#Define plot frame and colors
dz.FigConf(n_colors=5)

#Loop through files
for i in range(len(FilesList)):
    
    
    
    #Analyze file address
    CodeName, FileName, FileFolder  = dz.Analyze_Address(FilesList[i])
    
    #Import fits file    
    Wave, Int, ExtraData            = dz.File_to_data(FileFolder,FileName)
        
    #Getting the masks as a two lists with initial and final points            #WARNING the masks generated do not distinguish the absorptions
    MaskFileName                    = CodeName + '_Mask.lineslog'
Exemple #31
0
from numpy import nan as np_nan
from dazer_methods import Dazer
from pandas import notnull

#Generate dazer object
dz = Dazer()

#Load catalogue dataframe
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)

dz.quick_indexing(catalogue_df)

# counter = 1
# for obj in catalogue_df.index:
#
#     if catalogue_df.loc[obj,'Ignore_article'] != 'yes':
#
#         if notnull(catalogue_df.loc[obj,'Favoured_ref']):
#             catalogue_df.loc[obj,'quick_index'] = catalogue_df.loc[obj,'Favoured_ref']
#         else:
#             catalogue_df.loc[obj,'quick_index'] = str(counter)
#             counter += 1

idx_include = notnull(catalogue_df['quick_index'])

print catalogue_df.loc[idx_include, 'quick_index']

print 'Otra\n'
for obj in catalogue_df.loc[idx_include].index:
from dazer_methods import Dazer
from pandas import notnull
from numpy import median
from libraries.Astro_Libraries.Nebular_Continuum import NebularContinuumCalculator

# Declare objects
dz = Dazer()
nebCalc = NebularContinuumCalculator()
script_code = dz.get_script_code()

# Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_dataframe(catalogue_dict["dataframe"])
cHbeta_type = "cHbeta_reduc"
AbundancesFileExtension = "_" + catalogue_dict["Datatype"] + "_linesLog_reduc.txt"

# Define plot frame and colors
dz.FigConf()

# Loop through files only if we are dealing the WHT data and only scientific objects:
for i in range(len(catalogue_df.index)):

    print "-- Treating {} @ {}".format(catalogue_df.iloc[i].name, AbundancesFileExtension)
    try:

        # Locate the objects
        objName = catalogue_df.iloc[i].name
        ouput_folder = "{}{}/".format(catalogue_dict["Obj_Folder"], objName)
        fits_file = catalogue_df.iloc[i].reduction_fits
        lineslog_address = "{objfolder}{codeName}{lineslog_extension}".format(
            objfolder=ouput_folder, codeName=objName, lineslog_extension=AbundancesFileExtension
Exemple #33
0
from dazer_methods import Dazer
from DZ_observation_reduction import spectra_reduction
from numpy import isnan
import os.path

dz = Dazer()
dz_reduc = spectra_reduction()
script_code = dz.get_script_code()

catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)

dz.FigConf(Figtype='Grid_size', n_columns=1, n_rows=2)

for i in range(len(catalogue_df.index)):

    #print '\n-- Treating {} @ {}'.format(catalogue_df.iloc[i].name, catalogue_df.iloc[i].Red_file)

    codeName = catalogue_df.iloc[i].name
    fits_file = catalogue_df.iloc[i].Red_file
    ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], codeName)
    redshift_factor = 1 + catalogue_df.iloc[i].z_Red

    star = catalogue_df.iloc[i].telluric_star
    calibration_star = catalogue_df.iloc[i].calibration_star.split(';')[0]

    if os.path.isfile(
            '{reduc_folder}objects/{calibStar}_Red_slit5.0_n.fits'.format(
                reduc_folder=catalogue_df.iloc[i].obsfolder,
#!/usr/bin/env python
from dazer_methods import Dazer
from numpy import linspace, zeros, hstack
from scipy.interpolate import interp1d

#Declare code classes
dz = Dazer()
script_code = dz.get_script_code()


def colorLineZones(wave, int, zones, color):

    for pairWave in zones:
        print pairWave
        idces = (pairWave[0] <= wave) & (wave <= pairWave[1])
        dz.data_plot(wave[idces], int[idces], '', color=color)


def LineZones(wave, int, zones, color):

    for pairWave in zones:
        idces = (pairWave[0] <= wave) & (wave <= pairWave[1])
        dz.data_plot(wave[idces], int[idces], '', color=color)
        # dz.area_fill(wave[idces], int[idces], zeros(int[idces].size), alpha=0.5)
        dz.Axis.fill_between(wave[idces],
                             int[idces],
                             zeros(int[idces].size),
                             color=color,
                             alpha=0.5)

#!/usr/bin/env python

from dazer_methods import Dazer
from os.path import basename
#Declare code classes
dz = Dazer()

#Declare data to treat
catalogue_dict          = dz.import_catalogue()
catalogue_df            = dz.load_dataframe(catalogue_dict['dataframe'])
cHbeta_type             = 'cHbeta_reduc'
nebular_fits_exten      = '_NebularContinuum.fits'

#Generate plot frame and colors
dz.FigConf()

#Loop through files
for i in range(len(catalogue_df.index)):
    
    #Locate the objects
    objName             = catalogue_df.iloc[i].name
    ouput_folder        = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) 
    fits_file           = catalogue_df.iloc[i].reduction_fits
    nebular_fits        = ouput_folder + objName + nebular_fits_exten
    
    Wave_T, Int_T, header_T = dz.get_spectra_data(fits_file)
    Wave_N, Int_N, header_T = dz.get_spectra_data(ouput_folder + objName + nebular_fits_exten)

    #Perform the reddening correction
    cHbeta = catalogue_df.iloc[i][cHbeta_type]
    spectrum_dered = dz.derreddening_continuum(Wave_T, Int_T - Int_N, cHbeta.nominal_value)
Exemple #36
0
#!/usr/bin/env python

from dazer_methods import Dazer
from os.path import basename
#Declare code classes
dz = Dazer()

#Declare data to treat
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
nebular_fits_exten = '_NebularContinuum_emis.fits'
stellar_files_exten = '_emision'

#Generate plot frame and colors
dz.FigConf()

#Reddening properties
R_v = 3.4
red_curve = 'G03'
cHbeta_type = 'cHbeta_emis'

#Loop through files
for i in range(len(catalogue_df.index)):

    #Locate the objects
    objName = catalogue_df.iloc[i].name
    ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName)
    fits_file = catalogue_df.iloc[i].reduction_fits
    nebular_fits = ouput_folder + objName + nebular_fits_exten
Exemple #37
0
from dazer_methods import Dazer
from uncertainties import unumpy
from collections import OrderedDict
from pylatex import Package, NoEscape
from numpy import isnan
from pandas import isnull
from uncertainties import UFloat
#Import library object
dz = Dazer()

#Load observational data
catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx')
dz.quick_indexing(catalogue_df)

#Define data to load
ext_data = '_emis2nd'
pdf_address = '/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/tables/AbundancesTable'

#Headers
headers_dic = OrderedDict()
headers_dic['HeI_HI']   = r'$\nicefrac{He}{H}$'
headers_dic['Ymass_O']  = r'$Y_{\left(\nicefrac{O}{H}\right)}$'
headers_dic['Ymass_S']  = r'$Y_{\left(\nicefrac{S}{H}\right)}$'
headers_dic['OI_HI']    = r'$12 + log\left(\nicefrac{O}{H}\right)$'
headers_dic['NI_HI']    = r'$12 + log\left(\nicefrac{N}{H}\right)$'
headers_dic['SI_HI']    = r'$12 + log\left(\nicefrac{S}{H}\right)$'

properties_list = map(( lambda x: x + ext_data), headers_dic.keys())
headers_format = ['HII Galaxy'] + headers_dic.values()

#Create a new list for the different entries
from dazer_methods import Dazer
import os
import numpy as np

dz = Dazer()
dz.FigConf()

data_folder = '/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/popstar_kroupa_004/'

for file_name in sorted(os.listdir(data_folder)):

    print file_name

    file_address = os.path.abspath(os.path.join(data_folder, file_name))

    wave, flux = np.loadtxt(file_address, usecols=(0, 3), unpack=True)

    age_float = 10**float(file_name[file_name.find('_t') + 2:])
    print age_float / 1000000

    age = 'age = {} Myr'.format(round(age_float / 1000000, 2))

    dz.data_plot(wave, flux, label=age)

dz.Axis.set_xlim(0, 10000)
dz.Axis.set_ylim(1e-9, 1)
dz.Axis.set_yscale('log')

dz.FigWording(
    r'Wavelength $(\AA)$', r'Normalized flux',
    'Popstar grid for Kroupa IMF, $Z_{gas}=0.004$\n (including nebular continua)'
Exemple #39
0
# !/usr/bin/env python
import lineid_plot
from collections import OrderedDict
from dazer_methods import Dazer
from matplotlib import rcParams, pyplot as plt
from matplotlib._png import read_png
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
from matplotlib.cbook import get_sample_data

# Declare code classes
dz = Dazer()

# Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
cHbeta_type = 'cHbeta_reduc'
nebular_exten = '_NebularContinuum.fits'
Stellar_ext = '_StellarContinuum.fits'
emitting_ext = '_Emission.fits'

# Define plot frame and colors
size_dict = {
    'figure.figsize': (26, 10),
    'axes.labelsize': 28,
    'legend.fontsize': 28,
    'font.family': 'Times New Roman',
    'mathtext.default': 'regular',
    'xtick.labelsize': 28,
    'ytick.labelsize': 28
from dazer_methods import Dazer
from numpy import nanmean, nanstd, mean, nan as np_nan
from uncertainties import ufloat, unumpy
import pandas as pd

#Generate dazer object
dz = Dazer()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)

#Plot configuration
dz.FigConf()

idcs = (pd.notnull(catalogue_df.OI_HI_emis2nd)) & (pd.notnull(
    catalogue_df.NI_HI_emis2nd)) & (
        ~catalogue_df.index.isin(['0564', '3', '70', '51991-224']))

#Prepare data
O_values = catalogue_df.loc[idcs].OI_HI_emis2nd.values
N_values = catalogue_df.loc[idcs].NI_HI_emis2nd.values
objects = catalogue_df.loc[idcs].index.values

print objects

N_O_ratio = N_values / O_values

for i in range(len(N_O_ratio)):
from dazer_methods import Dazer

#Create class object
dz = Dazer()
script_code = dz.get_script_code()

#Define operation
catalogue_dict = dz.import_catalogue()

#Load catalogue dataframe
catalogue_df = dz.load_dataframe(catalogue_dict['dataframe'])

#Set figure format
dz.FigConf()

#Loop through the objects
for i in range(len(catalogue_df.index)):

    #Treat each arm file
    for color in ['Blue', 'Red']:
    
        if (color == 'Red') and (catalogue_df.iloc[i].tell_correction != 'None'):
            fits_file = catalogue_df.iloc[i].tellRed_file
        
        else:
            fits_file = catalogue_df.iloc[i]['{}_file'.format(color)]
        
        #Read the data
        redshift = catalogue_df.iloc[i]['z_{}'.format(color)]
        z_fits_file = fits_file.replace('.fits', '_z.fits')
    dz.FigWording(plot_xlabel, plot_ylabel, plot_Title, loc='lower right')

    #Save the data to the Catalogue folder
    output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(
        objFolder=ouput_folder,
        stepCode=script_code,
        objCode=CodeName,
        ext='MassFraction')
    dz.save_manager(output_pickle, save_pickle=True)

    return


#Declare objects

dz = Dazer()
script_code = dz.get_script_code()

#Define data type and location
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
Stellar_ext = '_StellarContinuum.fits'
Sl_OutputFolder = '/home/vital/Starlight/Output/'

#Define plot frame and colors
dz.FigConf()
colorVector = {
    'dark blue': '#0072B2',
    'green': '#009E73',
import numpy as np
from uncertainties import ufloat, unumpy
from dazer_methods import Dazer

#Generate dazer object
dz = Dazer()

#Set figure format
dz.FigConf()

file_tradional_reduc = '/home/vital/Dropbox/Astrophysics/Data/Fabian_Catalogue/data/Traditional_Abundances.xlsx'
file_starlight = '/home/vital/Dropbox/Astrophysics/Data/Fabian_Catalogue/data/Starlight_Abundances.xlsx'

df_dict = {}
df_dict['traditional'] = dz.load_excel_DF(file_tradional_reduc)
df_dict['starlight'] = dz.load_excel_DF(file_starlight)

type = 'traditional'
element = 'Oxygen'

conf_dict = {}
conf_dict['Oxygen_xlabel'] = r'y'
conf_dict['Nitrogen_xlabel'] = r'N/H $(10^{-6})$'
conf_dict['ylabel'] = r'$Y$'
conf_dict['title'] = 'Helium mass fraction versus {} abundance'.format(element)
conf_dict['legend_label'] = 'Data generated from {} treatment'.format(type)
conf_dict['Oxygen_color'] = 'green'
conf_dict['Nitrogen_color'] = 'blue'

x = df_dict[type][element]
y = df_dict[type].y
Exemple #44
0
from collections import OrderedDict
from dazer_methods import Dazer
import numpy as np

dz = Dazer()
dz.FigConf()

Grid_Values = OrderedDict()

Grid_Values = OrderedDict()
Grid_Values['age'] = ['5.0', '5.48', '6.0', '6.48', '6.72']
Grid_Values['clus_mass'] = [
    '12000.0', '20000.0', '60000.0', '100000.0', '200000.0'
]
Grid_Values['zGas'] = ['0.0004', '0.004', '0.008', '0.02']
Grid_Values['zStars'] = ['-2.1']

colors_list = [
    '#0072B2', '#009E73', '#D55E00', '#CC79A7', '#7f7f7f', '#FFB5B8', '#F0E442'
]

data_folder = '/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/teporingos/Grid_data_vital/'

for age in Grid_Values['age']:
    for mass in Grid_Values['clus_mass']:
        for zGas in Grid_Values['zGas']:
            for zStar in Grid_Values['zStars']:

                idx_color = Grid_Values['age'].index(age)

                name_root = 'TGrid' + '_Mass' + mass + '_age' + age + '_zStar' + zStar + '_zGas' + zGas
Exemple #45
0
from dazer_methods import Dazer
from collections import OrderedDict
from numpy import concatenate, unique, round, nan
from pandas import read_csv, isnull, notnull, DataFrame
from lib.CodeTools.sigfig import round_sig

lines_log_format_headers = ['Ions', 'lambda_theo', 'notation']
lines_log_format_address = '/home/vital/PycharmProjects/dazer/format/emlines_pyneb_optical_infrared.dz'
lines_df = read_csv(lines_log_format_address,
                    index_col=0,
                    names=lines_log_format_headers,
                    delim_whitespace=True)

# Generate dazer object
dz = Dazer()

# Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
norm_factor = 100

# Treatment add quick index
dz.quick_indexing(catalogue_df)

# Declare data for the analisis
AbundancesFileExtension = '_' + catalogue_dict[
    'Datatype'] + '_linesLog_reduc.txt'

# Reddening properties
    #Prepare PyNeb data for ratios characteristics
    pn.atomicData.setDataFile('s_iii_coll_HRS12.dat')
    O3 = pn.Atom('O', 3) 
    N2 = pn.Atom('N', 2)
    S3 = pn.Atom('S', 3)
    Atom_Dict = dict()
    Atom_Dict['O3_ratio'] = O3.getEmissivity(10000, 100, wave = 5007) / O3.getEmissivity(10000, 100, wave = 4959) 
    Atom_Dict['N2_ratio'] = N2.getEmissivity(10000, 100, wave = 6584) / N2.getEmissivity(10000, 100, wave = 6548)
    Atom_Dict['S3_ratio'] = S3.getEmissivity(10000, 100, wave = 9531) / S3.getEmissivity(10000, 100, wave = 9069)
   
    return Atom_Dict

#Declare objects

dz = Dazer()
 
#Define data type and location
Catalogue_Dic   = dz.import_catalogue()
Table_Name      = 'Catalogue_Full_Data' 
log_extension   = '_log.txt'
cHbeta_type     = 'cHBeta_red'
emission_log    = '_' + Catalogue_Dic['Datatype'] + '_emission_LinesLog_v3.txt'

#Load pyneb data
Atom_dict       = load_pyneb()

#Locate files on hard drive
FilesList       = dz.Folder_Explorer(log_extension, Catalogue_Dic['Obj_Folder'], CheckComputer=False)

#Load catalogue properties frame
from dazer_methods import Dazer

#Create class object
dz = Dazer()

#Set figure format
dz.FigConf()


extracted_files = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e.fits',
'/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e.fits']

flux_calibrated = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e_fglobal.fits',
'/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e_fglobal.fits']

# flux_calibrated = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e_fglobal.fits',
# '/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e_fglobal.fits']

flux_calibrated = [
                   '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Blue_fglobal.fits',
                   '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Blue_fglobal.fits',
                   '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Red_fglobal.fits',
                   '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Red_fglobal.fits',
                   ]

for i in range(len(flux_calibrated)):
    
#     color = 'Blue' if 'Blue' in extracted_files[i] else 'Red'
    
    
    CodeName, FileName, FileFolder  = dz.Analyze_Address(flux_calibrated[i])
'''
Created on Mar 15, 2017

@author: vital
'''

import numpy as np
from dazer_methods import Dazer

dz = Dazer()

#Set figure format
sizing_dict = {'figure.figsize': (8, 8)}
dz.FigConf(sizing_dict)

te_SIII = np.linspace(8000, 20000, 50)
te_SII = 0.88 * te_SIII + 1560
line_unity = te_SIII

dz.data_plot(te_SIII, te_SII, label=r'$T_e[SII]=0.88T_e[SIII]+1560$')
dz.data_plot(te_SIII, te_SIII, label='', color='grey', linestyle='--')

dz.Axis.set_xlim(8000, 20000)
dz.Axis.set_ylim(8000, 20000)
dz.Axis.grid(True)

ticklines = dz.Axis.get_xticklines() + dz.Axis.get_yticklines()
gridlines = dz.Axis.get_xgridlines() + dz.Axis.get_ygridlines()
ticklabels = dz.Axis.get_xticklabels() + dz.Axis.get_yticklabels()

for line in ticklines:
Exemple #49
0
    c_SI = 300000.0

    if O3_5007_sigma >= 0:
        Sigma = O3_5007_sigma / 5007.0 * c_SI

    elif Hbeta_sigma >= 0:
        Sigma = Hbeta_sigma / 4861.0 * c_SI

    else:
        Sigma = 100

    return Sigma


#Declare data to treat
dz = Dazer()
script_code = dz.get_script_code()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
AbundancesFileExtension = '_' + catalogue_dict[
    'Datatype'] + '_linesLog_reduc.txt'

#Define plot frame and colors
dz.FigConf()

#Default configuration file
dz.RootFolder = '/home/vital/'
Exemple #50
0
from dazer_methods import Dazer
from uncertainties import unumpy
from collections import OrderedDict

#Import library object
dz = Dazer()

#Load observational data
catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx')

#Define data to load
ext_data        = '_emis'
pdf_address     = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/data/HeliumAbund_table'

#Headers
headers_dic  = OrderedDict()
headers_dic['HeII_HII_from_S']  = r'$\big(\frac{He^{+}}{H^{+}}\big)_{S}$'
headers_dic['HeIII_HII_from_S'] = r'$\big(\frac{He^{+2}}{H^{+}}\big)_{S}$'
headers_dic['HeII_HII_from_O']  = r'$\big(\frac{He^{+}}{H^{+}}\big)_{O}$'
headers_dic['HeIII_HII_from_O'] = r'$\big(\frac{He^{+2}}{H^{+}}\big)_{O}$'
headers_dic['HeI_HI_from_O']    = r'$\big(\frac{He}{H}\big)_{O}$'
headers_dic['HeI_HI_from_S']    = r'$\big(\frac{He}{H}\big)_{S}$'
headers_dic['Ymass_O']          = r'$Y_{O}$'
headers_dic['Ymass_S']          = r'$Y_{S}$'

properties_list = map(( lambda x: x + ext_data), headers_dic.keys())
headers_format  = ['HII Galaxy', 'SDSS reference'] + headers_dic.values()

print 'Headers for table', headers_format
print 'Properties from df', properties_list
 
Exemple #51
0
#!/usr/bin/env python
import lineid_plot
from collections import OrderedDict
from dazer_methods import Dazer
from matplotlib import rcParams, pyplot as plt
from matplotlib._png        import read_png
from matplotlib.offsetbox   import OffsetImage, AnnotationBbox
from matplotlib.cbook import get_sample_data

#Declare code classes
dz = Dazer()

#Load catalogue dataframe
catalogue_dict          = dz.import_catalogue()
catalogue_df            = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx')
cHbeta_type             = 'cHbeta_reduc'
nebular_exten           = '_NebularContinuum.fits'
Stellar_ext             = '_StellarContinuum.fits'
emitting_ext            = '_Emission.fits'

#Treatment add quick index
dz.quick_indexing(catalogue_df)

#Define plot frame and colors
size_dict = {'figure.figsize':(12,5),'axes.labelsize':16, 'legend.fontsize':16, 'font.family':'Times New Roman', 'mathtext.default':'regular', 'xtick.labelsize':16, 'ytick.labelsize':16}
# dz.FigConf(plotSize = size_dict)

#Reddening properties
R_v = 3.4
red_curve = 'G03_average'
cHbeta_type = 'cHbeta_reduc'
Exemple #52
0
Created on Mar 13, 2017
 
@author: vital
'''
# from mpl_toolkits.mplot3d import Axes3D
from astropy.io import fits
from dazer_methods import Dazer
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cbook
from matplotlib import cm
from matplotlib.colors import LightSource
import matplotlib.pyplot as plt
import numpy as np

#Create class object
dz = Dazer()

#Plot configuration
dz.frames_colors = {'Blue arm': 'bone', 'Red arm': 'gist_heat'}

#Load the data
Spectra_address = '/home/vital/Astrodata/WHT_2011_11/Night1/objects/11_Blue_cr_f_t_w.fits'

#Open the image
with fits.open(Spectra_address) as hdu_list:
    image_data = hdu_list[0].data

xmin, xmax, ymin, ymax = 90, 120, 400, 800

y = np.arange(ymin, ymax)
x = np.arange(xmin, xmax)
from numpy import where
from uncertainties import ufloat
from dazer_methods import Dazer

#Declare objects
dz = Dazer()
 
#Define data type and location
Catalogue_Dic   = dz.import_catalogue()
Table_Name      = '_lineslog' 
log_extension   = '_log.txt'
cHbeta_type     = 'cHBeta_red'
emission_log    = '_' + Catalogue_Dic['Datatype'] + '_LinesLog_v3.txt'
# emission_log_st = '_' + Catalogue_Dic['Datatype'] + '_emission_LinesLog_v3.txt'

#Get file list
FilesList = dz.Folder_Explorer(emission_log, Catalogue_Dic['Obj_Folder'], CheckComputer=False)

#Get the dictionary with the headers format and the data
dz.EmissionLinesLog_header()
 
#Generate list of objects (Dazer should have a method for this)
for i in range(len(FilesList)):                 
     
    CodeName, FileName, FileFolder  = dz.Analyze_Address(FilesList[i])
     
    #load object data
    cHbeta                  = dz.GetParameter_ObjLog(CodeName, FileFolder, cHbeta_type, Assumption='float')     
    obj_lines_frame         = dz.load_object_frame(FileFolder, CodeName, emission_log, chbeta_coef = cHbeta_type)    
#     obj_lines_frame_star    = dz.load_object_frame(FileFolder, CodeName, emission_log_st, chbeta_coef = cHbeta_type)    
    Hbeta_Flux              = obj_lines_frame['line_Flux']['H1_4861A']
from numpy import where
from uncertainties import ufloat
from dazer_methods import Dazer

#Declare objects
dz = Dazer()

#Define data type and location
Catalogue_Dic = dz.import_catalogue()
Table_Name = '_lineslog'
log_extension = '_log.txt'
cHbeta_type = 'cHBeta_red'
emission_log = '_' + Catalogue_Dic['Datatype'] + '_LinesLog_v3.txt'
# emission_log_st = '_' + Catalogue_Dic['Datatype'] + '_emission_LinesLog_v3.txt'

#Get file list
FilesList = dz.Folder_Explorer(emission_log,
                               Catalogue_Dic['Obj_Folder'],
                               CheckComputer=False)

#Get the dictionary with the headers format and the data
dz.EmissionLinesLog_header()

#Generate list of objects (Dazer should have a method for this)
for i in range(len(FilesList)):

    CodeName, FileName, FileFolder = dz.Analyze_Address(FilesList[i])

    #load object data
    cHbeta = dz.GetParameter_ObjLog(CodeName,
                                    FileFolder,
import numpy as np
from collections import OrderedDict
from dazer_methods import Dazer
from lib.inferenceModel import SpectraSynthesizer
from lib.Astro_Libraries.spectrum_fitting.import_functions import make_folder

# Import functions
dz = Dazer()
specS = SpectraSynthesizer()

# Declare data location
root_folder = 'E:\\Dropbox\\Astrophysics\\Data\\WHT_observations\\bayesianModel\\'
whtSpreadSheet = 'E:\\Dropbox\\Astrophysics\\Data\\WHT_observations\\WHT_Galaxies_properties.xlsx'

# Import data
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(whtSpreadSheet)

default_lines = [
    'H1_4341A', 'H1_6563A', 'He1_4471A', 'He1_5876A', 'He1_6678A', 'He2_4686A',
    'O2_7319A', 'O2_7319A_b', 'O2_7330A', 'O3_4363A', 'O3_4959A', 'O3_5007A',
    'N2_6548A', 'N2_6584A', 'S2_6716A', 'S2_6731A', 'S3_6312A', 'S3_9069A',
    'S3_9531A', 'Ar3_7136A', 'Ar4_4740A'
]

# Quick indexing
dz.quick_indexing(catalogue_df)

# Sample objects
excludeObjects = [
    'SHOC579', 'SHOC575_n2', '11', 'SHOC588', 'SDSS3', 'SDSS1', 'SHOC36'
Exemple #56
0
import pandas as pd
from os import makedirs
from astropy.io import fits
from os.path import isdir
from dazer_methods import Dazer
from shutil import rmtree, copy
from collections import OrderedDict
from numpy import loadtxt

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)

dz = Dazer()

#Input and output locations
input_folders = OrderedDict()
input_folders['WHT_2016_10_n1'] = '/home/vital/Astrodata/WHT_2016_10/'

input_folders['WHT_2016_04_n1'] = '/home/vital/Astrodata/WHT_2016_04/Night1/'
input_folders['WHT_2016_04_n2'] = '/home/vital/Astrodata/WHT_2016_04/Night2/'

input_folders['WHT_2011_11_n1'] = '/home/vital/Astrodata/WHT_2011_11/Night1/'
input_folders['WHT_2011_11_n2'] = '/home/vital/Astrodata/WHT_2011_11/Night2/'

input_folders['WHT_2011_09_n1'] = '/home/vital/Astrodata/WHT_2011_09/Night1/'
input_folders['WHT_2011_09_n2'] = '/home/vital/Astrodata/WHT_2011_09/Night2/'

input_folders['WHT_2011_01_n2'] = '/home/vital/Astrodata/WHT_2011_01/Night2/'

input_folders['WHT_2009_07_n1'] = '/home/vital/Astrodata/WHT_2009_07/Night1/'
input_folders['WHT_2009_07_n2'] = '/home/vital/Astrodata/WHT_2009_07/Night2/'
from pandas import read_csv
from dazer_methods import Dazer
from timeit import default_timer as timer
from DZ_LineMesurer import LineMesurer_v2

#Define main class
dz = Dazer()
lm = LineMesurer_v2('/home/vital/workspace/dazer/format/',
                    'DZT_LineLog_Headers.dz')

#Making the plot:
dz.FigConf()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(
    '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
)
lickIndcs_extension = '_lick_indeces.txt'

#Declare object to treat
objName = 'SHOC575_n2'

#Load line regions
ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName)
lick_idcs_df = read_csv(ouput_folder + objName + lickIndcs_extension,
                        delim_whitespace=True,
                        header=0,
                        index_col=0,
                        comment='L')  #Dirty trick to avoid the Line_label row
    LineHeight = max(PartialIntensity[indmin:indmax])
    LineExpLoc = median(PartialWavelength[where(PartialIntensity == LineHeight)])

    return PartialWavelength, PartialIntensity, LineHeight, LineExpLoc


def region_indeces(wave_min, wave_max, wavenlength_range):

    low_trim, up_trim = searchsorted(wavenlength_range, [wave_min, wave_max])
    indeces_array = array(range(low_trim, up_trim))

    return indeces_array


dz = Dazer()
script_code = dz.get_script_code()
lickIndcs_extension = "_lick_indeces.txt"

# Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_dataframe(catalogue_dict["dataframe"])

SIII_theo = 2.469
H7_H8_ratio_theo = 1.98

# Set figure format
size_dict = {"figure.figsize": (16, 10), "axes.labelsize": 16, "legend.fontsize": 20}
dz.FigConf(plotStyle="seaborn-colorblind", plotSize=size_dict, Figtype="Grid_size", n_columns=1, n_rows=2)

# Sulfur lines to plot
import pandas as pd
import pyfits as pf
from astroquery.simbad import Simbad
from dazer_methods import Dazer

dz = Dazer()
Catalogue_Dic   = '/home/vital/Dropbox/Astrophysics/Telescope Time/Standard_Stars/Calspec_Spectra/'
Pattern         = '.fits'
FilesList       = dz.Folder_Explorer(Pattern,  Catalogue_Dic, CheckComputer=False)
 
#Generate plot frame and colors
dz.FigConf()
 
#Loop through files
for i in range(len(FilesList)):
        
    #Analyze file address
    CodeName, FileName, FileFolder          = dz.Analyze_Address(FilesList[i])
     
    #Import fits file
    fits_file   = pf.open(FilesList[i])
    Wave        = fits_file[1].data['WAVELENGTH']
    Int         = fits_file[1].data['FLUX']
     
    fits_file.close()
     
    dz.data_plot(Wave, Int, label=FileName.replace('_', ''))
     
dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Calspec library')         
dz.Axis.set_yscale('log')
dz.Axis.set_xlim(7000, 10000)
from dazer_methods import Dazer
from numpy import nanmean, nanstd
from uncertainties import ufloat

#Generate dazer object
dz = Dazer()
dz.load_elements()

#Load catalogue dataframe
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_dataframe(catalogue_dict['dataframe'])

#Declare data for the analisis
AbundancesFileExtension = '_' + catalogue_dict['Datatype'] + '_linesLog_reduc.txt'
cHbeta_type = 'cHbeta_reduc'
  
#Loop through objects:
for i in range(len(catalogue_df.index)):
    
    #print '-- Treating {} @ {}'.format(catalogue_df.iloc[i].name, AbundancesFileExtension), i + 1, '/', len(catalogue_df.index)
    
    #Locate the objects
    objName = catalogue_df.iloc[i].name
    ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) 
    lineslog_address = '{objfolder}{codeName}{lineslog_extension}'.format(objfolder = ouput_folder, codeName=objName, lineslog_extension=AbundancesFileExtension)
    
#     if objName == '8':
    
    #Load lines frame
    lineslog_frame = dz.load_lineslog_frame(lineslog_address)