Beispiel #1
0
def load_slices(z=0):
    global data
    camera = Camera(center=[0.5, 0.5, 0.5], line_of_sight_axis='z', region_size=[1., 1.])
    points = camera.get_slice_points(z)
    data = sample_points(grid, points)
    #print data
    return data
Beispiel #2
0
def load_slices(z=0):
    global data
    camera = Camera(center=[0.5, 0.5, 0.5],
                    line_of_sight_axis='z',
                    region_size=[1., 1.])
    points = camera.get_slice_points(z)
    data = sample_points(grid, points)
    return data
Beispiel #3
0
def load_slices(z=0.0, size=10):
    global data
    map_size = 2**size
    camera = Camera(center=[0.5, 0.5, z], line_of_sight_axis='z', region_size=[1., 1.], map_max_size=map_size)
    points = camera.get_slice_points(0.0)
    data = sample_points(grid, points)
    #print data
    return data
Beispiel #4
0
def load_slices(z=0.0, size=10):
    global data
    map_size = 2**size
    camera = Camera(center=[0.5, 0.5, z],
                    line_of_sight_axis='z',
                    region_size=[1., 1.],
                    map_max_size=map_size)
    points = camera.get_slice_points(0.0)
    data = sample_points(grid, points)
    #print data
    return data
Beispiel #5
0
def test_cyl_profile():
    # Galactic cylinder parameters
    gal_center = [0.567811, 0.586055, 0.559156]  # in box units
    gal_radius = 0.00024132905460547268  # in box units
    gal_thickn = 0.00010238202316595811  # in box units
    gal_normal = [-0.172935, 0.977948, -0.117099]  # Norm = 1

    # RamsesOutput
    ro = RamsesOutput("/data/Aquarius/output", 193)

    # Prepare to read the density field only
    source = ro.amr_source(["rho"])

    # Cylinder region
    cyl = Cylinder(gal_center, gal_normal, gal_radius, gal_thickn)

    # AMR density field point sampling
    numpy.random.seed(1652336)
    points = cyl.random_points(1.0e6)  # 1M sampling points
    point_dset = sample_points(source, points)
    rho_weight_func = lambda dset: dset["rho"]
    r_bins = numpy.linspace(0.0, gal_radius, 200)

    # Profile computation
    rho_profile = bin_cylindrical(point_dset,
                                  gal_center,
                                  gal_normal,
                                  rho_weight_func,
                                  r_bins,
                                  divide_by_counts=True)

    # Plot
    # Geometrical midpoint of the bins
    length = ro.info["unit_length"].express(C.kpc)
    bins_centers = (r_bins[1:] + r_bins[:-1]) / 2. * length
    dens = ro.info["unit_density"].express(C.H_cc)

    #h5f = tables.openFile("./long_tests/cyl_profile.h5", mode='w')
    #h5f.createArray("/", "cyl_profile", rho_profile)
    #h5f.close()

    h5f = tables.openFile("./long_tests/cyl_profile.h5", mode='r')
    rho_profileB = h5f.getNode("/cyl_profile").read()
    h5f.close()

    print(rho_profile)
    assert sum(rho_profile - rho_profileB) < 10e-6
