Example #1
0
def smooth_spectrum( spectrum, smooth_factor ):
    
    # initialise the spectrum array with blank arrays
    len_specs = len(spectrum.spec[0]) - smooth_factor
    nspecs = len(spectrum.spec)

    dummy = np.array( [ np.arange(len_specs) for i in range(nspecs)] )


    smoothed_spectrum = cls.specclass ([],[],[],[],[],[], [], [], dummy) 
    
    # we don't want to smooth over frequency and wavelength, just shorten them!
    smoothed_spectrum.freq = spectrum.freq
    smoothed_spectrum.wavelength = spectrum.wavelength
    
    # now set the correct elements of the class to be the smoothed_arrays using smooth arrays function
    smoothed_spectrum.emitted = smooth_arrays (spectrum.emitted, smooth_factor)
    smoothed_spectrum.censrc = smooth_arrays (spectrum.censrc, smooth_factor)
    smoothed_spectrum.disk = smooth_arrays (spectrum.disk, smooth_factor)
    smoothed_spectrum.wind = smooth_arrays (spectrum.wind, smooth_factor)
    smoothed_spectrum.scattered = smooth_arrays (spectrum.scattered, smooth_factor)
    smoothed_spectrum.hitsurf = smooth_arrays (spectrum.hitsurf, smooth_factor)

    for i in range(nspecs):
        smoothed_spectrum.spec[i] = smooth_arrays (spectrum.spec[i], smooth_factor)
    
    return smoothed_spectrum
Example #2
0
def read_spec_file (filename, new=True):
    
    '''reads a Python .spec file and places in specclass array,
       which is returned'''
    
    if not '.spec' in filename: 
        filename = filename + '.spec'

    if new:
        add = 0
    else:
        add = 1
        
    
    # initialise the spectrum array with blank arrays
    spectrum = cls.specclass ([],[],[],[],[],[],[], [], [], []) 
    
    # first read the file into a temporary storage array
    spectrum_temp = np.loadtxt (filename, comments ='#', unpack=True)
    
    # now set the correct elements of the class to be the temporary array
    #spectrum.tot = spectrum_temp[0]
    spectrum.freq = spectrum_temp[0]
    spectrum.wavelength = spectrum_temp[1]

    if new:
        spectrum.created = spectrum_temp[2]

    spectrum.emitted = spectrum_temp[3-add]
    spectrum.censrc = spectrum_temp[4-add]
    spectrum.disk = spectrum_temp[5-add]
    spectrum.wind = spectrum_temp[6-add] 
    spectrum.scattered = spectrum_temp[8-add]
    spectrum.hitsurf = spectrum_temp[7-add]
    spectrum.spec = spectrum_temp[9-add:]
        
     #finally, return the spectrum class which is a series of named arrays      
    return spectrum