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
		sf_low_y = rad_sf_low_y[1]
		sf_high_y = rad_sf_high_y[1]
		# For z LOS
		sf_low_z = rad_sf_low_z[1]
		sf_high_z = rad_sf_high_z[1]

		# Extract the radius values used to calculate this structure function,
		# for low and high magnetic field simulations.
Exemple #2
0
    # field raised to the power of gamma
    mag_mean_sq_gamma = np.mean(np.power(mag_perp_gamma, 2.0),
                                dtype=np.float64)

    # Calculate the correlation function for the perpendicular component of the
    # magnetic field, when raised to the power of gamma
    perp_gamma_corr = cf_fft(mag_perp_gamma, no_fluct=True)

    # Print a message to show that the correlation function of the perpendicular
    # component of the magnetic field has been calculated for gamma
    print 'Correlation function of the perpendicular component of the magnetic'\
    + ' field calculated for gamma = {}'.format(gamma_arr[i])

    # Calculate the radially averaged correlation function for the perpendicular
    # component of the magnetic field, raised to the power of gamma
    perp_gamma_rad_corr = sfr(perp_gamma_corr, num_bins, verbose=False)

    # Calculate the normalised correlation function for the magnetic field
    # perpendicular to the line of sight, for gamma. This is the right hand
    # side of equation 15.
    mag_gamma_norm_corr = (perp_gamma_rad_corr[1] - mag_sq_mean_gamma)\
     / (mag_mean_sq_gamma - mag_sq_mean_gamma)

    # Insert the calculated normalised, radially averaged correlation function
    # into the matrix that stores all of the calculated correlation functions
    cf_mat[i] = mag_gamma_norm_corr

    # Insert the radius values used to calculate this correlation function
    # into the matrix that stores the radius values
    rad_arr[i] = perp_gamma_rad_corr[0]
# Print a message to show that the perpendicular component of the magnetic
# field has been calculated
print 'Perpendicular component of the magnetic field calculated'

# ---------------- Normalised correlation x-comp B field ----------------------

# Calculate the correlation function for the x-component of the magnetic field
x_corr = cf_fft(mag_x_data, no_fluct = True)

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

# Calculate the radially averaged correlation function for the x-component
# of the magnetic field
x_rad_av_corr = sfr(x_corr, num_bins)

# Extract the radius values used to calculate the radially averaged 
# correlation function
radius_array = x_rad_av_corr[0]

# Calculate the normalised radially averaged correlation function for the 
# x-component of the magnetic field. This is equation 13 of Lazarian and 
# Pogosyan 2012.
c_1 = x_rad_av_corr[1] / mag_x_mean_sq

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

# ---------------- Normalised correlation y-comp B field ----------------------
Exemple #4
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
		# 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]),\
			np.log10(sf_arr[i,j,5:14]), 1, full = True)

		# Extract the returned coefficients from the polynomial fit
		coeff = spec_ind_data[0]
Exemple #6
0
	# 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'\
	+ ' rotation angle = {}'.format(rot_ang_arr[rot_index])

# Loop over the rotation angle values, to calculate the spectral index
# for each structure function of synchrotron emission
# same shape as the array holding the normalised, radially averaged correlation
# functions
rad_arr = np.zeros((sync_shape[0], num_bins))

# Loop over the third axis of the data cube, to calculate the correlation 
# function for each map of synchrotron emission
for i in range(sync_shape[0]):
	# Calculate the 2D correlation 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 correlation function
	corr = cf_fft(sync_data[i], no_fluct = True)

	# Radially average the calculated 2D correlation function, using the 
	# specified number of bins
	rad_corr = sfr(corr, num_bins, verbose = False)

	# 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)

	# Insert the calculated normalised, radially averaged correlation function
	# into the matrix that stores all of the calculated correlation functions
	cf_mat[i] = norm_rad_corr
