Esempio n. 1
0
 def get_ppv(self, axis, prefix='ppv_1', ppv_args={}):
     self.get_fits_name('density', axis)
     ds = yt.load(self.enzo_dataset)
     ppv_name_vel = '%s/%s_vel.fits' % (self.fits_dir, prefix)
     ppv_name_yt = '%s/%s_yt.fits' % (self.fits_dir, prefix)
     normal = axis
     if len(glob.glob(ppv_name_yt)) == 0:
         field = ppv_args.get('field', 'density')
         velocity_bounds = ppv_args.get('velocity_bounds',
                                        (-35, 35, 14, 'code_velocity'))
         dims = ppv_args.get('dims', 256)
         cube = PPVCube(ds,
                        normal,
                        "density",
                        velocity_bounds,
                        dims=dims,
                        method='sum')
         cube.write_fits(ppv_name_yt)
         hdu = pyfits.PrimaryHDU(cube.vbins)
         hdulist = pyfits.HDUList([hdu])
         hdulist.writeto(ppv_name_vel, clobber=True)
         print "Wrote", ppv_name_yt
         print "Wrote", ppv_name_vel
     print "Reading", ppv_name_yt
     #self.ppv_name = ppv_name
     self.ppv_name_yt = ppv_name_yt
     ds_cube = yt.load(ppv_name_yt)
     cube_only = np.rot90(
         pyfits.open(ppv_name_yt)[0].data.swapaxes(0, 2), 3)
     vel = pyfits.open(ppv_name_vel)[0].data
     return cube_only, ds_cube, vel
Esempio n. 2
0
def test_ppv():

    np.random.seed(seed=0x4d3d3d3)

    dims = (8, 8, 1024)
    v_shift = 1.0e7 * u.cm / u.s
    sigma_v = 2.0e7 * u.cm / u.s
    T_0 = 1.0e8 * u.Kelvin
    data = {
        "density": (np.ones(dims), "g/cm**3"),
        "temperature": (T_0.v * np.ones(dims), "K"),
        "velocity_x": (np.zeros(dims), "cm/s"),
        "velocity_y": (np.zeros(dims), "cm/s"),
        "velocity_z": (np.random.normal(loc=v_shift.v,
                                        scale=sigma_v.v,
                                        size=dims), "cm/s")
    }

    ds = load_uniform_grid(data, dims)

    cube = PPVCube(ds,
                   "z",
                   "density", (-300., 300., 1024, "km/s"),
                   dims=8,
                   thermal_broad=True)

    dv = cube.dv
    v_th = np.sqrt(2. * kboltz * T_0 / (56. * mh) +
                   2. * sigma_v**2).in_units("km/s")
    a = cube.data.mean(axis=(0, 1)).v
    b = dv * np.exp(-(
        (cube.vmid + v_shift) / v_th)**2) / (np.sqrt(np.pi) * v_th)

    yield assert_allclose_units, a, b, 1.0e-2

    E_0 = 6.8 * u.keV

    cube.transform_spectral_axis(E_0.v, str(E_0.units))

    dE = -cube.dv
    delta_E = E_0 * v_th.in_cgs() / clight
    E_shift = E_0 * (1. + v_shift / clight)

    c = dE * np.exp(-(
        (cube.vmid - E_shift) / delta_E)**2) / (np.sqrt(np.pi) * delta_E)

    yield assert_allclose_units, a, c, 1.0e-2
