class needed_param():

	path = os.getcwd()



	#store the uvf, mod and fits files of the maps in a list
	files = []
	for filename in sorted(glob.glob(path+'/UVF/*.uvf*')):   
		files.append(filename)     #for the moment as well, you can also read the file with header = pf.getheader(uvffile) and then freq = header['CRVAL4'], all that would be easier in general as i dont need to depend of having a similar modification date in all of them ----> leads to changing the function order_by_nu
			
	models = []
	for filename in sorted(glob.glob(path+'/MODELS/*.mod*')):   
		models.append(filename)  #for the moment, in the modelfit file it is posible to read the frequency, which will simplify how to get it in general
		
	fits = []
	for filename in sorted(glob.glob(path+'/FITS/*.fits*')):   
		fits.append(filename)  

	modelfit = []
	for filename in sorted(glob.glob(path+'/modelfit/*.mod*')):   
		modelfit.append(filename)  #for the moment, in the modelfit file it is posible to read the frequency, which will simplify how to get it in general

	modelfit.sort(key=natural_keys)

	modelfiterror = []
	for filename in sorted(glob.glob(path+'/modelfit/*.dat*')):   
		modelfiterror.append(filename)  #for the moment, in the modelfit file it is posible to read the frequency, which will simplify how to get it in general

	modelfiterror.sort(key=natural_keys)

	coreshiftfile = []
	for filename in sorted(glob.glob(path+'/coreshiftmeas/*.meas*')):   
		coreshiftfile.append(filename)   #for the moment, in the modelfit file it is posible to read the frequency, which will simplify how to get it in general

					
	#initialize arrays
	cell = np.array([0.]*len(fits))
	bmaj = np.array([0.]*len(fits))
	bmin = np.array([0.]*len(fits))
	bpa = np.array([0.]*len(fits))
	freq = np.array([0.]*len(fits))
	beam = np.array([0.]*len(fits))
	size_map = np.array([0.]*len(fits))
	size_map_y =np.array([0.]*len(fits))

	#order the the list by frequency and 
	#getting the corresponding values of the previous initialized arrays ordered by frequency 
	#(lower to higher)
	ordered_params = order_by_nu(files,models,fits,False)
	
	freq = ordered_params[0]
	files = ordered_params[8]
	models = ordered_params[9]
	fits = ordered_params[10]
	
	#source name
	header = take_header(fits[0],False)
	source_name = header[8]
    def findingBEAM(self,checkBOXes,freq): #self.checks,freq ###stop_event,checkBOXes,freq 
	#self.myLongTask.start()

	self.fits_conv = []

	for filename in sorted(glob.glob(needed_param.path+'/CONV/*.fits*')):   
		self.fits_conv.append(filename)   
	files_temp = self.fits_conv
	models_temp = self.fits_conv


	###ORDER THEM BY FREQUENCY
	ordered_params_conv = order_by_nu(files_temp,files_temp,self.fits_conv)
	self.freq_conv = ordered_params_conv[0]
	self.beam_conv = ordered_params_conv[5]
	self.fits_conv = ordered_params_conv[10]

	finding_beam = beam_array(checkBOXes,freq,self.freq_conv,self.beam_conv)
	self.freq1_index,self.freq2_index,self.index_beam12 = finding_beam[0],finding_beam[1],finding_beam[2]
	self.beam1,self.beam2 = finding_beam[3],finding_beam[4]

	if len(self.index_beam12)== 1:
		track_freq1 = self.index_beam12[0][0]
		index_freq1 = self.freq1_index[0][track_freq1]
		self.fits1 = self.fits_conv[index_freq1]

		track_freq2 = self.index_beam12[0][1]-len(self.freq1_index[0])
		index_freq2 = self.freq2_index[0][track_freq2]
		self.fits2 = self.fits_conv[index_freq2]

		self.labelFITS1file.setText(self.fits1[len(needed_param.path):])
		self.labelFITS2file.setText(self.fits2[len(needed_param.path):])
			
		see_if_OK = check_map_params(str(self.fits1),str(self.fits2))
		OK = see_if_OK[0]

		if OK == True:
			self.labelFITS1file.setStyleSheet('QLabel {color: green } QLabel {font: Bold }')
			self.labelFITS2file.setStyleSheet('QLabel {color: green } QLabel {font: Bold }')
			self.labelOK.setText("Files OK")
			self.labelOK.setStyleSheet('QLabel {color: green } QLabel {font: Bold }')
		else:
			self.labelFITS1file.setStyleSheet('QLabel {color: red } QLabel {font: Bold }')
			self.labelFITS2file.setStyleSheet('QLabel {color: red } QLabel {font: Bold }')
			self.labelOK.setText("Convolve the files with the same beam,cell and mapsize")
			self.labelOK.setStyleSheet('QLabel {color: red } QLabel {font: Bold }')

	else:
		ShiftWindow.diff_beams = []

		for i in xrange(0,len(self.index_beam12)):
			ShiftWindow.diff_beams.append(self.beam1[self.index_beam12[i][0]])
	
		self.wi = popup_beams()
		self.wi.show()
		self.wi.selectButton.clicked.connect(lambda: self.getBEAM(self.wi.checks2, ShiftWindow.diff_beams,self.beam1,self.beam2,self.freq1_index,self.freq2_index,self.fits_conv))

	return popup_beams