Exemple #8
0
		# 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 correlation 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 correlation function
		corr = cf_fft(sync_data, no_fluct = True)

		# Radially average the calculated 2D correlation function, using the 
		# specified number of bins
		rad_corr = sfr(corr, num_bins, verbose = False)

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

		# Calculate the mean of the synchrotron intensity values squared
		sync_mean_sq = np.mean( np.power(sync_data, 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)

		# Print a message to show that the correlation function of the
		# synchrotron intensity has been calculated for this line of sight
		print 'Correlation function of synchrotron intensity'\
		+ ' calculated for {} LOS'.format(line_o_sight[j])
Exemple #9
0
'hot', xlabel = 'x-axis separation', ylabel = 'y-axis separation', title =\
 '2D Correlation Function for int2')

# Print a message to show that the plots of the correlation functions have
# been produced successfully
print 'Tutorial: Plots of the correlation functions for int1 and int2 '\
+ 'produced successfully'

# The results are in 2D, in fact I used these 2D maps to plot the isocountours
# that you took to Northwestern U with Alex. sf_fft, cf_fft work in 3D as well.

# To average in R you can use the function sfr (works also in 3D)

# Calculate the radially averaged structure function for int1. The 15 is the
# number of bins to use in the radial averaging process.
sf_int1_r = sfr(sf_int1_2D, 15)

# Calculate the radially averaged correlation function for int1.
cf_int1_r = sfr(cf_int1_2D, 15)
# Calculate the radially averaged correlation function for int2.
cf_int2_r = sfr(cf_int2_2D, 15)

# The sfr function returns a matrix, where the first row of the matrix,
# sf_int1_r[0] returns the values of R (radius) used to perform the radial
# averaging, and the second row, sf_int1_r[1], returns the average of the
# structure function values for that value of R.

# Print out the radially averaged structure function for int1, to show what
# the values are.
print 'Tutorial: The values of the radius (top row) and of the radially'\
+ ' averaged structure function (second row) for int1 are sf_int1_r = {}'\
Exemple #10
0
# Print a message to the screen to show that the data has been loaded
print 'Magnetic field components loaded successfully'

# ---------------- Normalised correlation x-comp B field ----------------------

# Calculate the correlation function for the x-component of the magnetic field
x_corr = cf_fft(mag_x_data, no_fluct=True)

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

# Calculate the radially averaged correlation function for the x-component
# of the magnetic field
x_rad_av_corr = sfr(x_corr, num_bins)

# Extract the radius values used to calculate the radially averaged
# correlation function
radius_array = x_rad_av_corr[0]

# Calculate the normalised radially averaged correlation function for the
# x-component of the magnetic field. This is the left hand side of equation 13
# of Lazarian and Pogosyan 2012.
c_1 = x_rad_av_corr[1] / mag_x_mean_sq

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

# ---------------- Normalised correlation y-comp B field ----------------------
# Print a message to show that the perpendicular component of the magnetic
# field has been calculated
print 'Perpendicular component of the magnetic field calculated'

# ---------------- Normalised correlation x-comp B field ----------------------

# Calculate the correlation function for the x-component of the magnetic field
x_corr = cf_fft(mag_x_data, no_fluct=True)

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

# Calculate the radially averaged correlation function for the x-component
# of the magnetic field
x_rad_av_corr = sfr(x_corr, num_bins)

# Extract the radius values used to calculate the radially averaged
# correlation function
radius_array = x_rad_av_corr[0]

# Calculate the normalised radially averaged correlation function for the
# x-component of the magnetic field. This is equation 13 of Lazarian and
# Pogosyan 2012.
c_1 = x_rad_av_corr[1] / mag_x_mean_sq

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

# ---------------- Normalised correlation y-comp B field ----------------------
Exemple #12
0
'hot', xlabel = 'x-axis separation', ylabel = 'y-axis separation', title =\
 '2D Correlation Function for int2')

# Print a message to show that the plots of the correlation functions have
# been produced successfully
print 'Tutorial: Plots of the correlation functions for int1 and int2 '\
+ 'produced successfully'

# The results are in 2D, in fact I used these 2D maps to plot the isocountours
# that you took to Northwestern U with Alex. sf_fft, cf_fft work in 3D as well.

# To average in R you can use the function sfr (works also in 3D)

# Calculate the radially averaged structure function for int1. The 15 is the 
# number of bins to use in the radial averaging process.
sf_int1_r = sfr(sf_int1_2D, 15)

# Calculate the radially averaged correlation function for int1.
cf_int1_r = sfr(cf_int1_2D, 15)
# Calculate the radially averaged correlation function for int2.
cf_int2_r = sfr(cf_int2_2D, 15)