Beispiel #6
0
def main():

	# Defaults
	iout = 1
	npsample = ['128', '128', '64']
	npbin = ['32', '32']

	# Parse Arguments
	if len(sys.argv) == 4:
		npbin = re.split(',', sys.argv[3])
	if len(sys.argv) >= 3:
		npsample = re.split(',', sys.argv[2])
	if len(sys.argv) >= 2:
		iout = int(sys.argv[1])

	# Compute Requested Outputs
	if iout < 0:
		iouts = range(1, abs(iout) + 1)
	else:
		iouts = range(iout, iout + 1)

	# Define Region of Interest (Box Units)
	center    = 0.5
	radius    = 0.4
	thickness = 0.2

	# Sample Points
	nr   = int(npsample[0])
	nphi = int(npsample[1])
	nz   = int(npsample[2])

	# Binning Points
	nrbins = int(npbin[0])
	nzbins = int(npbin[1])

	# Give Feedback
	print "Computing RZ Profile(s) for Output(s) %s." % iouts
	print "Sampling Grid with %ix%ix%i = %i Points." % ( nr, nphi, nz, nr * nphi * nz )
	print ""

	# Generate Sampling Points
	x, y, z = mkpoints_rpz(center, radius, thickness, nr, nphi, nz)

	# Make Sampling Vectors, Reshape Them
	xx, yy, zz = mkvec(x, y, z)
	points = np.zeros((xx.shape[0], 3))
	for ii in range(xx.shape[0]):
		points[ii,:] = np.array([xx[ii], yy[ii], zz[ii]])

	# Loop Desired Outputs
	for iiout in iouts:

		# Link AMR Data
		output = RamsesOutput(".", iiout)
		source = output.amr_source(["rho"])

		# Sample AMR Data
		point_dset = sample_points(source, points)

		# Shift Origin, Convert to RZ Coordinates
		points_xyz  = points
		points_xyz0 = points_xyz - 0.5
		points_r0   = np.sqrt(points_xyz0[:,0]**2. + points_xyz0[:,1]**2.)
		points_z0   = points_xyz0[:,2]

		print ""
		print "Binning onto (RxZ) = (%ix%i) Grid." % ( nrbins, nzbins )

		# Prepare Bins
		rbins = np.linspace(0.0, radius, nrbins + 1)
		zbins = np.linspace(-thickness/2., thickness/2., nzbins + 1)

		# Binning Routine
		rhoRZ, rbins, zbins = prof2d(points_r0, points_z0, point_dset["rho"], rbins, zbins)

		# Compute Extent
		ext = np.array([rbins.min(), rbins.max(), -thickness/2., thickness/2.])

		# Save Binned Data
		fname = 'rhoRZ_%i.npz' % iiout

		print ""
		print "Saving Data to File %s..." % fname

		# Save Binned Data
		np.savez(fname,\
			rhoRZ=rhoRZ, rbins=rbins, zbins=zbins,\
			iout=iiout,\
			boxlen=output.info["boxlen"],\
			tout=output.info["time"],\
			ext=ext,
			center=center, radius=radius, thickness=thickness,\
			nr=nr, nphi=nphi, nz=nz,\
			nrbins=nrbins, nzbins=nzbins)

		print "Done."
Beispiel #7
0
def main():

    # Set Defaults
    iout = 1
    npsample = ['128', '128', '64']

    # Parse Arguments
    if len(sys.argv) == 3:
        npsample = re.split(',', sys.argv[2])
    if len(sys.argv) >= 2:
        iout = int(sys.argv[1])

    # Compute Requested Outputs
    if iout < 0:
        iouts = range(1, abs(iout) + 1)
    else:
        iouts = range(iout, iout + 1)

    # Define Region of Interest (Box Units)
    center    = 0.5
    radius    = 0.4
    thickness = 0.2

    # Sample Points
    nx = int(npsample[0])
    ny = int(npsample[1])
    nz = int(npsample[2])

    # Generate Sampling Points
    x, y, z = mkpoints_xyz(center, radius, thickness, nx, ny, nz)

    # Some Reshaping
    zz, yy, xx = mkvec(z, y, x)
    points = np.zeros((xx.shape[0], 3))
    for ii in range(xx.shape[0]):
        points[ii,:] = np.array([xx[ii], yy[ii], zz[ii]])

    # Loop Over Outputs
    for iiout in iouts:

        # Open Ramses Output
        output = RamsesOutput(".", iiout)
        source = output.amr_source(["P"])

        # Fetch Ramses Data
        points_dset = sample_points(source, points)

        # Allocate Memory for Output Array
        PXY = np.zeros((nx, ny))

        # Integrate Along Z (Simpson's Rule)
        print "(%s UTC) Integrating..." % strftime("%H:%M:%S", gmtime())
        idx_lo = 0
        for ix in range(nx):
            for iy in range(ny):
                idx_hi = idx_lo + nz
                PXY[ix,iy] = simps(points_dset["P"][idx_lo:idx_hi], z)
                idx_lo = idx_hi
        print "(%s UTC) Done Integrating." % strftime("%H:%M:%S", gmtime())

        # Compute Limits, Centre, Rescale
        ext = np.array([x.min(), x.max(), y.min(), y.max()])
        ext = ( ext - 0.5 ) * output.info["boxlen"]

        # Save 2D Pressure Map
        np.savez('PXY_%i.npz' % iiout, \
            PXY=PXY,\
            x=x, y=y, z=z,\
            boxlen=output.info["boxlen"],\
            ext=ext,\
            tout=output.info["time"])