예제 #3
0
class needed_param():

	path = os.getcwd()

	if not os.path.exists('Plot_fitted_synchrotron'):
		os.makedirs('Plot_fitted_synchrotron')
	if not os.path.exists('Plot_fitted_PL'):
		os.makedirs('Plot_fitted_PL')
	if not os.path.exists('Plot_fitted_synchrotronExtrapolated'):
		os.makedirs('Plot_fitted_synchrotronExtrapolated')


	#store the uvf, mod and fits files of the maps in a list
	files = []
	for filename in sorted(glob.glob(path+'/UVF/*.uvf*')):   
		files.append(filename)   
			
	models = []
	for filename in sorted(glob.glob(path+'/MODELS/*.mod*')):   
		models.append(filename)  
		
	fits = []
	for filename in sorted(glob.glob(path+'/FITS/*.fits*')):   
		fits.append(filename)  
					
	#initialize arrays
	cell = np.array([0.]*len(fits))
	bmaj = np.array([0.]*len(fits))
	bmin = np.array([0.]*len(fits))
	bpa = np.array([0.]*len(fits))
	freq = np.array([0.]*len(fits))
	beam = np.array([0.]*len(fits))
	size_map = np.array([0.]*len(fits))
	size_map_y =np.array([0.]*len(fits))

	#order the the list by frequency and 
	#getting the corresponding values of the previous initialized arrays ordered by frequency 
	#(lower to higher)
	ordered_params = order_by_nu(files,models,fits,False)
	
	freq = ordered_params[0]
	files = ordered_params[8]
	models = ordered_params[9]
	fits = ordered_params[10]
	
	#source name
	header = take_header(fits[0],False)
	source_name = header[8]
예제 #4
0
class needed_param():

    path = os.getcwd()

    #store the uvf, mod and fits files of the maps in a list
    files = []
    for filename in sorted(glob.glob(path + '/UVF/*.uvf*')):
        files.append(filename)

    models = []
    for filename in sorted(glob.glob(path + '/MODELS/*.mod*')):
        models.append(filename)

    fits = []
    for filename in sorted(glob.glob(path + '/FITS/*.fits*')):
        fits.append(filename)

    modelfit = []
    for filename in sorted(glob.glob(path + '/modelfit/*.mod*')):
        modelfit.append(filename)

    modelfit.sort(key=natural_keys)

    #initialize arrays
    cell = np.array([0.] * len(fits))
    bmaj = np.array([0.] * len(fits))
    bmin = np.array([0.] * len(fits))
    bpa = np.array([0.] * len(fits))
    freq = np.array([0.] * len(fits))
    beam = np.array([0.] * len(fits))
    size_map = np.array([0.] * len(fits))
    size_map_y = np.array([0.] * len(fits))

    #order the the list by frequency and
    #getting the corresponding values of the previous initialized arrays ordered by frequency
    #(lower to higher)
    ordered_params = order_by_nu(files, models, fits, False)

    freqOrig = ordered_params[0]
    beam = ordered_params[5]
    files = ordered_params[8]
    models = ordered_params[9]
    fits = ordered_params[10]

    freq = freqOrig.copy()
    units = []

    for i in xrange(0, len(freq)):
        if freq[i] < 0.5:
            freq[i] = freq[i] * 1000
            units.append('MHz')
        else:
            units.append('GHz')

    units = np.asarray(units)

    #source name
    header = take_header(fits[0], False)
    source_name = header[8]

    #reads the modelfit files and obtains the modelfit values and errors

    if len(modelfit) > 0:
        if os.path.isfile('pos_errors.dat'):
            errors = True
        else:
            errors = None

        mod_parameters = read_modfile(modelfit, beam, errors)
        """
		r, errr = radial distance and error of the component
		psi, errpsi = position angle and error of the component
		size, errsize =  size and error of the component
		"""
        r, errr = mod_parameters[0], mod_parameters[1]
        psi, errpsi = mod_parameters[2], mod_parameters[3]
        size, errsize = mod_parameters[4], mod_parameters[5]
        flux, errflux = mod_parameters[7], mod_parameters[8]

        #with the radial distance and position angle, the central positions of the components in RA and DEC are calculated
        """
		x, errx = position in RA and error of the component
		y, erry = position in DEC and error of the component
		"""
        x_and_y = x_y(r, errr, psi, errpsi, errors)
        x, errx = np.asarray(x_and_y[0]), np.asarray(x_and_y[1])
        y, erry = np.asarray(x_and_y[2]), np.asarray(x_and_y[3])

        #for plotting the components in the map
        """
		pts_arr = points for drawing the external countour of the ellipse, i.e., the ellipse itself

		x_el_arr = points for the x axis in the x direction of the ellipse. They are between (x_cent_component - size component) and (x_cent_component + size component).They are a total of 50
		y_elH_arr = points for the y axis in the x direction of the ellipse. It is a constant, so it is the same value 50 times, for using it with x_el_arr 

		y_el_arr = points for the y axis in the y direction of the ellipse. They are between (y_cent_component - size component) and (y_cent_component + size component). They are a total of 50
		x_elH_arr = points for the x axis in the y direction of the ellipse. It is a constant, so it is the same value 50 times, for using it with y_el_arr 

		"""
        pts_arr = []
        pt_arr = []
        x_el_arr = []
        x_elH_arr = []
        y_el_arr = []
        y_elH_arr = []

        ellipse_plot = ellipse_axis_lines(x, y, size)
        pts_arr, pt_arr = ellipse_plot[0], ellipse_plot[1]
        x_el_arr, y_el_arr = ellipse_plot[2], ellipse_plot[3]
        x_elH_arr, y_elH_arr = ellipse_plot[4], ellipse_plot[5]
