def arcturus_link(): arc_list =list() for file in os.listdir('Arcturus'): if 'ar' in file: arc_list.append(file) Arcturus = [] for line in arc_list: arcspecfile = ('Arcturus/{}'.format(line) ) ArcSpec = np.genfromtxt(arcspecfile,dtype=float) ArcSpec = np.array(ArcSpec,dtype=float) Arcturus.append(ArcSpec) Arc = np.vstack(Arcturus) Arc[:,1] = Arc[:,1][np.argsort(Arc[:,0])] Arc[:,2] = Arc[:,2][np.argsort(Arc[:,0])] Arc[:,3] = Arc[:,3][np.argsort(Arc[:,0])] Arc[:,0] = np.sort(Arc[:,0]) Arc[:,0] = pyasl.airtovac2(Arc[:,0]) np.savetxt('ArcturusSpectrum.txt',Arc) Arc = Arc[(Arc[:,1] > 0.) & (Arc[:,3] > 0.)] return Arc
def get_dispsol(wc_file, ap_max, show=False, col='b', is_wave_air=False, label=None): lines = open(wc_file, 'r').readlines() shift, offset, slope = 0, 0, 1 #default values in case absent in ec* file for i, l in enumerate(lines): if '\tslope\t' in l: slope = float(l.split()[1]) if '\toffset\t' in l: offset = float(l.split()[1]) if '\tshift\t' in l: shift = float(l.split()[1]) if '\tcoefficients\t' in l: start = i xpow = int(float(lines[start + 2].strip())) opow = int(float(lines[start + 3].strip())) xmin, xmax = float(lines[start + 5].strip()), float(lines[start + 6].strip()) omin, omax = float(lines[start + 7].strip()), float(lines[start + 8].strip()) c = np.reshape( [float(lines[start + 9 + i].strip()) for i in range(opow * xpow)], (opow, xpow)) ypix = np.arange(int(xmin), int(xmax) + 1) wlist = [] for ap in range(1, ap_max + 1): w = [] o = ap * slope + offset for x in ypix: w.append( (wc(x, o, xpow, opow, xmin, xmax, omin, omax, c) + shift) / o) if is_wave_air: w = p.airtovac2( w, mode='ciddor' ) #to convert to vacuum wavelengths if initially it is air wavelength if show: if ap > 1: label = None plt.plot(ypix, w, c=col, label=label) plt.axhline(w[-1], linestyle='dotted', c='k') # wlist.append(w) if show: plt.xlabel('y-pixel') plt.ylabel('Observed wavelength(A)') plt.title('Dispersion solution') plt.show(block=False) return np.array(wlist) #----------------------------------------------------------------
def load_linelist(linelist,directory=None): if directory == None: directory = '.' Linelist = np.genfromtxt('{}/{}'.format(directory,linelist), dtype=([('element','a2'), ('ion' ,'a2'), ('wavelength' ,'f8'), ('potential' ,'f8'), ('oscillator' ,'f8')]) ,skip_header = 1) Linelist['element'] = Linelist['element'][np.argsort(Linelist['wavelength'])] Linelist['ion'] = Linelist['ion'][np.argsort(Linelist['wavelength'])] Linelist['potential'] = Linelist['potential'][np.argsort(Linelist['wavelength'])] Linelist['oscillator'] = Linelist['oscillator'][np.argsort(Linelist['wavelength'])] Linelist['wavelength'] = np.sort(Linelist['wavelength']) Linelist['wavelength'] = pyasl.airtovac2(Linelist['wavelength']) return Linelist
def mask_lines_bank(Data): # The objects in the bank have a redshift of zero z_obj = 0 #These lines are in rest frame host_lines=np.array([ 6564.61 ,4862.69 ,3726.09 ,3729.88 ,5008.24 ,4960.30 ,6549.84 ,6585.23 ,6718.32 ,6732.71]) host_lines_air = (1+z_obj)*pyasl.airtovac2(host_lines) host_range_air = np.column_stack([host_lines_air,host_lines_air]) z_disp = 4e2/3e5 host_range_air[:,0]=host_range_air[:,0]*(1-z_disp) host_range_air[:,1]=host_range_air[:,1]*(1+z_disp) func=lambda x,y: (x<y[1])&(x>y[0]) cum_mask=np.array([True]*len(Data[:,0])) for i in range(len(host_lines_air)): mask=np.array(list(map(lambda x: ~func(x,host_range_air[i]),Data[:,0]))) cum_mask = cum_mask & mask Data_masked = Data[cum_mask] #plt.figure() #plt.plot(Data[:,0],Data[:,1],'r') #plt.plot(Data_masked[:,0],Data_masked[:,1],'.b') #plt.show() return Data_masked
Linelist = np.genfromtxt('SpecConvolve/NLTEin.txt', dtype=([('element' ,'a2'), ('ion' ,'a2'), ('wavelength' ,'f8'), ('potential' ,'f8'), ('oscillator' ,'f8')]) ,skip_header = 1) Linelist['element'] = Linelist['element'][np.argsort(Linelist['wavelength'])] Linelist['ion'] = Linelist['ion'][np.argsort(Linelist['wavelength'])] Linelist['potential'] = Linelist['potential'][np.argsort(Linelist['wavelength'])] Linelist['oscillator'] = Linelist['oscillator'][np.argsort(Linelist['wavelength'])] Linelist['wavelength'] = np.sort(Linelist['wavelength']) #print min(Linelist['wavelength']), max(Linelist['wavelength']) #### Converting wavelengths in air to wavelengths in vacuum. #### Linelist['wavelength'] = pyasl.airtovac2(Linelist['wavelength']) allelementslist = [] for l in range(0,len(Linelist)): if Linelist['element'][l] not in allelementslist: allelementslist.append(Linelist['element'][l]) print 'Elements to choose from:' print allelementslist while True: try: element = raw_input('Type an element to analyze, or type All for all elements: ') if element != 'All':
dtype=([('element', 'a2'), ('ion', 'a2'), ('wavelength', 'f8'), ('potential', 'f8'), ('oscillator', 'f8')]), skip_header=1) Linelist['element'] = Linelist['element'][np.argsort(Linelist['wavelength'])] Linelist['ion'] = Linelist['ion'][np.argsort(Linelist['wavelength'])] Linelist['potential'] = Linelist['potential'][np.argsort( Linelist['wavelength'])] Linelist['oscillator'] = Linelist['oscillator'][np.argsort( Linelist['wavelength'])] Linelist['wavelength'] = np.sort(Linelist['wavelength']) #print min(Linelist['wavelength']), max(Linelist['wavelength']) #### Converting wavelengths in air to wavelengths in vacuum. #### Linelist['wavelength'] = pyasl.airtovac2(Linelist['wavelength']) allelementslist = [] for l in range(0, len(Linelist)): if Linelist['element'][l] not in allelementslist: allelementslist.append(Linelist['element'][l]) print 'Elements to choose from:' print allelementslist while True: try: element = raw_input( 'Type an element to analyze, or type All for all elements: ') if element != 'All':
import matplotlib.pyplot as plt Data=np.genfromtxt('/home/idoi/Dropbox/superfit/ZTF20aawbzlo_20200527_P200_v2.ascii') z_obj=0.034 host_lines=np.array([ 6564.61 ,4862.69 ,3726.09 ,3729.88 ,5008.24 ,4960.30 ,6549.84 ,6585.23 ,6718.32 ,6732.71]) host_lines_air=(1+z_obj)*pyasl.airtovac2(host_lines) host_range_air=np.column_stack([host_lines_air,host_lines_air]) z_disp=4e2/3e5 host_range_air[:,0]=host_range_air[:,0]*(1-z_disp) host_range_air[:,1]=host_range_air[:,1]*(1+z_disp) func=lambda x,y: (x<y[1])&(x>y[0]) cum_mask=np.array([True]*len(Data[:,0])) for i in range(len(host_lines_air)): mask=np.array(list(map(lambda x: ~func(x,host_range_air[i]),Data[:,0]))) cum_mask=cum_mask & mask Data_masked = Data[cum_mask] np.savetxt('/home/idoi/Dropbox/superfit/ZTF20aawbzlo_20200527_P200_v2_host_line_masked.ascii',Data_masked)