コード例 #1
0
ファイル: euler_3dPlot_2.py プロジェクト: hongzhan2015/cryoet
def main():
    file_angles = sys.argv[1]
    angles = np.loadtxt(file_angles, delimiter=",")
    ptl = len(angles)
    h = special.spherical_histogram(angles, theta_bins=16, phi_bins=16)
    globe = h.projection("theta", "phi")
    p = globe.plot.globe_map(density=True, figsize=(5, 5), cmap="Reds")
    cbar = plt.colorbar(p)

    plt.show()
コード例 #2
0
def main():
    file_angles = sys.argv[1]
    angles = np.loadtxt(file_angles, delimiter=",")
    X = angles[:, 0]
    Y = angles[:, 1]
    Z = angles[:, 2]
    h = special.spherical_histogram(angles, theta_bins=20, phi_bins=20)
    globe = h.projection("theta", "phi")
    m = np.amax(globe.bins)
    n = np.amin(globe.bins)
    norm = mpl.colors.Normalize(vmin=n, vmax=m)
    ax = globe.plot.globe_map(density=True, figsize=(7, 7), cmap="Reds")
    plt.colorbar(cm.ScalarMappable(norm=norm, cmap="Reds"), ax=ax)
    plt.show()
コード例 #3
0
ファイル: test_special.py プロジェクト: janpipek/physt
 def test_projection_types(self):
     h = special.spherical_histogram([[1, 2, 3], [2, 3, 4]])
     assert special.DirectionalHistogram == type(h.projection("phi", "theta"))
     assert special.DirectionalHistogram == type(h.projection("theta", "phi"))
コード例 #4
0
 def test_projection_types(self):
     h = special.spherical_histogram([[1, 2, 3], [2, 3, 4]])
     assert special.DirectionalHistogram == type(
         h.projection("phi", "theta"))
     assert special.DirectionalHistogram == type(
         h.projection("theta", "phi"))
コード例 #5
0
def Project_Flux(particle_array,bins=240):
	"""
	Sorts particles from continuous, single pulsar case into
	Right Ascension & Declination coordinates, then creates
	a flux density map using a Mollweide projection.

	Parameters
	----------
	particle_array	: 4D array, float
			  Contains all particle coordinate
			  data in shape (tbins,ebins,N,3),
			  which sorts by time of packet
			  injection, energy of each distribution
			  per packet, each particle for each
			  distribution for each injection time,
			  and (x,y,z) positions for each.
	Returns
	-------
	"""


	## Saves the number of energy and time bins dependent on dimension of particle array
	tbins = np.size(particle_array,0)
	ebins = np.size(particle_array,1)
	N = len(particle_array[0][0][:,0])
	
	## particle_array was calculated in the pulsar-frame; we convert to the earth frame by getting the (x,y,z) distance to the pulsar
	transformed_array = np.zeros((ebins,N*tbins,3))

	## We construct grid of RA and Dec coordinates for our flux density map
	ra  = np.linspace(-180., 180., 1000)
	dec = np.linspace(-90., 90., 1000)
	X,Y = np.meshgrid(ra,dec)

	E_label = [100,500,1000]
	
	for EE in range(ebins):
		## Resort our particle_array in Earth frame, flattening the time bins
		for TT in range(tbins):
			transformed_array[EE][TT*N:(TT+1)*N,0] = particle_array[TT][EE][:,0] 
			transformed_array[EE][TT*N:(TT+1)*N,1] = particle_array[TT][EE][:,1]
			transformed_array[EE][TT*N:(TT+1)*N,2] = particle_array[TT][EE][:,2]

		## Spherically bin the transformed data, then create a 2D (theta, phi) projection
		h = special.spherical_histogram(transformed_array[EE])
		globe = h.projection("theta","phi")

		## We get the centers of each angular bin, and convert from (theta, phi) to (RA, Dec)
		ra_centers   = get_bin_centers(globe.numpy_bins[1]) * (180./np.pi) - 180.
		dec_centers = get_bin_centers(globe.numpy_bins[0]) * (180./np.pi) - 90.

		## Frequencies are the counts, and bin sizes normalizes counts based on the area of the bin (which are irregular in spherical coordinates)
		counts = globe.frequencies/globe.bin_sizes

		## Create an interpolation function based on the counts in each bin, then evaluate it on our RA/Dec grid
		IntFlux = interp2d(ra_centers,dec_centers,counts,kind='linear')
		Z = IntFlux(ra,dec)

		## Creates a flux density plot in RA/Dec coordinates on a Mollweide map
		m = Basemap(projection='moll',lon_0=0.,resolution='c')
		m.drawparallels(np.arange(-90.,91.,30.),labels=[True,True,False,False],dashes=[2,2])
		m.drawmeridians(np.arange(-180.,181.,60.),labels=[True,True,True,True],dashes=[2,2])
		m.contourf(X,Y,Z, 40,cmap=plt.cm.plasma,latlon=True)
		m.colorbar(label='Unnormalized Electron Column Density')
		plt.title(r'Galactic PWNe Spectra, $N = %s$, $E = %s$ GeV' % (100,E_label[EE]))
		fn = "ecd_map_" + str(E_label) + "gev_" + str(N) + "n.pdf"
		plt.savefig(fn)
		plt.show()
	
	return