Beispiel #8
0
def main():

    # Set Defaults
    iout = 1
    npsample = ['128', '128', '64']

    # Parse Arguments
    if len(sys.argv) == 3:
        npsample = re.split(',', sys.argv[2])
    if len(sys.argv) >= 2:
        iout = int(sys.argv[1])

    # Compute Requested Outputs
    if iout < 0:
        iouts = range(1, abs(iout) + 1)
    else:
        iouts = range(iout, iout + 1)

    # Define Region of Interest (Box Units)
    center    = 0.5
    radius    = 0.4
    thickness = 0.2

    # Sample Points
    nx = int(npsample[0])
    ny = int(npsample[1])
    nz = int(npsample[2])

    # Generate Sampling Points
    x, y, z = mkpoints_xyz(center, radius, thickness, nx, ny, nz)

    # Some Reshaping
    zz, yy, xx = mkvec(z, y, x)
    points = np.zeros((xx.shape[0], 3))
    for ii in range(xx.shape[0]):
        points[ii,:] = np.array([xx[ii], yy[ii], zz[ii]])

    # Loop Over Outputs
    for iiout in iouts:

        # Open Ramses Output
        output = RamsesOutput(".", iiout)
        source = output.amr_source(["rho", "vel"])

        # Fetch Ramses Data
        points_dset = sample_points(source, points)

        # Allocate Memory for Output Array
        OmegaXY = np.zeros((nx, ny))

        # Average Along Z
        print "(%s UTC) Z-Averaging XY Velocity Field..." % strftime("%H:%M:%S", gmtime())
        idx_lo = 0
        for ix in range(nx):
            for iy in range(ny):
                idx_hi = idx_lo + nz
                v_x = points_dset["vel"][idx_lo:idx_hi,0]
                v_y = points_dset["vel"][idx_lo:idx_hi,1]
                v_xy = np.sqrt(v_x**2. + v_y**2.)
                rho_tot = np.sum(points_dset["rho"][idx_lo:idx_hi])
                weight = points_dset["rho"][idx_lo:idx_hi] / rho_tot
                v_xy_avg = np.sum(v_xy * weight) / nz
                r = np.sqrt((x[ix] - 0.5)**2. + (y[iy]-0.5)**2.) * output.info["boxlen"]
                OmegaXY[ix,iy] = v_xy_avg / r
                idx_lo = idx_hi
        print "(%s UTC) Done Averaging." % strftime("%H:%M:%S", gmtime())

        # Compute Limits, Centre, Rescale
        ext = np.array([x.min(), x.max(), y.min(), y.max()])
        ext = ( ext - 0.5 ) * output.info["boxlen"]

        # Save Z-Averaged Planar Angular Velocity Map
        np.savez('OmegaXY_%i.npz' % iiout, \
            OmegaXY=OmegaXY,\
            x=x, y=y, z=z,\
            boxlen=output.info["boxlen"],\
            ext=ext,\
            tout=output.info["time"])
Beispiel #9
0
gal_normal = [ 0.000094, 0.011879 , 0.999929]


from pymses import RamsesOutput
output = RamsesOutput("/home/ankit/ramses/trunk/old_run/17May2016/lambda0.1",4)

source = output.amr_source(["rho"])


from pymses.utils.regions import Cylinder
cyl = Cylinder(gal_center, gal_normal, gal_radius, gal_thickn)

from pymses.analysis import sample_points
points = cyl.random_points(1.0e4) # 1M sampling points
point_dset = sample_points(source, points)

import numpy
rho_weight_func = lambda dset: dset["rho"]
r_bins = numpy.linspace(0.0, gal_radius, 200)


from pymses.analysis import bin_cylindrical
rho_profile = bin_cylindrical(point_dset, gal_center, gal_normal,rho_weight_func, r_bins, divide_by_counts=True)


 
m=np.linspace(0.0,gal_radius, num=199)*output.info["unit_length"].express(C.kpc)

"""print rho_profile.shape
print m.shape