def plot_dist(fig, ax,P,coods,cmap,
              vmin=1e-4,vmax=None,extent=300,
              p=0,t=0,roll=0):
 
    C = sph.Camera(x=coods[0], y=coods[1], z=coods[2], 
                   r='infinity', zoom=1,
                   t=t, p=p, roll=roll,
                   extent=[-extent,extent,-extent,extent],
                   xsize=512, ysize=512)
 
    S = sph.Scene(P, Camera=C)
    R = sph.Render(S)
    #R.set_logscale()
    img = R.get_image()
    # img = img / img.mean()

    if vmax is None:    
        vmax = img.max()

    if vmin > vmax:
        print("vmin larger than vmax! Setting lower")
        vmin = img.max() / 10
    print("vmin,vmax:",vmin,vmax)
    
    cNorm  = colors.LogNorm(vmin=vmin,vmax=vmax)
    sm = cm.ScalarMappable(norm=cNorm, cmap=cmap)

    ax.imshow(img, extent=[-extent,extent,-extent,extent],
              cmap=cmap, norm=cNorm)

    return sm,img
Ejemplo n.º 2
0
t = 0  #np.arctan(s[0]/s[2]) * 180./np.pi
p = 0  #np.arctan(s[1]/s[2]) * 180./np.pi

## Create particle and camera objects

dx = 3
norm_coods = coods - [a, b, c]
coods_mask = (norm_coods[:,0] < dx) & (norm_coods[:,0] > -dx) &\
             (norm_coods[:,1] < dx) & (norm_coods[:,1] > -dx) &\
             (norm_coods[:,2] < dx) & (norm_coods[:,2] > -dx)

C = sph.Camera(x=0,
               y=0,
               z=0,
               r='infinity',
               extent=[-dx, dx, -dx, dx],
               t=t,
               p=p,
               roll=0,
               xsize=4000,
               ysize=2250)

# Gas density
P = sph.Particles(norm_coods[coods_mask],
                  pmass[coods_mask] / pmass[coods_mask].min())
# hsml = hsml * 10)# * 2)

hsml = P.get_hsml()

## Create scene and render
S = sph.Scene(P, Camera=C)
R = sph.Render(S)
        ext = 500  # number of pixels in image
        convers = ext / (2 * dl)  # conversion factor

        P = sph.Particles(pgas[pmask], mass=np.ones(np.sum(pmask)))

        fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15, 7))

        for ax, t, p, c1, c2 in zip([ax1, ax2, ax3], [0, 0, 90], [0, 90, 90],
                                    [0, 2, 2], [1, 1, 0]):

            C = sph.Camera(r='infinity',
                           t=t,
                           p=p,
                           roll=0,
                           xsize=ext,
                           ysize=ext,
                           x=c[0],
                           y=c[1],
                           z=c[2],
                           extent=[-dl, dl, -dl, dl])

            S = sph.Scene(P, C)
            R = sph.Render(S)
            img = np.log10(R.get_image())
            extent = R.get_extent()
            ax.imshow(img, cmap=cmaps.twilight())


        ax1.text(0.1,0.9,'$\mathrm{log_{10}}(M_{\star} \,/\, \mathrm{M_{\odot}}) = %.2f$'%\
                 np.log10(mstar["%02d"%region][tag][_idx] * 1e10),
                 transform=ax1.transAxes)
_coods = np.squeeze(np.array([_x, _z, _y])).T

radius = 15  # kpc
mask = _radius < radius
print("radius:", radius)
print("mass weighted temp:",
      np.sum((_temp * _mass)[mask]) / np.sum(_mass[mask]))

extent = 15
img = [None, None]
for i, _weight in enumerate([_temp, _temp * (_mass / 1.99e38)]):
    Pd = sph.Particles(_coods, _weight)  # halog_dust[mask] * 1e10)
    C = sph.Camera(x=0,
                   y=0,
                   z=0,
                   r='infinity',
                   zoom=1,
                   extent=[-extent, extent, -extent, extent],
                   xsize=512,
                   ysize=512)
    S = sph.Scene(Pd, Camera=C)
    R = sph.Render(S)
    # R.set_logscale()
    img[i] = R.get_image()

#if vmax is None:
#    vmax = img.max()
#
#if vmin > vmax:
#    print("vmin larger than vmax! Setting lower")
#    vmin = img.max() / 10
#print("vmin,vmax:",vmin,vmax)
Ejemplo n.º 5
0
## Align with spin axis of galaxy

s = spin[idx]
t = np.arctan(s[0] / s[2]) * 180. / np.pi
p = np.arctan(s[1] / s[2]) * 180. / np.pi

## Create particle and camera objects
scaling = 1
P = sph.Particles(np.array(coods - [a, b, c]) * scaling, np.ones(len(coods)))

C = sph.Camera(x=0,
               y=0,
               z=0,
               r=1,
               zoom=1,
               t=t,
               p=p,
               roll=0,
               xsize=4000,
               ysize=2250)  # 16:9

S = sph.Scene(P, Camera=C)

## loop round object
for i in nrange:

    print("p = %s" % i)
    sys.stdout.flush()

    ## update scene camera
    S.update_camera(p=i)
Ejemplo n.º 6
0
def plot_parent(i, P, n, res, centre, z_centre):
    print("i:", i)
    sys.stdout.flush()
    cmap = cmaps.twilight()

    f = modified_sigmoid(i / n, 3)
    L, l = 3300 / 2, 50
    dl = L * (1 - f) + l * f
    R = 16. / 9
    offset = 100
    dx = dl * R
    dy = dl

    ext_x = 3200 / 2
    ext_y = 3200 / 2
    if ext_x > dx: ext_x = dx
    if ext_y > dy: ext_y = dy

    C = sph.Camera(r='infinity',
                   t=0,
                   p=0,
                   roll=0,
                   xsize=res,
                   ysize=res,
                   x=centre,
                   y=centre,
                   z=z_centre,
                   extent=[-ext_x, ext_x, -ext_y, ext_y])

    S = sph.Scene(P, C)
    R = sph.Render(S)
    extent = R.get_extent()
    img = np.log10(R.get_image())
    print(img.max(), img.min())

    fig = plt.figure(figsize=(16, 9))
    ax = fig.add_axes([0, 0, 1, 1])

    # ax.imshow(img, cmap=cmap, vmin=-0.05, vmax=1.2, extent=extent,aspect='equal')
    ax.imshow(img,
              cmap=cmap,
              vmin=--1,
              vmax=2.4,
              extent=extent,
              aspect='equal')

    del (img)
    del (C)

    ax.set_facecolor(cmap(0.0))
    ax.set_xlim(-dx, dx)
    ax.set_ylim(-dy, dy)

    ax.hlines(0.9, 0.092, 0.192, transform=ax.transAxes, color='red', lw=2)
    ax.text(0.1,
            0.94,
            '$%i \; \mathrm{cMpc}$' % (dx * 0.2),
            transform=ax.transAxes,
            size=12,
            color='black')

    rect = patches.Rectangle((0.09, 0.92),
                             0.105,
                             0.065,
                             linewidth=1,
                             edgecolor='none',
                             facecolor='white',
                             alpha=0.5,
                             transform=ax.transAxes)

    ax.add_patch(rect)

    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)

    # plt.show()
    fname = 'plots/parent_zoom/parent_zoom_%03d.png' % i
    # plt.gca().set_axis_off()
    # plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0,
    #                     hspace = 0, wspace = 0)
    # plt.margins(0,0)
    print(fname)
    fig.savefig(fname, dpi=150)  #, bbox_inches='tight', pad_inches = 0)
    plt.close(fig)