Пример #1
0
		# Enter the value of the residuals into the corresponding array
		residual_arr[i,j] = spec_ind_data[1]

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

		# Add the calculated modulus of the quadrupole ratio to the final array
		quad_arr[i,j] = quad_mod

		# Add the radius values used to calculate the quadrupole ratio to the
		# corresponding array
		quad_rad_arr[i,j] = quad_rad

		# 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
Пример #2
0
        norm_strfn_high_z = sf_fft(sync_map_free_param_high_z,
                                   no_fluct=True,
                                   normalise=True)

        # Shift the 2D structure function so that the zero radial separation
        # entry is in the centre of the image. This is done for low and high
        # magnetic field simulations
        norm_strfn_low_y = np.fft.fftshift(norm_strfn_low_y)
        norm_strfn_high_y = np.fft.fftshift(norm_strfn_high_y)
        # For z LOS
        norm_strfn_low_z = np.fft.fftshift(norm_strfn_low_z)
        norm_strfn_high_z = np.fft.fftshift(norm_strfn_high_z)

        # Calculate the magnitude and argument of the quadrupole ratio, for
        # low and high magnetic field simulations
        quad_mod_low_y, quad_arg_low_y, quad_rad_low_y = calc_quad_ratio(
            norm_strfn_low_y, num_bins)
        quad_mod_high_y, quad_arg_high_y, quad_rad_high_y = calc_quad_ratio(
            norm_strfn_high_y, num_bins)
        # For z LOS
        quad_mod_low_z, quad_arg_low_z, quad_rad_low_z = calc_quad_ratio(
            norm_strfn_low_z, num_bins)
        quad_mod_high_z, quad_arg_high_z, quad_rad_high_z = calc_quad_ratio(
            norm_strfn_high_z, 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
Пример #3
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
Пример #4
0
		# For z LOS
		norm_strfn_low_z = sf_fft(sync_map_low_z, no_fluct = True, normalise = True)
		norm_strfn_high_z = sf_fft(sync_map_high_z, no_fluct = True, normalise = True)

		# Shift the 2D structure function so that the zero radial separation
		# entry is in the centre of the image. This is done for low and high 
		# magnetic field simulations
		norm_strfn_low_y = np.fft.fftshift(norm_strfn_low_y)
		norm_strfn_high_y = np.fft.fftshift(norm_strfn_high_y)
		# For z LOS
		norm_strfn_low_z = np.fft.fftshift(norm_strfn_low_z)
		norm_strfn_high_z = np.fft.fftshift(norm_strfn_high_z)

		# Calculate the magnitude and argument of the quadrupole ratio, for 
		# low and high magnetic field simulations
		quad_mod_low_y, quad_arg_low_y, quad_rad_low_y = calc_quad_ratio(norm_strfn_low_y, num_bins)
		quad_mod_high_y, quad_arg_high_y, quad_rad_high_y = calc_quad_ratio(norm_strfn_high_y, num_bins)
		# For z LOS
		quad_mod_low_z, quad_arg_low_z, quad_rad_low_z = calc_quad_ratio(norm_strfn_low_z, num_bins)
		quad_mod_high_z, quad_arg_high_z, quad_rad_high_z = calc_quad_ratio(norm_strfn_high_z, 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. This is done for low and high magnetic field 
		# simulations
Пример #5
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
        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
Пример #6
0
        # 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]

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

        #--------------------- Fitting Line of Best Fit ------------------------

        # Extract the slope of the structure function
Пример #7
0
        # 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
        print 'Quad ratio calculated for {}'.format(spec_loc[sim_index])

    # Now that the quadrupole ratios have been calculated, start plotting them
    # all on the same plot

    # Create a figure to display a plot comparing the magnitude of the
    # quadrupole ratios for all of the synchrotron maps, for a line of sight
    # along the x axis.
    fig1 = plt.figure(figsize=(10, 6))

    # Create an axis for this figure
Пример #8
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_y = sf_fft(sync_map_y, no_fluct = True, normalise = True)
	norm_strfn_z = sf_fft(sync_map_z, 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_y = np.fft.fftshift(norm_strfn_y)
	norm_strfn_z = np.fft.fftshift(norm_strfn_z)

	# Calculate the magnitude and argument of the quadrupole ratio
	quad_mod_y, quad_arg_y, quad_rad_y = calc_quad_ratio(norm_strfn_y, num_bins)
	quad_mod_z, quad_arg_z, quad_rad_z = calc_quad_ratio(norm_strfn_z, 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_arr_y[j] = np.trapz(quad_mod_y[11:20], dx = 1.0) / (19 - 11)
	int_quad_arr_z[j] = np.trapz(quad_mod_z[11:20], dx = 1.0) / (19 - 11)

	# Create errors for each of the statistics. These errors are only for the
Пример #9
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_y = sf_fft(sync_map_y, no_fluct=True, normalise=True)
    norm_strfn_z = sf_fft(sync_map_z, 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_y = np.fft.fftshift(norm_strfn_y)
    norm_strfn_z = np.fft.fftshift(norm_strfn_z)

    # Calculate the magnitude and argument of the quadrupole ratio
    quad_mod_y, quad_arg_y, quad_rad_y = calc_quad_ratio(
        norm_strfn_y, num_bins)
    quad_mod_z, quad_arg_z, quad_rad_z = calc_quad_ratio(
        norm_strfn_z, 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_arr_y[j] = np.trapz(quad_mod_y[11:20], dx=1.0) / (19 - 11)
    int_quad_arr_z[j] = np.trapz(quad_mod_z[11:20], dx=1.0) / (19 - 11)
Пример #10
0
		# 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
		print 'Quad ratio calculated for {}'.format(spec_loc[sim_index])

	# Now that the quadrupole ratios have been calculated, start plotting them
	# all on the same plot 

	# Create a figure to display a plot comparing the magnitude of the 
	# quadrupole ratios for all of the synchrotron maps, for a line of sight 
	# along the x axis.
	fig1 = plt.figure(figsize = (10,6))

	# Create an axis for this figure
Пример #11
0
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 
# magnitude of the quadrupole ratio obtained for different gamma on the same 
# plot 

# Create a figure to display a plot comparing the magnitude of the quadrupole 
# ratio for all of the synchrotron maps, i.e. for all gamma
fig1 = plt.figure(figsize = (10,6))

# Create an axis for this figure
ax1 = fig1.add_subplot(111)
Пример #12
0
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
# magnitude of the quadrupole ratio obtained for different gamma on the same
# plot

# Create a figure to display a plot comparing the magnitude of the quadrupole
# ratio for all of the synchrotron maps, i.e. for all gamma
fig1 = plt.figure(figsize=(10, 6))

# Create an axis for this figure
ax1 = fig1.add_subplot(111)
Пример #13
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
Пример #14
0
	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)
	quad_mod_alf, quad_arg_alf, quad_rad_alf = calc_quad_ratio(norm_strfn_alf, num_bins)
	quad_mod_slow, quad_arg_slow, quad_rad_slow = calc_quad_ratio(norm_strfn_slow, num_bins)
	quad_mod_fast, quad_arg_fast, quad_rad_fast = calc_quad_ratio(norm_strfn_fast, num_bins)

	# Add the calculated modulus of the quadrupole ratio to the final array, 
	# for all MHD modes, and for the full turbulence
	quad_arr[0,j] = quad_mod_alf
	quad_arr[1,j] = quad_mod_slow
	quad_arr[2,j] = quad_mod_fast
	quad_arr[3,j] = quad_mod_full

	# Add the radius values used to calculate the quadrupole ratio to the
	# corresponding array, for all MHD modes, and the full turbulence
	quad_rad_arr[0,j] = quad_rad_alf
	quad_rad_arr[1,j] = quad_rad_slow