import functions
import string
import sys

cython_dir = functions.read_param_file("CYTHON_DIR")
print cython_dir
sys.path.append(cython_dir)

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("spectype_numerical_functions", ["spectype_numerical_functions.pyx"])]
)
Example #2
0
def make_string_from_list(input_list):
    string_output = ""
    for i in range(len(input_list)):
        string_output = string_output + input_list[i] + ","
    return string_output

########################
### Start of program ###
########################

file_path = "/priv/mulga2/george/wifes/"
folders_to_search = ["02Jun2014/spectype/blue/"]

grating = functions.read_config_file("GRATING")
dichroic = functions.read_config_file("DICHROIC")
wave1 = functions.read_param_file(grating+"_"+dichroic+"_w1")
wave2 = functions.read_param_file(grating+"_"+dichroic+"_w2")

program_dir = os.getcwd() + "/" #Save the current working directory

### Remove existing files in the "smooth" directory
#os.system("rm -rf smooth_dir")
os.system("rm *smooth.fits")

### Create a folder of smooth images in program dir
os.system("mkdir smooth_dir")
os.system("rm smooth_dir/master_smooth.fits")
os.system("rm smooth_dir/smooth_*.fits")

### Go through the folders, identify and reduce each smooth image
smooth_files_list = []
Example #3
0
    #spectype_functions.plot_contour(object_name,teff_space,logg_space,probability,5000,0,4.0,0,program_dir)

    return probability

########################
### Start of program ###
########################

file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

### Read from param and config files
model_path_flux = functions.read_param_file("MODEL_PATH_FLUX")
model_path_norm = functions.read_param_file("MODEL_PATH_NORM")

### Find the region within which to flux normalise
flux_normalise_w1 = eval(functions.read_param_file("NORM_REGION_w1"))
flux_normalise_w2 = eval(functions.read_param_file("NORM_REGION_w2"))

### Find initial estimate of properties
hdulist = pyfits.open(file_path + file_name)
object_name = hdulist[0].header["OBJECT"]
hdulist.close()

print "Analysing ",object_name

hsmso_connect = functions.read_config_file("HSMSO_CONNECT")
hscand_connect = functions.read_config_file("HSCAND_CONNECT")
Example #4
0
########################

### Set file_path
file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

image_slices = functions.read_ascii(file_path_temp + "stellar_apertures.txt")

camera = functions.read_config_file("CAMERA")
grating = functions.read_config_file("GRATING")
dichroic = functions.read_config_file("DICHROIC")

spectrum_w1 = functions.read_param_file(grating+"_"+dichroic+"_w1")
spectrum_w2 = functions.read_param_file(grating+"_"+dichroic+"_w2")

sample_w1 = functions.read_param_file("FLUX_NORMALISE_w1")
sample_w2 = functions.read_param_file("FLUX_NORMALISE_w2")
sample_region = "a"+sample_w1+"-"+sample_w2

combine_apertures = functions.read_config_file("COMBINE_APERTURES")

program_dir = os.getcwd() + "/" #Save the current working directory
os.chdir(file_path_temp) #Change to ../temp/ dir

print "Combining spectra from multiple image slices into a single spectral object"

#####################################################################
### Check if the required spectra exists, and create combine list ###
Example #5
0
            sequence.append(input_list[len(input_list)-i][0])
            i = i+1
            n = n+1
        else:
            n = n
            i = i+1
    return sequence

########################
### Start of program ###
########################

### Read from config file
no_apertures = int(functions.read_config_file("NO_APERTURES"))
no_stars = int(functions.read_config_file("NO_STARS"))
se_path = functions.read_param_file("SE_PATH")
program_dir = os.getcwd()+"/"

### Set file_path
file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

interactive = functions.read_config_file("INTERACT")

image_slices_list = functions.read_ascii(file_path_temp + "slice_" + file_name+".txt")
image_slices_list = functions.read_table(image_slices_list)
image_slices_list = image_slices_list[1:]
Example #6
0
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

print "This script uses iraf.fxcor to generate a CCF for " +file_name + " using synthetic templates"

program_dir = os.getcwd() + "/" #Save the current working directory
### Load fxcor RV measurements
fxcor_stellar = functions.read_ascii(file_path_reduced + "fxcor_stellar.txt")
fxcor_stellar = functions.read_table(fxcor_stellar)