コード例 #6
0
def count_angular(props):
    N_frames = 0
    g_ref = sel[props['ref']]
    print("Reference COM: {}".format(props['ref']))
    bins, all_dens = [], []
    for target in props['targets']:
        g_target = sel[target]
        print("Current target: {}".format(target))
        count = []
        for ts in U.trajectory:
            if ts.time >= props['start_ps'] and ts.time % props['dt'] == 0:
                N_frames += 1
                #print(ts.time)
                x_target = np.subtract(g_target.positions,
                                       g_ref.center_of_mass())
                dists = np.linalg.norm(x_target, axis=1)
                count += list(x_target[dists <= props['d_max']].flatten())
            if ts.time >= props['stop_ps']:
                break
        count = np.array(count).reshape((len(count) // 3, 3))
        h = special.spherical_histogram(count, theta_bins=props['bins'])
        h = h.projection('theta')
        counts = h.frequencies / N_frames
        N_counts = np.sum(counts)
        vols = 2. * np.pi / 3 * (props['d_max'] / 10)**3 * (
            np.cos(h.numpy_bins[:-1]) - np.cos(h.numpy_bins[1:]))
        densities = np.divide(counts, vols)
        all_dens.append(densities)
        print("Average counts: {:.2f}".format(N_counts))

        if props['plot']:
            homo_dens = 3. * N_counts / (4 * np.pi *
                                         (props_count['d_max'] / 10)**3)
            print(homo_dens)
            db = h.numpy_bins[1] - h.numpy_bins[0]

            x0, y0 = props_count['res'] / 2, props_count['res'] / 2
            v0 = np.array([x0, y0])
            space = np.full((props_count['res'], props_count['res']),
                            homo_dens)
            thetas = []
            for y in range(props_count['res']):
                for x in range(props_count['res']):
                    v = np.array([x, y]) - v0
                    r = np.linalg.norm(v)
                    if r < props_count['res'] / 2 and r != 0:
                        th = np.arccos(v[1] / r)
                        thetas.append(th)
                        space[y, x] = densities[int((th % np.pi) // db) - 1]

            f_pm = 0.4
            fig = plt.figure()
            ax = plt.axes()
            cax = ax.imshow(space,
                            vmin=(1 - f_pm) * homo_dens,
                            vmax=(1 + f_pm) * homo_dens,
                            interpolation='bilinear',
                            cmap='bwr')
            cbar = fig.colorbar(cax,
                                ticks=[(1 - f_pm) * homo_dens, homo_dens,
                                       (1 + f_pm) * homo_dens])
            cbar.ax.set_yticklabels([
                '-{:.0f}%'.format(f_pm * 100), 'Uniform',
                '+{:.0f}%'.format(f_pm * 100)
            ])
            cbar.ax.tick_params(labelsize=z)
            plt.show()

    all_dens = np.array(all_dens).T

    return h.numpy_bins[:-1], all_dens  #h.numpy_bins go from 0 - pi