# The sfr function returns a matrix, where the first row of the matrix,
# sf_int1_r[0] returns the values of R (radius) used to perform the radial
# averaging, and the second row, sf_int1_r[1], returns the average of the
# structure function values for that value of R.

# Print out the radially averaged structure function for int1, to show what
# the values are.
print 'Tutorial: The values of the radius (top row) and of the radially'\
+ ' averaged structure function (second row) for int1 are sf_int1_r = {}'\
Exemple #13
0
    # field has been calculated
    print 'Perpendicular component of the magnetic field calculated'

    # -------------- Normalised correlation x-comp B field ---------------------

    # Calculate the correlation function for the x-component of the magnetic
    # field (this has already been normalised)
    x_corr = cf_fft(mag_x_data, no_fluct=True, normalise=True)

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

    # Calculate the radially averaged correlation function for the x-component
    # of the magnetic field
    x_rad_av_corr = sfr(x_corr, num_bins, verbose=False)

    # Extract the radius values used to calculate the radially averaged
    # correlation function
    radius_array = x_rad_av_corr[0]

    # Calculate the normalised radially averaged correlation function for the
    # x-component of the magnetic field. This is equation 13 of Lazarian and
    # Pogosyan 2012.
    c_1 = x_rad_av_corr[1]

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

    # ---------------- Normalised correlation y-comp B field -------------------
Exemple #14
0
# field has been calculated
print 'Perpendicular component of the magnetic field calculated'

# ---------------- Normalised correlation x-comp B field ----------------------

# Calculate the normalised correlation function for the x-component of the 
# magnetic field
x_corr = cf_fft(mag_x_data, no_fluct = True, normalise = True)

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

# Calculate the radially averaged correlation function for the x-component
# of the magnetic field
x_rad_av_corr = sfr(x_corr, num_bins, verbose = False)

# Extract the radius values used to calculate the radially averaged 
# correlation function
radius_array = x_rad_av_corr[0]

# Calculate the normalised radially averaged correlation function for the 
# x-component of the magnetic field. This is equation 13 of Lazarian and 
# Pogosyan 2012.
c_1 = x_rad_av_corr[1]

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

# ---------------- Normalised correlation y-comp B field ----------------------
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 #16
0
	# Print a message to the screen to show that the data has been loaded
	print 'Synchrotron intensity loaded successfully'

	# Loop over the gamma values, to calculate the correlation function, 
	# structure function and quadrupole ratio for each gamma value
	for j in range(len(gamma_arr)):
		# Calculate the 2D correlation 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 correlation function
		corr = cf_fft(sync_data[2*j], no_fluct = True)

		# Radially average the calculated 2D correlation function, using the 
		# specified number of bins
		rad_corr = sfr(corr, num_bins, verbose = False)

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

		# Calculate the mean of the synchrotron intensity values squared
		sync_mean_sq = np.mean( np.power(sync_data[2*j], 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)

		# Print a message to show that the correlation function of the
		# synchrotron intensity has been calculated for this gamma
		print 'Correlation function of synchrotron intensity'\
		+ ' calculated for gamma = {}'.format(gamma_arr[j])
Exemple #17
0
    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]
        sf_rad_arr_x = rad_sf_x[0]

        # Store the values for the radially averaged structure function in the
        # corresponding array, for each line of sight
        sf_z_arr[i] = sf_z