class needed_files():

	path = os.getcwd()
	sourcepath = os.getcwd()

	if not os.path.exists('UVF'):
		os.makedirs('UVF')
	if not os.path.exists('MODELS'):
		os.makedirs('MODELS')
	if not os.path.exists('FITS'):
		os.makedirs('FITS')
	if not os.path.exists('CONV'):
		os.makedirs('CONV')
	if not os.path.exists('CONV_ALL'):
		os.makedirs('CONV_ALL')
	if not os.path.exists('SHIFT'):
		os.makedirs('SHIFT')
	if not os.path.exists('Shift_parameters'):
		os.makedirs('Shift_parameters')
	if not os.path.exists('SHIFT_ALL'):
		os.makedirs('SHIFT_ALL')
	if not os.path.exists('Plot_fitted'):
		os.makedirs('Plot_fitted')
	if not os.path.exists('SPIX_MAPS'):
		os.makedirs('SPIX_MAPS')
	if not os.path.exists('coreshiftmeas'):
		os.makedirs('coreshiftmeas')

	source = os.listdir(sourcepath)
	destinationpath_uvf = path+'/UVF/'
	destinationpath_models = path+'/MODELS/'
	destinationpath_fits = path+'/FITS/'

	for files in source:
		if files.endswith('.uvf'):
       			 shutil.move(os.path.join(sourcepath,files), os.path.join(destinationpath_uvf,files))
		if files.endswith('.mod'):
       			 shutil.move(os.path.join(sourcepath,files), os.path.join(destinationpath_models,files))
		if files.endswith('.fits'):
       			 shutil.move(os.path.join(sourcepath,files), os.path.join(destinationpath_fits,files))

	#store the uvf, mod and fits files of the maps in a list
	files = []
	for filename in sorted(glob.glob(path+'/UVF/*.uvf*')):   
		files.append(filename)   
			
	models = []
	for filename in sorted(glob.glob(path+'/MODELS/*.mod*')):   
		models.append(filename)  
		
	fits = []
	for filename in sorted(glob.glob(path+'/FITS/*.fits*')):   
		fits.append(filename)  
					
	#initialize arrays
	cell = np.array([0.]*len(fits))
	bmaj = np.array([0.]*len(fits))
	bmin = np.array([0.]*len(fits))
	bpa = np.array([0.]*len(fits))
	freq = np.array([0.]*len(fits))
	beam = np.array([0.]*len(fits))
	size_map = np.array([0.]*len(fits))
	size_map_y =np.array([0.]*len(fits))

	#order the the list by frequency and 
	#getting the corresponding values of the previous initialized arrays ordered by frequency 
	#(lower to higher)
	ordered_params = order_by_nu(files,models,fits,False)
	
	freqOrig = ordered_params[0]
	cell = ordered_params[1]
	bmaj = ordered_params[2]
	bmin = ordered_params[3]
	bpa = ordered_params[4]
	beam = ordered_params[5]
	size_map = ordered_params[6]
	size_map_y = ordered_params[7]
	files = ordered_params[8]
	models = ordered_params[9]
	fits = ordered_params[10]

	freq = freqOrig.copy()

	units = []

	for i in xrange(0,len(freq)):
		if freq[i] < 0.5:
			freq[i] = freq[i]*1000
			units.append('MHz')
		else:
			units.append('GHz')
	
	units = np.asarray(units)

	#source name
	header = take_header(fits[0],False)
	source_name = header[8]
	
	xshift = 0
	yshift = 0