import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('../../')
import pyterpol

# create the grid
sygri = pyterpol.SyntheticGrid(debug=True, mode='default')
parlis = sygri.select_parameters(order=4, **{'logg':3.9999999999999982, 'z':1.0, 'teff':16000.})
print parlis
parlis = sygri.deselect_exact(parlis,  **{'logg':3.9999999999999982, 'z':1.0, 'teff':16000.})
print parlis
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('../../')
import pyterpol

# create the grid
sygri = pyterpol.SyntheticGrid()

# read properties
sygri.read_list_from_file('b1.dat',
                          columns=['FILENAME', 'TEFF', 'LOGG', 'Z'],
                          family='BSTAR')
sygri.read_list_from_file('p1.dat',
                          columns=['FILENAME', 'TEFF', 'LOGG', 'Z'],
                          family='POLLUX')

# test of dealing with degeneracies - this should return two pectra
sl = sygri.get_all(z=1.0, teff=15000, logg=4.5)
#print sl

# resolve degeneracy - should raise an exception - checked
#sl = sygri.resolve_degeneracy(sl)

## so we set the grid order and now it should return one spectrum - checked
sygri.set_grid_order(['BSTAR', 'POLLUX'])
sl = sygri.resolve_degeneracy(sl)
#print sl['family']

# this should create a list with intensities of individual
# spectra that will be used for interpolation
Esempio n. 3
0
"""
This script serves a demonstration of the class SyntheticGrid.
"""
# import the library
import pyterpol
import matplotlib.pyplot as plt

# The handling of the synthetic grid is shadowed from the user,
# therefore the interaction of the user with the grid should
# restrict to only few methods.

# How to create a grid? Ups - we have forgotten, which modes are available.as
# So we create a default grid and have a look at the grids that are available
# In general user should use default grid, because it spans over all
# implemented grids
sg = pyterpol.SyntheticGrid()

# The method list_modes returns string, so it has to be printed
print sg.list_modes()

# Now we know the modes, so we can either create the grid again
sg = pyterpol.SyntheticGrid(mode='bstar')

# or just set mode for the existing one - BSTAR will be our
# exemplary grid.
sg.set_mode(mode='bstar')

# we set up a grid, so we can interpolate.
# synthetic spectra should be queried with
# the method get_synthetic_spectrum - lets do some calls
# Grid parameters have to be wrapped using
Esempio n. 4
0
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('../../')
import pyterpol
import time

# create the grid - custom does nothing
sygri = pyterpol.SyntheticGrid('POLLUX')

# try to load a spectrum
keys = ['Z', 'LOGG', 'TEFF']
vals = [1.0, 4.0, 13000]
wmin = 6400
wmax = 6600

# create a dictionary for future look up
specs= {}
for k, v in zip(keys, vals):
    specs[k] = v
    
# load the spectra
t0 = time.time()
print sygri.get_spectra_for_interpolation([vals], keys, wmin=wmin, wmax=wmax)
t1 = time.time()
print t1-t0

# load them again
t0 = time.time()
print sygri.get_spectra_for_interpolation([vals], keys, wmin=wmin, wmax=wmax)
t1 = time.time()
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('../../')
import pyterpol
import time

# create the grid - custom does nothing
sygri = pyterpol.SyntheticGrid('POLLUX', debug=True)

# interpolate at
wmin = 6500
wmax = 6650
keys = ['Z', 'LOGG', 'TEFF']
values = [1.0, 4.0, 12000]
params = {k: v for k, v in zip(keys, values)}
name = '_'.join([k + '_' + str(v) for k, v in zip(keys, values)])

plt.figure(figsize=(12, 5), dpi=100)
spectrum = sygri.get_synthetic_spectrum(params, wmin, wmax)
w, i = spectrum.get_spectrum()
plt.plot(w, i, 'k-')
plt.savefig(name + '.png')
plt.close()
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('../../')
import pyterpol
import time

# create the grid - custom does nothing
sygri = pyterpol.SyntheticGrid('BSTAR', debug=True)

# interpolate at
wmin = 6500
wmax = 6650
keys = ['Z', 'LOGG', 'TEFF']
values = [1.0, 3.8, 18400]
params = {k:v for k,v in zip(keys, values)}
name = '_'.join([k+'_'+str(v) for k,v in zip(keys, values)])

ords = np.arange(2,6)

for order in ords:
    spectrum = sygri.get_synthetic_spectrum(params, wmin, wmax, order=order)
    w,i = spectrum.get_spectrum()
    
    #plot the spectrum 
    plt.figure(figsize=(12,10), dpi=100)
    plt.plot(w, i, 'k-')
    plt.savefig(name+"_order_%s" % str(order)+'.png')
    plt.close()
    
    # save the spectrum in text file
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('../../')
import pyterpol

# create the grid - custom does nothing
sygri = pyterpol.SyntheticGrid()
print sygri

## create the grid - BSTAR does nothing
sygri = pyterpol.SyntheticGrid('BSTAR')
print sygri

## create the grid - OSTAR does nothing
sygri = pyterpol.SyntheticGrid('OSTAR')
print sygri

## create the grid - POLLUX does nothing
sygri = pyterpol.SyntheticGrid('POLLUX')
print sygri

## create the grid - POLLUX does nothing
sygri = pyterpol.SyntheticGrid('AMBRE')
print sygri

## create the grid - DEFAULT does nothing
sygri = pyterpol.SyntheticGrid('DEFAULT')
print sygri
Esempio n. 8
0
import pyterpol
import matplotlib.pyplot as plt

wmin = 3600
wmax = 4100
sygri = pyterpol.SyntheticGrid(flux_type='absolute')
params = dict(teff=9950, logg=3.7, z=1.0)
spec1 = sygri.get_synthetic_spectrum(params, [wmin, wmax], order=4, step=0.1)
params = dict(teff=10000, logg=3.5, z=1.0)
spec2 = sygri.get_synthetic_spectrum(params, [wmin, wmax], order=4, step=0.1)
params = dict(teff=10000, logg=4.0, z=1.0)
spec3 = sygri.get_synthetic_spectrum(params, [wmin, wmax], order=4, step=0.1)

ax = plt.subplot(111)
spec1.plot(ax=ax)
spec2.plot(ax=ax)
spec3.plot(ax=ax)
plt.show()