def test_ppv():

    np.random.seed(seed=0x4d3d3d3)

    dims = (8,8,1024)
    v_shift = 1.0e7*u.cm/u.s
    sigma_v = 2.0e7*u.cm/u.s
    T_0 = 1.0e8*u.Kelvin
    data = {"density":(np.ones(dims),"g/cm**3"),
            "temperature":(T_0.v*np.ones(dims), "K"),
            "velocity_x":(np.zeros(dims),"cm/s"),
            "velocity_y":(np.zeros(dims),"cm/s"),
            "velocity_z":(np.random.normal(loc=v_shift.v,scale=sigma_v.v,size=dims), "cm/s")}

    ds = load_uniform_grid(data, dims)

    cube = PPVCube(ds, "z", "density", (-300., 300., 1024, "km/s"),
                   dims=8, thermal_broad=True)

    dv = cube.dv
    v_th = np.sqrt(2.*kboltz*T_0/(56.*mh) + 2.*sigma_v**2).in_units("km/s")
    a = cube.data.mean(axis=(0,1)).v
    b = dv*np.exp(-((cube.vmid+v_shift)/v_th)**2)/(np.sqrt(np.pi)*v_th)

    yield assert_allclose_units, a, b, 1.0e-2

    E_0 = 6.8*u.keV

    cube.transform_spectral_axis(E_0.v, str(E_0.units))

    dE = -cube.dv
    delta_E = E_0*v_th.in_cgs()/clight
    E_shift = E_0*(1.+v_shift/clight)

    c = dE*np.exp(-((cube.vmid-E_shift)/delta_E)**2)/(np.sqrt(np.pi)*delta_E)

    yield assert_allclose_units, a, c, 1.0e-2
Esempio n. 4
0
def test_ppv_nothermalbroad():

    np.random.seed(seed=0x4d3d3d3)

    dims = (16, 16, 128)
    v_shift = 1.0e6*u.cm/u.s
    sigma_v = 2.0e6*u.cm/u.s
    data = {"density":(np.ones(dims),"g/cm**3"),
            "velocity_x":(np.zeros(dims),"cm/s"),
            "velocity_y":(np.zeros(dims),"cm/s"),
            "velocity_z":(np.random.normal(loc=v_shift.v,scale=sigma_v.v,size=dims), "cm/s")}

    ds = load_uniform_grid(data, dims)

    cube = PPVCube(ds, "z", "density", (-100., 100., 128, "km/s"),
                   dims=16, thermal_broad=False)

    dv = cube.dv
    v_noth = np.sqrt(2)*(sigma_v).in_units("km/s")
    a = cube.data.mean(axis=(0,1)).v
    b = dv*np.exp(-((cube.vmid+v_shift)/v_noth)**2)/(np.sqrt(np.pi)*v_noth)

    assert_allclose_units(a, b, atol=5.0e-3)
Esempio n. 5
0
execfile('go')
def fake_temp(field,data):
    return data.ds.arr(np.ones_like(data['density'].v)*10,'K')

yt.add_field('temperature',function=fake_temp,units='K')
from yt.analysis_modules.ppv_cube.api import PPVCube
velocity_bounds = (-70,70,128,'code_velocity')
dims = 256
normal = [0,0,-1]
normal = 'x'
ds = yt.load('/scratch1/dcollins/Paper08/B02/256/RS0050/restart0050')
cube = PPVCube(ds, normal, "density", velocity_bounds,dims=dims, method='sum')
print "nans", np.isnan(cube[:]).sum()
Esempio n. 6
0
def fake_temp(field,data):
    return data.ds.arr(np.ones_like(data['density'].v)*10,'K')

yt.add_field('temperature',function=fake_temp,units='K')

if 0:

    simname = 'B02'
    resolution = 256
    frame = 30
    dirname = '/scratch1/dcollins/Paper08/%s/%d/RS%04d/restart%04d'%(simname,resolution,frame,frame)

    ds = yt.load(dirname)
    ds.index.grids[0]['temperature']
    L = [0,0,1]
    cube = PPVCube(ds, L, "density", (-150.,150.,50,"code_velocity"), dims=200, method="sum")

if 0:
    for n,v in enumerate(cube.vmid):
#       if n not in [20,21]:
#           continue
        plt.clf()
        plt.imshow(np.log10(cube[:,:,n].v),cmap='jet',origin='lower',interpolation='nearest')
        plt.text(0,0,r'$%0.2f \rm{km}/\rm{s}$'%v)
        cb=plt.colorbar()
        cb.cmap.set_under('w')
        cb.cmap.set_bad('w')
        outname = 'p14b_tmp_slice%04d.png'%n
        plt.savefig(outname)
        print outname