### Load grating / camera settings
grating = functions.read_config_file("GRATING")
dichroic = functions.read_config_file("RT560")

region_w1 = functions.read_param_file(grating+"_"+dichroic+"_w1")
region_w2 = functions.read_param_file(grating+"_"+dichroic+"_w2")

### Load location of library
synthetic_library = functions.read_param_file("RV_SPECTRAL_LIBRARY")

### Load RV fxcor region
stellar_region = functions.read_param_file("STELLAR_REGION")

### Determine best aperture
### by finding the flux ratios of apertures
### We use only the best aperture for generating the CCF
aperture_weights = list(find_flux_weights(file_name))

best_aperture = 1
for i in range(len(aperture_weights)):
Example #7
0
########################
### Start of program ###
########################

file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]
file_name_floor = string.split(file_name, "_")[-1]
fits = pyfits.open(file_path + file_name_floor)
candidate = fits[0].header["OBJECT"]

### Read in spectral regions for RV cc
stellar_region = functions.read_param_file("STELLAR_REGION")
print stellar_region
### Find out number of apertures used
if functions.read_config_file("COMBINE_APERTURES") == "false":
    no_apertures = int(functions.read_config_file("NO_APERTURES"))
else:
    no_apertures = 1

### Check if target is mdwarf
teff, logg = functions.estimate_teff_logg(file_path, file_name_floor, candidate, "true", "true", 5500, 4.5)

if teff < 3800:
    no_apertures = 3
    stellar_region = "*"
if teff > 7500:
    stellar_region = "a6450-6700"
Example #8
0
### Set file_path
file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

hdulist = pyfits.open(file_path + file_name)
object_mjd = hdulist[0].header['MJD-OBS']
hdulist.close()

camera = functions.read_config_file("CAMERA")
grating = functions.read_config_file("GRATING")
dichroic = functions.read_config_file("DICHROIC")

telluric_region = functions.read_param_file("TELLURIC_REGION")

### Copy telluric line spectra to working directory
telluric_fits = grating + "_telluric.fits"
os.system("cp -f telluric_fits/" + telluric_fits + " " + file_path_temp+"telluric.fits")

### Get slice numbers
image_slices = functions.read_ascii(file_path_temp + "stellar_apertures.txt")

### We want to change directory to ../temp/
### This is because of some stupid way autoidentify names database files
program_dir = os.getcwd() + "/" #Save the current working directory
os.chdir(file_path_temp) #Change to ../temp/ dir

##################
### Find shift ###
### Prepare for use in spectraltyping later

### Usage: python normalise_for_spectype.py file_path file_name

########################
### Start of program ###
########################

file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

### Read in param_files settings
norm_w1 = functions.read_param_file("NORM_REGION_w1")
norm_w2 = functions.read_param_file("NORM_REGION_w2")

program_dir = os.getcwd() + "/" #Save the current working directory

### Change directory to reduced/
os.chdir(file_path_temp) #Change to ../reduced/ dir

###########################
### Operate on spectrum ###
###########################

### Chop out section norm_w1 - norm_w2 (according to param_file)
### This avoids the balmer jump and all the Ca lines
### Which are hard to normalise
Example #10
0
if sys.argv[1] == "-o":
    object_name = sys.argv[2]

# if object_name[:4] == "HATS":
#     object_name_query = object_name[:11]
# else:
#     object_name_query = object_name

if ord(object_name[-1])-ord("A")>0 and ord(object_name[-1])-ord("A")<10:
    object_name_query = object_name[:-1]
else:
    object_name_query = object_name

print object_name_query

plots_folder = functions.read_param_file("RV_PLOTS_FOLDER")

### Extract rv points from HSMSO
query_entry = "select SPEChjd, SPECrv, SPECrv_err from SPEC where SPECtype=\"RV\" and SPECobject=\"%s\" " % object_name
RV_points = mysql_query.query_hsmso(query_entry)

print RV_points

if len(RV_points) > 0:
    cand_txt = open(plots_folder + object_name + ".txt","w")
    functions.write_table(RV_points,cand_txt)
    cand_txt.close()
else:
    print "ERROR entries not found for " + object_name

if len(RV_points) > 1:
Example #11
0
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

