Exemple #1
0
sync_data_slow = sync_fits_slow[0].data
sync_data_fast = sync_fits_fast[0].data

# Print a message to the screen to show that the data has been loaded
print 'Synchrotron intensities loaded successfully'

# Loop over the gamma values, to calculate the quadrupole ratio for each gamma
# value, for the different MHD modes and the full turbulence.
for j in range(len(gamma_arr)):
	# Calculate the 2D structure function for this slice of the synchrotron
	# intensity data cube. Note that no_fluct = True is set, because we are
	# not subtracting the mean from the synchrotron maps before calculating
	# the structure function. We are also calculating the normalised 
	# structure function, which only takes values between 0 and 2.
	# This is done for all MHD modes, and the full turbulence
	norm_strfn_full = sf_fft(sync_data_full[2*j], no_fluct = True, normalise = True)
	norm_strfn_alf = sf_fft(sync_data_alf[2*j], no_fluct = True, normalise = True)
	norm_strfn_slow = sf_fft(sync_data_slow[2*j], no_fluct = True, normalise = True)
	norm_strfn_fast = sf_fft(sync_data_fast[2*j], no_fluct = True, normalise = True)

	# Shift the 2D structure function so that the zero radial separation
	# entry is in the centre of the image. Do this for all MHD modes, and the
	# full turbulence
	norm_strfn_full = np.fft.fftshift(norm_strfn_full)
	norm_strfn_alf = np.fft.fftshift(norm_strfn_alf)
	norm_strfn_slow = np.fft.fftshift(norm_strfn_slow)
	norm_strfn_fast = np.fft.fftshift(norm_strfn_fast)

	# Calculate the magnitude and argument of the quadrupole ratio, for all
	# MHD modes, and for the full turbulence
	quad_mod_full, quad_arg_full, quad_rad_full = calc_quad_ratio(norm_strfn_full, num_bins)
	# free parameter related to the observational effect being studied. Each
	# row corresponds to a value of the free parameter, and each column 
	# corresponds to a radial value. There is one array for a line of sight 
	# along the z axis, and another for a line of sight along the x axis.
	rad_z_arr = np.zeros((len(iter_array),num_bins))
	rad_x_arr = np.zeros((len(iter_array),num_bins))

	# Loop over the various values of the free parameter related to the 
	# observational effect being studied, to calculate the structure function
	# for the synchrotron map observed for each value of the free parameter
	for i in range(len(iter_array)):
		# Calculate the structure function (two-dimensional) of the synchrotron
		# intensity maps, for the lines of sight along the x and z axes. Note 
		# that no_fluct = True is set, because we are not subtracting the mean
		# from the synchrotron maps before calculating the structure function.
		strfn_z = sf_fft(sync_data_z[i], no_fluct = True)
		strfn_x = sf_fft(sync_data_x[i], no_fluct = True)

		# Radially average the calculated 2D structure function, using the 
		# specified number of bins, for lines of sight along the x and z axes.
		rad_sf_z = sfr(strfn_z, num_bins, verbose = False)
		rad_sf_x = sfr(strfn_x, num_bins, verbose = False)

		# Extract the calculated radially averaged structure function for lines
		# of sight along the x and z axes.
		sf_z = rad_sf_z[1]
		sf_x = rad_sf_x[1]

		# Extract the radius values used to calculate this structure function,
		# for lines of sight along the x and z axes.
		sf_rad_arr_z = rad_sf_z[0]
		# store the result in the corresponding array
		stdev_arr[i,j] = np.std(flat_sync, dtype=np.float64)

		# Calculate the biased skewness of the synchrotron intensity map, and store
		# the result in the corresponding array
		skew_arr[i,j] = stats.skew(flat_sync)

		# Calculate the biased Fisher kurtosis of the synchrotron intensity 
		# map, and store the result in the corresponding array
		kurt_arr[i,j] = stats.kurtosis(flat_sync)

		# Calculate the structure function (two-dimensional) of the synchrotron
		# intensity map. Note that no_fluct = True is set, because we are not 
		# subtracting the mean from the synchrotron maps before calculating the
		# structure function.
		strfn = sf_fft(np.log10(sync_data/np.mean(sync_data,dtype=np.float64)), no_fluct = True)

		# Radially average the calculated 2D structure function, using the 
		# specified number of bins.
		rad_sf = sfr(strfn, num_bins, verbose = False)

		# Extract the calculated radially averaged structure function
		sf_arr[i,j] = rad_sf[1]

		# Extract the radius values used to calculate this structure function
		sf_rad_arr[i,j] = rad_sf[0]

		# Calculate the spectral index of the structure function calculated for
		# this value of gamma.
		spec_ind_data = np.polyfit(np.log10(\
			sf_rad_arr[i,j,5:14]),\
Exemple #4
0
	# Print a message to the screen to show that the synchrotron data has been 
	# loaded successfully
	print 'Simulated synchrotron data loaded'

	# Calculate the shape of the synchrotron data cube
	sync_shape = np.shape(sync_data)

	# Print the shape of the synchrotron data matrix, as a check
	print 'The shape of the synchrotron data matrix is: {}'.\
	format(sync_shape)

	# Calculate the 2D structure function for the relevant slice of the 
	# synchrotron intensity data cube, i.e. the value of gamma we are interested
	# in. Note that no_fluct = True is set, because we are not subtracting the 
	# mean from the synchrotron maps before calculating the structure function
	strfn = sf_fft(sync_data[gamma_index], no_fluct = True)

	# Radially average the calculated 2D structure function, using the 
	# specified number of bins
	rad_sf = sfr(strfn, num_bins)

	# Insert the calculated radially averaged structure function
	# into the matrix that stores all of the calculated structure functions
	sf_mat[rot_index] = rad_sf[1]

	# Insert the radius values used to calculate this structure function
	# into the matrix that stores the radius values
	rad_arr[rot_index] = rad_sf[0]

	# Print a message to show that the structure function has been calculated
	print 'Radially averaged structure function calculated for'\
Exemple #5
0
            sync_map_free_param_low_z = convolve_fft(sync_map_low_f_z,
                                                     gauss_kernel,
                                                     boundary='wrap')
            sync_map_free_param_high_z = convolve_fft(sync_map_high_f_z,
                                                      gauss_kernel,
                                                      boundary='wrap')

            # Replace the array of standard deviations with the array of final
            # resolutions, so that the final resolutions are used in all plots
            iter_array[j] = final_res[j]

        # Calculate the structure function (two-dimensional) of the synchrotron
        # intensity maps, for the low and high magnetic field simulations. Note
        # that no_fluct = True is set, because we are not subtracting the mean
        # from the synchrotron maps before calculating the structure function.
        strfn_low_y = sf_fft(sync_map_free_param_low_y, no_fluct=True)
        strfn_high_y = sf_fft(sync_map_free_param_high_y, no_fluct=True)
        # For z LOS
        strfn_low_z = sf_fft(sync_map_free_param_low_z, no_fluct=True)
        strfn_high_z = sf_fft(sync_map_free_param_high_z, no_fluct=True)

        # Radially average the calculated 2D structure function, using the
        # specified number of bins, for low and high magnetic field simulations.
        rad_sf_low_y = sfr(strfn_low_y, num_bins, verbose=False)
        rad_sf_high_y = sfr(strfn_high_y, num_bins, verbose=False)
        # For z LOS
        rad_sf_low_z = sfr(strfn_low_z, num_bins, verbose=False)
        rad_sf_high_z = sfr(strfn_high_z, num_bins, verbose=False)

        # Extract the calculated radially averaged structure function for low
        # and high magnetic field simulations
Exemple #6
0
        sync_fits_x = fits.open(data_loc + 'synint_p1-4x.fits')
        sync_fits_z = fits.open(data_loc + 'synint_p1-4.fits')

        # Extract the data for the simulated synchrotron intensities
        # This is a 3D data cube, where the slices along the third axis are the
        # synchrotron intensities observed for different values of gamma, the power law
        # index of the cosmic ray electrons emitting the synchrotron emission.
        sync_data_x = sync_fits_x[0].data
        sync_data_z = sync_fits_z[0].data

        # Calculate the 2D structure function for this slice of the synchrotron
        # intensity data cube. Note that no_fluct = True is set, because we are
        # not subtracting the mean from the synchrotron maps before calculating
        # the structure function. We are also calculating the normalised structure
        # function, which only takes values between 0 and 2.
        strfn_x = sf_fft(sync_data_x[gam_index], no_fluct=True, normalise=True)
        strfn_z = sf_fft(sync_data_z[gam_index], no_fluct=True, normalise=True)

        # Shift the 2D structure functions so that the zero radial separation
        # entry is in the centre of the image.
        strfn_x = np.fft.fftshift(strfn_x)
        strfn_z = np.fft.fftshift(strfn_z)

        # Calculate the magnitude, argument and radius values of the quadrupole
        # ratio for this simulation, for lines of sight along the x and z axes
        quad_mag_x[sim_index], quad_arg_x[sim_index], rad_arr_x[sim_index] =\
         calc_quad_ratio(strfn_x, num_bins)
        quad_mag_z[sim_index], quad_arg_z[sim_index], rad_arr_z[sim_index] =\
         calc_quad_ratio(strfn_z, num_bins)

        # Print a message to show that the quadrupole ratio has been calculated
def calc_err_bootstrap(sync_map_y, sync_map_z):
	'''
	Description
        This function divides the given images into quarters, and then 
        calculates statistics for each quarter. The standard deviation of the 
        calculated statistics is then returned, representing the error on 
        each statistic.
        
    Required Input
        sync_map_y - The synchrotron intensity map observed for a line of sight
        			 along the y axis.
        sync_map_z - The synchrotron intensity map observed for a line of sight 
        			 along the z axis. Must have the same size as the map 
        			 for a line of sight along the y axis.
                   
    Output
        skew_err - The error calculated for the skewness of synchrotron 
        		   intensity
        kurt_err - The error calculated for the kurtosis of synchrotron 
        		   intensity
        m_err - The error calculated for the structure function slope of the 
        		synchrotron intensity
		residual_err - The error calculated for the residual of the linear fit 
					   to the structure function of synchrotron intensity
		int_quad_err - The error calculated for the integrated quadrupole ratio
					   modulus of the synchrotron intensity
		quad_point_err - The error calculated for the value of the quadrupole 
						 ratio modulus at a point of synchrotron intensity
	'''

	# Create an array that will hold the quarters of the synchrotron images
	quarter_arr = np.zeros((8,np.shape(sync_map_y)[0]/2,np.shape(sync_map_y)[1]/2))

	# Add the quarters of the images into the array
	quarter_arr[0], quarter_arr[1] = np.split(np.split(sync_map_y,2,axis=0)[0],2,axis=1) 
	quarter_arr[2], quarter_arr[3] = np.split(np.split(sync_map_y,2,axis=0)[1],2,axis=1) 
	quarter_arr[4], quarter_arr[5] = np.split(np.split(sync_map_z,2,axis=0)[0],2,axis=1)
	quarter_arr[6], quarter_arr[7] = np.split(np.split(sync_map_z,2,axis=0)[1],2,axis=1)

	# Create arrays that will hold the calculated statistics for each quarter
	skew_val = np.zeros(np.shape(quarter_arr)[0])
	kurt_val = np.zeros(np.shape(quarter_arr)[0])
	m_val = np.zeros(np.shape(quarter_arr)[0])
	resid_val = np.zeros(np.shape(quarter_arr)[0])
	int_quad_val = np.zeros(np.shape(quarter_arr)[0])

	# Loop over the quarters, to calculate statistics for each one
	for i in range(np.shape(quarter_arr)[0]):
		# Extract the current image quarter from the array
		image = quarter_arr[i]

		# Flatten the image, so that we can calculate the skewness and kurtosis
		flat_image = image.flatten()

		# Calculate the biased skewness of the synchrotron intensity map
		skew_val[i] = stats.skew(flat_image)

		# Calculate the biased Fisher kurtosis of the synchrotron intensity 
		# maps
		kurt_val[i] = stats.kurtosis(flat_image)

		# Calculate the structure function (two-dimensional) of the synchrotron
		# intensity map. Note that no_fluct = True is set, because we are not 
		# subtracting the mean from the synchrotron maps before calculating the 
		# structure function.
		strfn = sf_fft(image, no_fluct = True)

		# Radially average the calculated 2D structure function, using the 
		# specified number of bins.
		rad_sf = sfr(strfn, num_bins, verbose = False)

		# Extract the calculated radially averaged structure function
		sf = rad_sf[1]

		# Extract the radius values used to calculate this structure function.
		sf_rad_arr = rad_sf[0]

		# Calculate the spectral index of the structure function calculated for
		# this value of gamma. Note that only the first third of the structure
		# function is used in the calculation, as this is the part that is 
		# close to a straight line. 
		spec_ind_data = np.polyfit(np.log10(\
			sf_rad_arr[11:16]),\
			np.log10(sf[11:16]), 1, full = True)

		# Extract the returned coefficients from the polynomial fit
		coeff = spec_ind_data[0]

		# Extract the sum of the residuals from the polynomial fit
		resid_val[i] = spec_ind_data[1]

		# Enter the value of m, the slope of the structure function minus 1,
		# into the corresponding array
		m_val[i] = coeff[0]-1.0

		# Calculate the 2D structure function for this slice of the synchrotron
		# intensity data cube. Note that no_fluct = True is set, because we are
		# not subtracting the mean from the synchrotron maps before calculating
		# the structure function. We are also calculating the normalised 
		# structure function, which only takes values between 0 and 2.
		norm_strfn = sf_fft(image, no_fluct = True, normalise = True)

		# Shift the 2D structure function so that the zero radial separation
		# entry is in the centre of the image.
		norm_strfn = np.fft.fftshift(norm_strfn)

		# Calculate the magnitude and argument of the quadrupole ratio
		quad_mod, quad_arg, quad_rad = calc_quad_ratio(norm_strfn, num_bins)

		# Integrate the magnitude of the quadrupole / monopole ratio from 
		# one sixth of the way along the radial separation bins, until three 
		# quarters of the way along the radial separation bins. This integration
		# is performed with respect to log separation (i.e. I am ignoring the 
		# fact that the points are equally separated in log space, to calculate 
		# the area under the quadrupole / monopole ratio plot when the x axis 
		# is scaled logarithmically). I normalise the value that is returned by 
		# dividing by the number of increments in log radial separation used in 
		# the calculation.
		int_quad_val[i] = np.trapz(quad_mod[11:20], dx = 1.0)\
		 / (19 - 11)

	# At this point, the statistics have been calculated for each quarter
	# The next step is to calculate the standard error of the mean of each
	# statistic
	skew_err = np.std(skew_val) / np.sqrt(len(skew_val))
	kurt_err = np.std(kurt_val) / np.sqrt(len(kurt_val))
	m_err = np.std(m_val) / np.sqrt(len(m_val))
	residual_err = np.std(resid_val) / np.sqrt(len(resid_val))
	int_quad_err = np.std(int_quad_val) / np.sqrt(len(int_quad_val))

	# Now that all of the calculations have been performed, return the 
	# calculated errors
	return skew_err, kurt_err, m_err, residual_err, int_quad_err
Exemple #8
0
#**********************************************************************

# Here we will calculate the structure functions and correlation functions
# of the fractal cube data using fast fourier transforms.

# Print a message to the screen to inform the user what is happening
print 'Tutorial: Computing structure functions and correlation functions'\
+ ' with FFT and inverse FFT'

# (You can find the routines to do this directly in configuration space
# in sfunc*.pro, you can figure out the differences)

# Calculate the structure function (SF) of int1, the 2D image found by
# integrating rho1 along the z direction
sf_int1_2D = sf_fft(int1)
# Calculate the correlation function (CF) of int1
cf_int1_2D = cf_fft(int1)

# Calculate the structure function (SF) of int2, the 2D image found by
# integrating rho2 along the z direction
sf_int2_2D = sf_fft(int2)
# Calculate the correlation function (CF) of int2
cf_int2_2D = cf_fft(int2)

# Print the shape of the returned structure function for int1, to demonstrate
# what is returned by the structure and correlation functions
print 'Tutorial: The shape of the structure function for int1 is = {}'\
.format(np.shape(sf_int1_2D))

# Create an image of the 2D correlation function for int1
		sync_fits_x = fits.open(data_loc + 'synint_p1-4x.fits')
		sync_fits_z = fits.open(data_loc + 'synint_p1-4.fits')

		# Extract the data for the simulated synchrotron intensities
		# This is a 3D data cube, where the slices along the third axis are the
		# synchrotron intensities observed for different values of gamma, the power law 
		# index of the cosmic ray electrons emitting the synchrotron emission.
		sync_data_x = sync_fits_x[0].data
		sync_data_z = sync_fits_z[0].data

		# Calculate the 2D structure function for this slice of the synchrotron
		# intensity data cube. Note that no_fluct = True is set, because we are
		# not subtracting the mean from the synchrotron maps before calculating
		# the structure function. We are also calculating the normalised structure
		# function, which only takes values between 0 and 2.
		strfn_x = sf_fft(sync_data_x[gam_index], no_fluct = True, normalise = True)
		strfn_z = sf_fft(sync_data_z[gam_index], no_fluct = True, normalise = True)

		# Shift the 2D structure functions so that the zero radial separation
		# entry is in the centre of the image.
		strfn_x = np.fft.fftshift(strfn_x)
		strfn_z = np.fft.fftshift(strfn_z)

		# Calculate the magnitude, argument and radius values of the quadrupole
		# ratio for this simulation, for lines of sight along the x and z axes
		quad_mag_x[sim_index], quad_arg_x[sim_index], rad_arr_x[sim_index] =\
		 calc_quad_ratio(strfn_x, num_bins)
		quad_mag_z[sim_index], quad_arg_z[sim_index], rad_arr_z[sim_index] =\
		 calc_quad_ratio(strfn_z, num_bins)

		# Print a message to show that the quadrupole ratio has been calculated
Exemple #10
0
# of the magnetic field
y_rad_av_corr = sfr(y_corr, num_bins)

# Calculate the normalised radially averaged correlation function for the
# y-component of the magnetic field. This is the left hand side of equation 14
# of Lazarian and Pogosyan 2012.
c_2 = y_rad_av_corr[1] / mag_y_mean_sq

# Print a message to show that c_2 has been calculated
print 'Normalised correlation function for the y-component of the magnetic'\
+ ' has been calculated'

# --------------- Structure function x-comp B field ---------------------------

# Calculate the structure function for the x-component of the magnetic field
x_sf = sf_fft(mag_x_data, no_fluct=True)

# Print a message to show that the structure function of the x-component of
# the magnetic field has been calculated
print 'Structure function of the x-component of the magnetic field calculated'

# Calculate the radially averaged structure function for the x-component
# of the magnetic field
x_rad_av_sf = sfr(x_sf, num_bins)

# Calculate the right hand side of equation 13 of Lazarian and Pogosyan 2012
# NOTE: The equation as specified in the paper is wrong. The structure function
# needs to be divided by the average of the x-component of the magnetic field
# squared.
RHS_13 = 1.0 - 0.5 * x_rad_av_sf[1] / mag_x_mean_sq
Exemple #11
0
        stdev_arr[i, j] = np.std(flat_sync, dtype=np.float64)

        # Calculate the biased skewness of the synchrotron intensity map, and store
        # the result in the corresponding array
        skew_arr[i, j] = stats.skew(flat_sync)

        # Calculate the biased Fisher kurtosis of the synchrotron intensity
        # map, and store the result in the corresponding array
        kurt_arr[i, j] = stats.kurtosis(flat_sync)

        # Calculate the structure function (two-dimensional) of the synchrotron
        # intensity map. Note that no_fluct = True is set, because we are not
        # subtracting the mean from the synchrotron maps before calculating the
        # structure function.
        strfn = sf_fft(np.log10(sync_data /
                                np.mean(sync_data, dtype=np.float64)),
                       no_fluct=True)

        # Radially average the calculated 2D structure function, using the
        # specified number of bins.
        rad_sf = sfr(strfn, num_bins, verbose=False)

        # Extract the calculated radially averaged structure function
        sf_arr[i, j] = rad_sf[1]

        # Extract the radius values used to calculate this structure function
        sf_rad_arr[i, j] = rad_sf[0]

        # Calculate the spectral index of the structure function calculated for
        # this value of gamma.
        spec_ind_data = np.polyfit(np.log10(\
Exemple #12
0
#**********************************************************************

# Here we will calculate the structure functions and correlation functions
# of the fractal cube data using fast fourier transforms.

# Print a message to the screen to inform the user what is happening
print 'Tutorial: Computing structure functions and correlation functions'\
+ ' with FFT and inverse FFT'

# (You can find the routines to do this directly in configuration space
# in sfunc*.pro, you can figure out the differences)

# Calculate the structure function (SF) of int1, the 2D image found by 
# integrating rho1 along the z direction
sf_int1_2D = sf_fft(int1)
# Calculate the correlation function (CF) of int1
cf_int1_2D = cf_fft(int1)

# Calculate the structure function (SF) of int2, the 2D image found by 
# integrating rho2 along the z direction
sf_int2_2D = sf_fft(int2)
# Calculate the correlation function (CF) of int2
cf_int2_2D = cf_fft(int2)

# Print the shape of the returned structure function for int1, to demonstrate
# what is returned by the structure and correlation functions
print 'Tutorial: The shape of the structure function for int1 is = {}'\
.format(np.shape(sf_int1_2D))

# Create an image of the 2D correlation function for int1
quad_arg_arr = np.zeros((sync_shape[0], num_bins))

# Create an array of zeroes, which will hold the radius values used to calculate
# the quadrupole for each structure function. This array has one row for each 
# gamma value, and a column for each radius value used in the calculation.
quad_rad_arr = np.zeros((sync_shape[0], num_bins))

# Loop over the third axis of the data cube, to calculate the normalised 
# structure function for each map of synchrotron emission
for i in range(sync_shape[0]):
	# Calculate the 2D structure function for this slice of the synchrotron
	# intensity data cube. Note that no_fluct = True is set, because we are
	# not subtracting the mean from the synchrotron maps before calculating
	# the structure function. We are also calculating the normalised structure
	# function, which only takes values between 0 and 2.
	strfn = sf_fft(sync_data[i], no_fluct = True, normalise = True)

	# Store the normalised structure function in the array of structure function
	# This has been shifted so that the zero radial separation entry is in 
	# the centre of the image.
	sf_mat[i] = np.fft.fftshift(strfn)

	# Calculate the magnitude and argument of the quadrupole ratio for the 
	# normalised structure function
	quad_mag_arr[i], quad_arg_arr[i], quad_rad_arr[i] = calc_quad_ratio(\
		sf_mat[i], num_bins = num_bins)

	# Print a message to show that the multipoles have been calculated
	print 'Multipoles calculated for gamma = {}'.format(gamma_arr[i])

# Now that the quadrupole ratios have been calculated, start plotting the 
Exemple #14
0
def calc_err_bootstrap(sync_map, first_index, end_index):
    '''
	Description
        This function divides the given images into quarters, and then 
        calculates statistics for each quarter. The standard deviation of the 
        calculated statistics is then returned, representing the error on 
        each statistic.
        
    Required Input
        sync_map - The synchrotron intensity map. Should be a 2D Numpy array.
        first_index - A variable to hold the first index to be used to calculate
        			  the standard deviation of the first derivative of the 
        			  quadrupole ratio
        end_index - A variable to hold the final index to be used to calculate
        			the standard deviation of the first derivative of the 
        			quadrupole ratio
                   
    Output
		quad_deriv_std_err - The error calculated for the standard deviation of
							 the first derivative of the quadrupole ratio
					   		 modulus of the synchrotron intensity.
	'''

    # Create an array that will hold the quarters of the synchrotron images
    quarter_arr = np.zeros(
        (4, np.shape(sync_map)[0] / 2, np.shape(sync_map)[1] / 2))

    # Add the quarters of the images into the array
    quarter_arr[0], quarter_arr[1] = np.split(np.split(sync_map, 2, axis=0)[0],
                                              2,
                                              axis=1)
    quarter_arr[2], quarter_arr[3] = np.split(np.split(sync_map, 2, axis=0)[1],
                                              2,
                                              axis=1)

    # Create arrays that will hold the calculated statistics for each quarter
    quad_deriv_std_val = np.zeros(np.shape(quarter_arr)[0])

    # Loop over the quarters, to calculate statistics for each one
    for i in range(np.shape(quarter_arr)[0]):
        # Extract the current image quarter from the array
        image = quarter_arr[i]

        # Calculate the 2D structure function for this slice of the synchrotron
        # intensity data cube. Note that no_fluct = True is set, because we are
        # not subtracting the mean from the synchrotron maps before calculating
        # the structure function. We are also calculating the normalised
        # structure function, which only takes values between 0 and 2.
        norm_strfn = sf_fft(image, no_fluct=True, normalise=True)

        # Shift the 2D structure function so that the zero radial separation
        # entry is in the centre of the image.
        norm_strfn = np.fft.fftshift(norm_strfn)

        # Calculate the magnitude and argument of the quadrupole ratio
        quad_mod, quad_arg, quad_rad = calc_quad_ratio(norm_strfn, num_bins)

        # Calculate the log of the radial spacing between evaluations of the
        # quadrupole ratio
        quad_space = np.log10(quad_rad[1]) - np.log10(quad_rad[0])

        # Calculate the first derivative of the quadrupole ratio modulus
        # Note that this assumes data that is equally spaced logarithmically,
        # so that we calculate the derivative as it appears on a semi-log plot
        quad_mod_deriv = np.gradient(quad_mod, quad_space)

        # Select the array values that are between the dissipation and
        # injection scales, as these will be used to calculate the standard
        # deviation of the first derivative.
        quad_mod_deriv = quad_mod_deriv[first_index:end_index] /\
         np.max(quad_mod[first_index:end_index])

        # Calculate the standard deviation of the first derivative of the
        # quadrupole ratio modulus
        quad_deriv_std_val[i] = np.std(quad_mod_deriv, dtype=np.float64)

    # At this point, the statistics have been calculated for each quarter
    # The next step is to calculate the standard error of the mean of each
    # statistic
    quad_deriv_std_err = np.std(quad_deriv_std_val) / np.sqrt(
        len(quad_deriv_std_val))

    # Now that all of the calculations have been performed, return the
    # calculated errors
    return quad_deriv_std_err
Exemple #15
0
        # simulation
        sync_fits = fits.open(data_loc + 'synint_{}_gam{}.fits'.format(\
         line_o_sight_cfed[j],gamma))

        # Extract the data for the simulated synchrotron intensities
        sync_data = sync_fits[0].data

        # Print a message to the screen to show that the data has been loaded
        print 'Synchrotron intensity loaded successfully'

        # Calculate the 2D structure function for this slice of the synchrotron
        # intensity data cube. Note that no_fluct = True is set, because we are
        # not subtracting the mean from the synchrotron maps before calculating
        # the structure function. We are also calculating the normalised
        # structure function, which only takes values between 0 and 2.
        norm_strfn = sf_fft(sync_data, no_fluct=True, normalise=True)

        # Shift the 2D structure function so that the zero radial separation
        # entry is in the centre of the image.
        norm_strfn = np.fft.fftshift(norm_strfn)

        # Calculate the magnitude and argument of the quadrupole ratio
        quad_mod, quad_arg, quad_rad = calc_quad_ratio(norm_strfn, num_bins)

        # Perform a linear fit to the quadrupole ratio on the radial scales
        # that have been specified
        spec_ind_data = np.polyfit(np.log10(quad_rad[first_index:end_index]),\
         quad_mod[first_index:end_index], 1, full = True)

        # Enter the value of the residuals into the corresponding array
        quad_resid_arr_cfed[i, j] = spec_ind_data[1]
Exemple #16
0
		# into the matrix that stores all of the calculated correlation functions
		norm_corr_arr[i,j] = norm_rad_corr

		# Insert the radius values used to calculate this correlation function
		# into the matrix that stores the radius values
		corr_rad_arr[i,j] = rad_corr[0]

		# Print a message to show that the correlation function has been calculated
		print 'Normalised, radially averaged correlation function calculated for'\
		+ ' gamma = {}'.format(gamma_arr[j])

		# Calculate the structure function (two-dimensional) of the synchrotron
		# intensity map. Note that no_fluct = True is set, because we are not 
		# subtracting the mean from the synchrotron maps before calculating the
		# structure function.
		strfn = sf_fft(sync_data[2*j], no_fluct = True)

		# Radially average the calculated 2D structure function, using the 
		# specified number of bins.
		rad_sf = sfr(strfn, num_bins, verbose = False)

		# Extract the calculated radially averaged structure function
		sf_arr[i,j] = rad_sf[1]

		# Extract the radius values used to calculate this structure function
		sf_rad_arr[i,j] = rad_sf[0]

		# Calculate the 2D structure function for this slice of the synchrotron
		# intensity data cube. Note that no_fluct = True is set, because we are
		# not subtracting the mean from the synchrotron maps before calculating
		# the structure function. We are also calculating the normalised 
Exemple #17
0
# to the number of bins being used to calculate the correlation functions.
sf_mat = np.zeros((sync_shape[0], num_bins))

# Create an array of zeroes, which will hold the radius values used to calculate
# each structure function. This array has the same shape as the array holding
# the radially averaged structure functions
rad_arr = np.zeros((sync_shape[0], num_bins))

# Loop over the third axis of the data cube, to calculate the structure 
# function for each map of synchrotron emission
for i in range(sync_shape[0]):
	# Calculate the 2D structure function for this slice of the synchrotron
	# intensity data cube. Note that no_fluct = True is set, because we are
	# not subtracting the mean from the synchrotron maps before calculating
	# the structure function
	strfn = sf_fft(sync_data[i], no_fluct = True)

	# Radially average the calculated 2D structure function, using the 
	# specified number of bins
	rad_sf = sfr(strfn, num_bins)

	# # Calculate the square of the mean of the synchrotron intensity values
	# sync_sq_mean = np.power( np.mean(sync_data[i], dtype = np.float64), 2.0 )

	# # Calculate the mean of the synchrotron intensity values squared
	# sync_mean_sq = np.mean( np.power(sync_data[i], 2.0), dtype = np.float64 )

	# # Calculate the normalised, radially averaged correlation function for
	# # this value of gamma
	# norm_rad_corr = (rad_corr[1] - sync_sq_mean) / (sync_mean_sq - sync_sq_mean)
Exemple #18
0
    # corresponding array.
    skew_z_arr[j] = stats.skew(flat_B_z)
    skew_x_arr[j] = stats.skew(flat_B_x)

    # Calculate the biased Fisher kurtosis of the magnetic field amplitude
    # maps, for lines of sight along the x and z axes, and store the results
    # in the corresponding array.
    kurt_z_arr[j] = stats.kurtosis(flat_B_z)
    kurt_x_arr[j] = stats.kurtosis(flat_B_x)

    # Calculate the structure function (two-dimensional) of the magnetic field
    # amplitude maps, for the lines of sight along the x and z axes. Note
    # that no_fluct = True is set, because we are not subtracting the mean
    # from the magnetic field amplitude maps before calculating the structure
    # function.
    strfn_z = sf_fft(B_map_z, no_fluct=True)
    strfn_x = sf_fft(B_map_x, no_fluct=True)

    # Radially average the calculated 2D structure function, using the
    # specified number of bins, for lines of sight along the x and z axes.
    rad_sf_z = sfr(strfn_z, num_bins, verbose=False)
    rad_sf_x = sfr(strfn_x, num_bins, verbose=False)

    # Extract the calculated radially averaged structure function for lines
    # of sight along the x and z axes.
    sf_z = rad_sf_z[1]
    sf_x = rad_sf_x[1]

    # Extract the radius values used to calculate this structure function,
    # for line os sight along the x and z axes.
    sf_rad_arr_z = rad_sf_z[0]
		skew_high_arr_z[i,j] = stats.skew(flat_sync_high_z)

		# Calculate the biased Fisher kurtosis of the synchrotron intensity 
		# maps, for low and high magnetic field simulations, and store the 
		# results in the corresponding array.
		kurt_low_arr_y[i,j] = stats.kurtosis(flat_sync_low_y)
		kurt_high_arr_y[i,j] = stats.kurtosis(flat_sync_high_y)
		# For z LOS
		kurt_low_arr_z[i,j] = stats.kurtosis(flat_sync_low_z)
		kurt_high_arr_z[i,j] = stats.kurtosis(flat_sync_high_z)

		# Calculate the structure function (two-dimensional) of the synchrotron
		# intensity maps, for the low and high magnetic field simulations. Note 
		# that no_fluct = True is set, because we are not subtracting the mean
		# from the synchrotron maps before calculating the structure function.
		strfn_low_y = sf_fft(sync_map_low_y, no_fluct = True)
		strfn_high_y = sf_fft(sync_map_high_y, no_fluct = True)
		# For z LOS
		strfn_low_z = sf_fft(sync_map_low_z, no_fluct = True)
		strfn_high_z = sf_fft(sync_map_high_z, no_fluct = True)

		# Radially average the calculated 2D structure function, using the 
		# specified number of bins, for low and high magnetic field simulations.
		rad_sf_low_y = sfr(strfn_low_y, num_bins, verbose = False)
		rad_sf_high_y = sfr(strfn_high_y, num_bins, verbose = False)
		# For z LOS
		rad_sf_low_z = sfr(strfn_low_z, num_bins, verbose = False)
		rad_sf_high_z = sfr(strfn_high_z, num_bins, verbose = False)

		# Extract the calculated radially averaged structure function for low 
		# and high magnetic field simulations
	# Calculate the biased skewness of the synchrotron intensity maps, and store
	# the results in the corresponding array, for y and z lines of sight
	skew_arr_y[j] = stats.skew(flat_sync_y)
	skew_arr_z[j] = stats.skew(flat_sync_z)

	# Calculate the biased Fisher kurtosis of the synchrotron intensity 
	# maps, and store the results in the corresponding array, for y and z LOS
	kurt_arr_y[j] = stats.kurtosis(flat_sync_y)
	kurt_arr_z[j] = stats.kurtosis(flat_sync_z)

	# Calculate the structure function (two-dimensional) of the synchrotron
	# intensity maps. Note that no_fluct = True is set, because we are not
	# subtracting the mean from the synchrotron maps before calculating the 
	# structure function, for y and z lines of sight
	strfn_y = sf_fft(sync_map_y, no_fluct = True)
	strfn_z = sf_fft(sync_map_z, no_fluct = True)

	# Radially average the calculated 2D structure function, using the 
	# specified number of bins, for y and z lines of sight
	rad_sf_y = sfr(strfn_y, num_bins, verbose = False)
	rad_sf_z = sfr(strfn_z, num_bins, verbose = False)

	# Extract the calculated radially averaged structure function, for y and
	# z lines of sight
	sf_y = rad_sf_y[1]
	sf_z = rad_sf_z[1]

	# Extract the radius values used to calculate this structure function, for
	# y and z lines of sight
	sf_rad_arr_y = rad_sf_y[0]
Exemple #21
0
    # free parameter related to the observational effect being studied. Each
    # row corresponds to a value of the free parameter, and each column
    # corresponds to a radial value. There is one array for a line of sight
    # along the z axis, and another for a line of sight along the x axis.
    rad_z_arr = np.zeros((len(iter_array), num_bins))
    rad_x_arr = np.zeros((len(iter_array), num_bins))

    # Loop over the various values of the free parameter related to the
    # observational effect being studied, to calculate the structure function
    # for the synchrotron map observed for each value of the free parameter
    for i in range(len(iter_array)):
        # Calculate the structure function (two-dimensional) of the synchrotron
        # intensity maps, for the lines of sight along the x and z axes. Note
        # that no_fluct = True is set, because we are not subtracting the mean
        # from the synchrotron maps before calculating the structure function.
        strfn_z = sf_fft(sync_data_z[i], no_fluct=True)
        strfn_x = sf_fft(sync_data_x[i], no_fluct=True)

        # Radially average the calculated 2D structure function, using the
        # specified number of bins, for lines of sight along the x and z axes.
        rad_sf_z = sfr(strfn_z, num_bins, verbose=False)
        rad_sf_x = sfr(strfn_x, num_bins, verbose=False)

        # Extract the calculated radially averaged structure function for lines
        # of sight along the x and z axes.
        sf_z = rad_sf_z[1]
        sf_x = rad_sf_x[1]

        # Extract the radius values used to calculate this structure function,
        # for lines of sight along the x and z axes.
        sf_rad_arr_z = rad_sf_z[0]
Exemple #22
0
# of the magnetic field
y_rad_av_corr = sfr(y_corr, num_bins)

# Calculate the normalised radially averaged correlation function for the 
# y-component of the magnetic field. This is the left hand side of equation 14
# of Lazarian and Pogosyan 2012.
c_2 = y_rad_av_corr[1] / mag_y_mean_sq

# Print a message to show that c_2 has been calculated
print 'Normalised correlation function for the y-component of the magnetic'\
+ ' has been calculated'

# --------------- Structure function x-comp B field ---------------------------

# Calculate the structure function for the x-component of the magnetic field
x_sf = sf_fft(mag_x_data, no_fluct = True)

# Print a message to show that the structure function of the x-component of
# the magnetic field has been calculated
print 'Structure function of the x-component of the magnetic field calculated'

# Calculate the radially averaged structure function for the x-component
# of the magnetic field
x_rad_av_sf = sfr(x_sf, num_bins)

# Calculate the right hand side of equation 13 of Lazarian and Pogosyan 2012
# NOTE: The equation as specified in the paper is wrong. The structure function
# needs to be divided by the average of the x-component of the magnetic field
# squared.
RHS_13 = 1.0 - 0.5 * x_rad_av_sf[1] / mag_x_mean_sq
Exemple #23
0
                                            ind_min:ind_max]

        # Integrate the perpendicular magnetic field strength raised to the power
        # of gamma along the required axis, to calculate the observed synchrotron
        # map for these slices. This integration is performed by the trapezoidal
        # rule. To normalise the calculated synchrotron map, divide by the number
        # of pixels along the integration axis. Note the array is ordered by(z,y,x)!
        # NOTE: Set dx to whatever the pixel spacing is
        sync_arr = np.trapz(sub_mag_perp_gamma, dx = 1.0, axis = int_axis) /\
         np.shape(sub_mag_perp_gamma)[int_axis]

        # Calculate the structure function (two-dimensional) of the synchrotron
        # intensity map. Note that no_fluct = True is set, because we are not
        # subtracting the mean from the synchrotron map before calculating the
        # structure function.
        strfn = sf_fft(sync_arr, no_fluct=True)

        # Radially average the calculated 2D structure function, using the
        # specified number of bins.
        rad_sf = sfr(strfn, num_bins, verbose=False)

        # Extract the calculated radially averaged structure function
        sf = rad_sf[1]

        # Extract the radius values used to calculate this structure function
        sf_rad_arr = rad_sf[0]

        # Store the values for the radially averaged structure function in the
        # corresponding array
        sf_arr[i] = sf
        sync_fits = fits.open(
            data_loc +
            'synint_p1-4_{}_frac.fits'.format(rot_ang_arr[rot_index]))

        # Extract the data for the simulated synchrotron intensities
        # This is a 3D data cube, where the slices along the third axis are the
        # synchrotron intensities observed for different values of gamma, the power law
        # index of the cosmic ray electrons emitting the synchrotron emission.
        sync_data = sync_fits[0].data

        # Calculate the 2D structure function for this slice of the synchrotron
        # intensity data cube. Note that no_fluct = True is set, because we are
        # not subtracting the mean from the synchrotron maps before calculating
        # the structure function. We are also calculating the normalised structure
        # function, which only takes values between 0 and 2.
        strfn = sf_fft(sync_data[gam_index], no_fluct=True, normalise=True)

        # Shift the 2D structure function so that the zero radial separation
        # entry is in the centre of the image.
        strfn = np.fft.fftshift(strfn)

        # Calculate the monopole for the normalised structure function
        monopole_arr, mono_rad_arr = calc_multipole_2D(strfn, order = 0,\
         num_bins = num_bins)

        # Calculate the quadrupole for the normalised structure function
        quadpole_arr, quad_rad_arr = calc_multipole_2D(strfn, order = 2,\
         num_bins = num_bins)

        # Insert the calculated multipole ratios into the matrix that stores all
        # of the calculated multipole
Exemple #25
0
def calc_err_bootstrap(sync_map_y, sync_map_z):
    '''
	Description
        This function divides the given images into quarters, and then 
        calculates statistics for each quarter. The standard deviation of the 
        calculated statistics is then returned, representing the error on 
        each statistic.
        
    Required Input
        sync_map_y - The synchrotron intensity map observed for a line of sight
        			 along the y axis.
        sync_map_z - The synchrotron intensity map observed for a line of sight 
        			 along the z axis. Must have the same size as the map 
        			 for a line of sight along the y axis.
                   
    Output
        m_err - The error calculated for the structure function slope of the 
        		synchrotron intensity
		residual_err - The error calculated for the residual of the linear fit 
					   to the structure function of synchrotron intensity
		int_quad_err - The error calculated for the integrated quadrupole ratio
					   modulus of the synchrotron intensity
	'''

    # Create an array that will hold the quarters of the synchrotron images
    quarter_arr = np.zeros(
        (8, np.shape(sync_map_y)[0] / 2, np.shape(sync_map_y)[1] / 2))

    # Add the quarters of the images into the array
    quarter_arr[0], quarter_arr[1] = np.split(np.split(sync_map_y, 2,
                                                       axis=0)[0],
                                              2,
                                              axis=1)
    quarter_arr[2], quarter_arr[3] = np.split(np.split(sync_map_y, 2,
                                                       axis=0)[1],
                                              2,
                                              axis=1)
    quarter_arr[4], quarter_arr[5] = np.split(np.split(sync_map_z, 2,
                                                       axis=0)[0],
                                              2,
                                              axis=1)
    quarter_arr[6], quarter_arr[7] = np.split(np.split(sync_map_z, 2,
                                                       axis=0)[1],
                                              2,
                                              axis=1)

    # Create arrays that will hold the calculated statistics for each quarter
    m_val = np.zeros(np.shape(quarter_arr)[0])
    resid_val = np.zeros(np.shape(quarter_arr)[0])
    int_quad_val = np.zeros(np.shape(quarter_arr)[0])

    # Loop over the quarters, to calculate statistics for each one
    for i in range(np.shape(quarter_arr)[0]):
        # Extract the current image quarter from the array
        image = quarter_arr[i]

        # Calculate the structure function (two-dimensional) of the synchrotron
        # intensity map. Note that no_fluct = True is set, because we are not
        # subtracting the mean from the synchrotron maps before calculating the
        # structure function.
        strfn = sf_fft(image, no_fluct=True)

        # Radially average the calculated 2D structure function, using the
        # specified number of bins.
        rad_sf = sfr(strfn, num_bins, verbose=False)

        # Extract the calculated radially averaged structure function
        sf = rad_sf[1]

        # Extract the radius values used to calculate this structure function.
        sf_rad_arr = rad_sf[0]

        # Calculate the spectral index of the structure function calculated for
        # this value of gamma. Note that only the first third of the structure
        # function is used in the calculation, as this is the part that is
        # close to a straight line.
        spec_ind_data = np.polyfit(np.log10(\
         sf_rad_arr[11:16]),\
         np.log10(sf[11:16]), 1, full = True)

        # Extract the returned coefficients from the polynomial fit
        coeff = spec_ind_data[0]

        # Extract the sum of the residuals from the polynomial fit
        resid_val[i] = spec_ind_data[1]

        # Enter the value of m, the slope of the structure function minus 1,
        # into the corresponding array
        m_val[i] = coeff[0] - 1.0

        # Calculate the 2D structure function for this slice of the synchrotron
        # intensity data cube. Note that no_fluct = True is set, because we are
        # not subtracting the mean from the synchrotron maps before calculating
        # the structure function. We are also calculating the normalised
        # structure function, which only takes values between 0 and 2.
        norm_strfn = sf_fft(image, no_fluct=True, normalise=True)

        # Shift the 2D structure function so that the zero radial separation
        # entry is in the centre of the image.
        norm_strfn = np.fft.fftshift(norm_strfn)

        # Calculate the magnitude and argument of the quadrupole ratio
        quad_mod, quad_arg, quad_rad = calc_quad_ratio(norm_strfn, num_bins)

        # Integrate the magnitude of the quadrupole / monopole ratio from
        # one sixth of the way along the radial separation bins, until three
        # quarters of the way along the radial separation bins. This integration
        # is performed with respect to log separation (i.e. I am ignoring the
        # fact that the points are equally separated in log space, to calculate
        # the area under the quadrupole / monopole ratio plot when the x axis
        # is scaled logarithmically). I normalise the value that is returned by
        # dividing by the number of increments in log radial separation used in
        # the calculation.
        int_quad_val[i] = np.trapz(quad_mod[11:20], dx = 1.0)\
         / (19 - 11)

    # At this point, the statistics have been calculated for each quarter
    # The next step is to calculate the standard error of the mean of each
    # statistic
    m_err = np.std(m_val) / np.sqrt(len(m_val))
    residual_err = np.std(resid_val) / np.sqrt(len(resid_val))
    int_quad_err = np.std(int_quad_val) / np.sqrt(len(int_quad_val))

    # Now that all of the calculations have been performed, return the
    # calculated errors
    return m_err, residual_err, int_quad_err
Exemple #26
0
    # Calculate the biased skewness of the synchrotron intensity maps, and store
    # the results in the corresponding array, for y and z lines of sight
    skew_arr_y[j] = stats.skew(flat_sync_y)
    skew_arr_z[j] = stats.skew(flat_sync_z)

    # Calculate the biased Fisher kurtosis of the synchrotron intensity
    # maps, and store the results in the corresponding array, for y and z LOS
    kurt_arr_y[j] = stats.kurtosis(flat_sync_y)
    kurt_arr_z[j] = stats.kurtosis(flat_sync_z)

    # Calculate the structure function (two-dimensional) of the synchrotron
    # intensity maps. Note that no_fluct = True is set, because we are not
    # subtracting the mean from the synchrotron maps before calculating the
    # structure function, for y and z lines of sight
    strfn_y = sf_fft(sync_map_y, no_fluct=True)
    strfn_z = sf_fft(sync_map_z, no_fluct=True)

    # Radially average the calculated 2D structure function, using the
    # specified number of bins, for y and z lines of sight
    rad_sf_y = sfr(strfn_y, num_bins, verbose=False)
    rad_sf_z = sfr(strfn_z, num_bins, verbose=False)

    # Extract the calculated radially averaged structure function, for y and
    # z lines of sight
    sf_y = rad_sf_y[1]
    sf_z = rad_sf_z[1]

    # Extract the radius values used to calculate this structure function, for
    # y and z lines of sight
    sf_rad_arr_y = rad_sf_y[0]
Exemple #27
0
	# corresponding array.
	skew_z_arr[j] = stats.skew(flat_B_z)
	skew_x_arr[j] = stats.skew(flat_B_x)

	# Calculate the biased Fisher kurtosis of the magnetic field amplitude 
	# maps, for lines of sight along the x and z axes, and store the results
	# in the corresponding array.
	kurt_z_arr[j] = stats.kurtosis(flat_B_z)
	kurt_x_arr[j] = stats.kurtosis(flat_B_x)

	# Calculate the structure function (two-dimensional) of the magnetic field
	# amplitude maps, for the lines of sight along the x and z axes. Note 
	# that no_fluct = True is set, because we are not subtracting the mean
	# from the magnetic field amplitude maps before calculating the structure
	# function.
	strfn_z = sf_fft(B_map_z, no_fluct = True)
	strfn_x = sf_fft(B_map_x, no_fluct = True)

	# Radially average the calculated 2D structure function, using the 
	# specified number of bins, for lines of sight along the x and z axes.
	rad_sf_z = sfr(strfn_z, num_bins, verbose = False)
	rad_sf_x = sfr(strfn_x, num_bins, verbose = False)

	# Extract the calculated radially averaged structure function for lines
	# of sight along the x and z axes.
	sf_z = rad_sf_z[1]
	sf_x = rad_sf_x[1]

	# Extract the radius values used to calculate this structure function,
	# for line os sight along the x and z axes.
	sf_rad_arr_z = rad_sf_z[0]
quad_rad_arr = np.zeros((sync_shape[0], num_bins))

# Create an array of zeroes, which will hold the radius values used to calculate
# the octopole for each structure function. This array has one row for each
# gamma value, and a column for each radius value used in the calculation.
octo_rad_arr = np.zeros((sync_shape[0], num_bins))

# Loop over the third axis of the data cube, to calculate the normalised
# structure function for each map of synchrotron emission
for i in range(sync_shape[0]):
    # Calculate the 2D structure function for this slice of the synchrotron
    # intensity data cube. Note that no_fluct = True is set, because we are
    # not subtracting the mean from the synchrotron maps before calculating
    # the structure function. We are also calculating the normalised structure
    # function, which only takes values between 0 and 2.
    strfn = sf_fft(sync_data[i], no_fluct=True, normalise=True)

    # Store the normalised structure function in the array of structure function
    # This has been shifted so that the zero radial separation entry is in
    # the centre of the image.
    sf_mat[i] = np.fft.fftshift(strfn)

    # Calculate the monopole for the normalised structure function
    monopole_arr[i], mono_rad_arr[i] = calc_multipole_2D(sf_mat[i], order = 0,\
     num_bins = num_bins)

    # Calculate the quadrupole for the normalised structure function
    quadpole_arr[i], quad_rad_arr[i] = calc_multipole_2D(sf_mat[i], order = 2,\
     num_bins = num_bins)

    # Calculate the octopole for the normalised structure function
Exemple #29
0
    # Print a message to the screen to show that the synchrotron data has been
    # loaded successfully
    print 'Simulated synchrotron data loaded'

    # Calculate the shape of the synchrotron data cube
    sync_shape = np.shape(sync_data)

    # Print the shape of the synchrotron data matrix, as a check
    print 'The shape of the synchrotron data matrix is: {}'.\
    format(sync_shape)

    # Calculate the 2D structure function for the relevant slice of the
    # synchrotron intensity data cube, i.e. the value of gamma we are interested
    # in. Note that no_fluct = True is set, because we are not subtracting the
    # mean from the synchrotron maps before calculating the structure function
    strfn = sf_fft(sync_data[gamma_index], no_fluct=True)

    # Radially average the calculated 2D structure function, using the
    # specified number of bins
    rad_sf = sfr(strfn, num_bins)

    # Insert the calculated radially averaged structure function
    # into the matrix that stores all of the calculated structure functions
    sf_mat[rot_index] = rad_sf[1]

    # Insert the radius values used to calculate this structure function
    # into the matrix that stores the radius values
    rad_arr[rot_index] = rad_sf[0]

    # Print a message to show that the structure function has been calculated
    print 'Radially averaged structure function calculated for'\
Exemple #30
0
		sub_mag_perp_gamma = mag_perp_gamma[ind_min:ind_max,ind_min:ind_max,ind_min:ind_max]

		# Integrate the perpendicular magnetic field strength raised to the power
		# of gamma along the required axis, to calculate the observed synchrotron 
		# map for these slices. This integration is performed by the trapezoidal 
		# rule. To normalise the calculated synchrotron map, divide by the number 
		# of pixels along the integration axis. Note the array is ordered by(z,y,x)!
		# NOTE: Set dx to whatever the pixel spacing is
		sync_arr = np.trapz(sub_mag_perp_gamma, dx = 1.0, axis = int_axis) /\
		 np.shape(sub_mag_perp_gamma)[int_axis]

		# Calculate the structure function (two-dimensional) of the synchrotron
		# intensity map. Note that no_fluct = True is set, because we are not 
		# subtracting the mean from the synchrotron map before calculating the 
		# structure function.
		strfn = sf_fft(sync_arr, no_fluct = True)

		# Radially average the calculated 2D structure function, using the 
		# specified number of bins.
		rad_sf = sfr(strfn, num_bins, verbose = False)

		# Extract the calculated radially averaged structure function
		sf = rad_sf[1]

		# Extract the radius values used to calculate this structure function
		sf_rad_arr = rad_sf[0]

		# Store the values for the radially averaged structure function in the 
		# corresponding array
		sf_arr[i] = sf