Exemple #18
0
		# Calculate the mean of the squared perpendicular component of the magnetic
		# field raised to the power of gamma
		mag_mean_sq_gamma = np.mean( np.power(mag_perp_gamma, 2.0),dtype=np.float64)

		# Calculate the correlation function for the perpendicular component of the
		# magnetic field, when raised to the power of gamma
		perp_gamma_corr = cf_fft(mag_perp_gamma, no_fluct = True)

		# Print a message to show that the correlation function of the perpendicular 
		# component of the magnetic field has been calculated for gamma
		print 'Correlation function of the perpendicular component of the magnetic'\
		+ ' field calculated for gamma = {}'.format(gamma_arr[j])

		# Calculate the radially averaged correlation function for the perpendicular
		# component of the magnetic field, raised to the power of gamma
		perp_gamma_rad_corr = sfr(perp_gamma_corr, num_bins)

		# Calculate the normalised correlation function for the magnetic field
		# perpendicular to the line of sight, for gamma. This is the right hand
		# side of equation 15.
		mag_gamma_norm_corr = (perp_gamma_rad_corr[1] - mag_sq_mean_gamma)\
		 / (mag_mean_sq_gamma - mag_sq_mean_gamma)

		# Insert the calculated normalised, radially averaged correlation function
		# into the matrix that stores all of the calculated correlation functions
		cf_mat[j] = mag_gamma_norm_corr

		# Insert the radius values used to calculate this correlation function
		# into the matrix that stores the radius values
		rad_arr[j] = perp_gamma_rad_corr[0]
Exemple #19
0
        # 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

        # Store the radius values used to calculate the structure function in
        # the corresponding array
        rad_arr[i] = sf_rad_arr
	# 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]
	sf_rad_arr_z = rad_sf_z[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 
Exemple #21
0
            # 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
        sf_low_y = rad_sf_low_y[1]
        sf_high_y = rad_sf_high_y[1]
        # For z LOS
        sf_low_z = rad_sf_low_z[1]
        sf_high_z = rad_sf_high_z[1]

        # Extract the radius values used to calculate this structure function,
        # for low and high magnetic field simulations.
Exemple #22
0
# Print a message to the screen to show that the data has been loaded
print 'Magnetic field components loaded successfully'

# ---------------- Normalised correlation x-comp B field ----------------------

# Calculate the correlation function for the x-component of the magnetic field
x_corr = cf_fft(mag_x_data, no_fluct = True)

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

# Calculate the radially averaged correlation function for the x-component
# of the magnetic field
x_rad_av_corr = sfr(x_corr, num_bins)

# Extract the radius values used to calculate the radially averaged 
# correlation function
radius_array = x_rad_av_corr[0]

# Calculate the normalised radially averaged correlation function for the 
# x-component of the magnetic field. This is the left hand side of equation 13
# of Lazarian and Pogosyan 2012.
c_1 = x_rad_av_corr[1] / mag_x_mean_sq

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

# ---------------- Normalised correlation y-comp B field ----------------------
Exemple #23
0
	# 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]
	sf_rad_arr_x = rad_sf_x[0]

	# Calculate the spectral index of the structure function. 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. Perform a linear fit for a 
Exemple #24
0
    # 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]
    sf_rad_arr_z = rad_sf_z[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
Exemple #25
0
    # 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'\
    + ' rotation angle = {}'.format(rot_ang_arr[rot_index])

# Loop over the rotation angle values, to calculate the spectral index
# for each structure function of synchrotron emission
Exemple #26
0
        # field raised to the power of gamma
        mag_mean_sq_gamma = np.mean(np.power(mag_perp_gamma, 2.0),
                                    dtype=np.float64)

        # Calculate the correlation function for the perpendicular component of the
        # magnetic field, when raised to the power of gamma
        perp_gamma_corr = cf_fft(mag_perp_gamma, no_fluct=True)

        # Print a message to show that the correlation function of the perpendicular
        # component of the magnetic field has been calculated for gamma
        print 'Correlation function of the perpendicular component of the magnetic'\
        + ' field calculated for gamma = {}'.format(gamma_arr[j])

        # Calculate the radially averaged correlation function for the perpendicular
        # component of the magnetic field, raised to the power of gamma
        perp_gamma_rad_corr = sfr(perp_gamma_corr, num_bins)

        # Calculate the normalised correlation function for the magnetic field
        # perpendicular to the line of sight, for gamma. This is the right hand
        # side of equation 15.
        mag_gamma_norm_corr = (perp_gamma_rad_corr[1] - mag_sq_mean_gamma)\
         / (mag_mean_sq_gamma - mag_sq_mean_gamma)

        # Insert the calculated normalised, radially averaged correlation function
        # into the matrix that stores all of the calculated correlation functions
        cf_mat[j] = mag_gamma_norm_corr

        # Insert the radius values used to calculate this correlation function
        # into the matrix that stores the radius values
        rad_arr[j] = perp_gamma_rad_corr[0]