program_dir = os.getcwd() + "/" #Save the current working directory

### Load fxcor RV measurements
fxcor_stellar = functions.read_ascii(file_path_reduced + "fxcor_stellar.txt")
fxcor_stellar = functions.read_table(fxcor_stellar)

### Load grating / camera settings
grating = functions.read_config_file("GRATING")
dichroic = functions.read_config_file("DICHROIC")

region_w1 = functions.read_param_file(grating+"_"+dichroic+"_w1")
region_w2 = functions.read_param_file(grating+"_"+dichroic+"_w2")

########################
### Start of program ###
########################

### Find weights according flux of each aperture
aperture_weights = find_flux_weights(file_name)
print "weights for each aperture"
print aperture_weights

### Check if previous entries exist
### If so, delete them
if os.path.isfile(file_path_reduced + "RV_out.dat"):
    RV_out = functions.read_ascii(file_path_reduced + "RV_out.dat")
Example #12
0
### Set file_path
file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

hdulist = pyfits.open(file_path + file_name)
object_name = hdulist[0].header["OBJECT"]
hdulist.close()

print "This script applies bias subtraction to the image " + file_name

camera = functions.read_config_file("CAMERA")
if camera == "red":
    trimsec_value = functions.read_param_file("RED_TRIMSEC")
    biassec_value = functions.read_param_file("RED_BIASSEC")
    region1 = functions.read_param_file("RED_REGION1")
    region2 = functions.read_param_file("RED_REGION2")
    use_regions = functions.read_param_file("RED_USEREGIONS")
    reflect = functions.read_param_file("RED_REFLECT")

if camera == "blue":
    trimsec_value = functions.read_param_file("BLUE_TRIMSEC")
    biassec_value = functions.read_param_file("BLUE_BIASSEC")
    region1 = functions.read_param_file("BLUE_REGION1")
    region2 = functions.read_param_file("BLUE_REGION2")
    use_regions = functions.read_param_file("BLUE_USEREGIONS")
    reflect = functions.read_param_file("BLUE_REFLECT")

grating = functions.read_config_file("GRATING")
Example #13
0
        filtpars = "",\
        keywpars = "")

########################
### Start of program ###
########################
file_path = sys.argv[1]
file_path_temp = file_path + "temp/"
file_path_reduced = file_path + "reduced/"

file_name = sys.argv[2]

program_dir = os.getcwd() + "/" #Save the current working directory

### Read from param and config files
model_path_flux = functions.read_param_file("MODEL_PATH_FLUX")
model_path_norm = functions.read_param_file("MODEL_PATH_NORM")

### Find the region within which to flux normalise
flux_normalise_w1 = eval(functions.read_param_file("FLUX_NORMALISE_w1"))
flux_normalise_w2 = eval(functions.read_param_file("FLUX_NORMALISE_w2"))

### Find initial estimate of properties
hdulist = pyfits.open(file_path_reduced+"spec_"+file_name)
#hdulist = pyfits.open(file_path+file_name)
object_name = hdulist[0].header["OBJECT"]
ra = hdulist[0].header["RA"]
dec = hdulist[0].header["DEC"]
max_reddening = find_max_reddening(ra,dec)

print "Regional maximum reddening of E(B-V):",max_reddening
Example #14
0
import functions
import spectype_functions
import spectype_numerical_functions
import matplotlib.pyplot as plt
import pyfits

file_name = "b0064.fits"
file_path = "/mimsy/george/wifes/15Mar2012/spectype/blue/"

best_reddening = 0.04842
teff = 6000
logg = 4.5
feh = 0.0

### Read from param and config files
model_path_flux = functions.read_param_file("MODEL_PATH_FLUX")
model_path_norm = functions.read_param_file("MODEL_PATH_NORM")

##########################
### Plot FLUX spectrum ###
##########################

flux_spectrum = "deredden_"+str(best_reddening)+"_"+file_name+".dat"
flux_spectrum = functions.read_ascii(file_path + "reduced/deredden/" +flux_spectrum)
flux_spectrum = functions.read_table(flux_spectrum)
flux_spectrum = transpose(array(flux_spectrum))
flux_spectrum = spectype_functions.normalise(flux_spectrum,4400.,4600.)

flux_wave = flux_spectrum[0]
flux_flux = flux_spectrum[1]