def make_image(self, image_name="output.fits", npix=600, phi=0.0, convolve=False): inclination = self.parameters["inclination"] posang = self.parameters["posang"] wavelength = self.parameters["wavelength"] print(self.domain_size()) image.makeImage(npix=npix, incl=inclination, posang=posang, phi=phi, wav=wavelength, binary=True, sizeau=self.domain_size()) # This calls radmc3d im = image.readImage(binary=True) self.parameters["sizepix_x"] = im.sizepix_x self.parameters["sizepix_y"] = im.sizepix_y if len(im.x) == 0: raise RuntimeError("Image creation failed, image is empty") if convolve: im = im.imConv(fwhm=1e-3 * np.array(self.parameters["beam_fwhm"]), pa=1e-3 * self.parameters["beam_posang"], dpc=self.parameters["distance"]) im.raw_input = lambda s: "y" image.plotImage(im, log=True, maxlog=2, dpc=101.0, cmap='inferno')
import radmc3dPy.image as image import matplotlib.pyplot as plt import numpy as np i = 7 dist = 5410. #lambdas = np.array([ 37500., 20000., 13043.47826087, 9375., 7142.85714286, # 5454.54545455, 4285.71428571, 3529.41176471]) #en GHz: np.array([8,15,23,32,42,55,70,85])*1. GHz. im = image.readImage() #image.plotImage(im, au=True, log=True, maxlog=10, saturate=1e-5, cmap=plt.cm.gist_heat) """ image.plotImage(im, dpc=140, arcsec=True, log=True, maxlog=10, saturate=1e-5, cmap=plt.cm.gist_heat) image.plotImage(im, dpc=dist, arcsec=True, log=True, maxlog=10, saturate=1e-5, cmap=plt.cm.gist_heat) cim = im.imConv(fwhm=[1.0, 0.6], pa=120., dpc=dist) image.plotImage(cim, arcsec=True, dpc=dist, log=True, maxlog=10, bunit='snu', cmap=plt.cm.gist_heat) """ im.writeFits('img_shell.fits', dpc=5410.) #, coord='03h10m05s -10d05m30s') #Mirar lo de inputs desde terminal
def getOutput_im(ifreq, dis, im, optim, tauim, polunitlen, fkabs, fksca,pngname, polmax=None, imUnits='Tb', imlim=None, xlim=None, ylim=None, axisUnits='au', opltr=None, inc=None): """ calculates image xlim : tuple ylim : tuple axisUnits = 'cm', 'arcsec', 'AU' """ # determine if there is stokes data dostokes = False if im.stokes: if im.image[:,:,1,ifreq].max() == 0 and im.image[:,:,2,ifreq].max() ==0: dostokes = False else: dostokes = True # image, polarized intensity, pol frac, tau, optical depth, pol vectors nsub = 1 #image if dostokes: # polarized intensity nsub = nsub + 1 if dostokes: # polarization fraction nsub = nsub + 1 if optim is not None: nsub = nsub + 1 if tauim is not None: nsub = nsub + 1 if dostokes: #vectors nsub = nsub + 1 # axis units if axisUnits.lower() == 'cm': axis_au = False axis_arcsec = False elif axisUnits.lower() == 'arcsec': axis_au = False axis_arcsec = True elif axisUnits.lower() == 'au': axis_au = True axis_arcsec = False else: raise ValueError('axisUnits not understood') nrow = np.floor(np.sqrt(nsub)) ncol = np.ceil(nsub / nrow) nrow, ncol = int(nrow), int(ncol) fig, axgrid = plt.subplots(nrows=nrow, ncols=ncol, figsize=(4*ncol, 3*nrow), sharex=True, sharey=True, squeeze=False) axes = axgrid.flatten() isubplot = 0 # image if imlim is not None: imvmin, imvmax = imlim[0], imlim[1] else: imvmin, imvmax = 0, None ax = axes[isubplot] image.plotImage(image=im, cmap=plt.cm.jet, interpolation='bilinear', arcsec=axis_arcsec, au=axis_au, dpc=dis, oplotbeam='w', stokes='I', bunit=imUnits,ifreq=ifreq, saturate='90percent', clevs=[1, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200], clcol='w', vmin=imvmin, vmax=imvmax, ax=ax) if im.stokes is True: image.plotPolDir(image=im, arcsec=False, au=True, dpc=dis, color='w', nx=16, ny=16, polunitlen=polunitlen, ifreq=ifreq, ax=ax) isubplot = isubplot + 1 # # polarized intensity if dostokes: #ax = fig.add_subplot(nrow,ncol,isubplot) ax = axes[isubplot] image.plotImage(image=im, cmap=plt.cm.jet, interpolation='bilinear', arcsec=axis_arcsec, au=axis_au, dpc=dis, oplotbeam='w', stokes='PI', bunit=imUnits,ifreq=ifreq, saturate='90percent', clevs=[0, 1.0, 10., 100., 200., 500.], clcol='w', ax=ax) isubplot = isubplot + 1 # polarized degree if dostokes: #ax = fig.add_subplot(nrow,ncol,isubplot) ax = axes[isubplot] image.plotImage(image=im, cmap=plt.cm.jet, interpolation='bilinear', arcsec=axis_arcsec, au=axis_au, dpc=dis, ifreq=ifreq, saturate='100percent', stokes='P',bunit='percent' , vmin=0, vmax=polmax, clevs=[1., 5.0, 10., 20.], clcol='k', ax=ax) isubplot = isubplot + 1 # optical depth if optim is not None: ax = axes[isubplot] kext = fkabs(im.wav[ifreq]) + fksca(im.wav[ifreq]) image.plotImage(image=optim, cmap=plt.cm.jet, interpolation='bilinear', arcsec=axis_arcsec, au=axis_au, dpc=dis, ifreq=ifreq, saturate='100percent', stokes='I', bunit='optdepth', clevs=[0.1,1.,5., 10.,100.], clcol='w', ax=ax ) isubplot = isubplot + 1 # tau image if tauim is not None: ax = axes[isubplot] reg = tauim.image[:,tauim.ny/2,0,ifreq] > tauim.image.min() if True in reg: xmax = tauim.x[reg].max()/natconst.au vmax = tauim.image[:,:,0,ifreq].max()/natconst.au else: xmax = tauim.x.max()/natconst.au vmax = tauim.image[:,:,0,:].max()/natconst.au # tausurface image.plotImage(image=tauim, cmap=plt.cm.jet, interpolation='bilinear', arcsec=axis_arcsec, au=axis_au, dpc=dis, stokes='I', bunit='length', ifreq=ifreq, vmin=-vmax, vmax=vmax, ax=ax) nx = int(2.*tauim.x.max()/natconst.au / (xmax / 8)) if (nx % 2) == 1: nx = nx + 1 if nx > 50: nx = 50 ny = nx # polarization vectors image.plotPolDir(image=im, arcsec=axis_arcsec, au=axis_au, dpc=dis, color='k', nx=nx, ny=ny, polunitlen=polunitlen, ifreq=ifreq, ax=ax) ax.set_xlim(-xmax, xmax) ax.set_ylim(-xmax, xmax) isubplot = isubplot + 1 # only polarized vectors that varies with polarized fraction, no image if dostokes: ax = axes[isubplot] image.plotPolDir(image=im, arcsec=axis_arcsec, au=axis_au, dpc=dis, color='k', nx=16, ny=16, polunitlen=-1, ifreq=ifreq, ax=ax) ax.set_title('Polarization E Vectors') # xlim and ylim if xlim is not None: for ii in range(len(axes)): axes[ii].set_xlim(xlim) if ylim is not None: for ii in range(len(axes)): axes[ii].set_ylim(ylim) # set aspect radtio for ii in range(len(axes)): axes[ii].set_aspect('equal') # over plot ellipses if (opltr is not None) and (inc is not None): for axii in axes: for ir in opltr: ells = Ellipse(xy=(0,0), width=2*ir, height=np.cos(inc*natconst.rad)*2*ir, angle=0, fill=False, color='k', linestyle='-', linewidth=1) axii.axes.add_patch(ells) fig.tight_layout() fig.savefig(pngname) plt.close()
def getOutput_wavim(im, dis, pngname, imTblim=None, imxlim=None, imylim=None, opltr=None, inc=None, anglim=None, angcmap='hsv'): """ plots all the images across wavelength: stokes I, polarization fraction, angles Parameters ---------- im : radmc3dImage dis : float distance in pc pngname : str name for png file output opltr : list of floats radius to overplot in au inc : float inclination in degrees angcmap : str name of colormap to use for angle plot. Default is 'hsv' """ if imTblim is None: vlim = [0, None] else: vlim = imTblim if imxlim is None: imxlim = (im.x.min()/natconst.au, im.x.max()/natconst.au) if imylim is None: imylim = (im.y.min()/natconst.au, im.y.max()/natconst.au) if anglim is None: anglim = [None, None] nwav = len(im.wav) if im.stokes: nrow = nwav ncol = 4 else: nrow = np.floor(np.sqrt(nwav)) ncol = np.ceil(nwav / nrow) nrow, ncol = int(nrow), int(ncol) fig, axgrid = plt.subplots(nrows=nrow, ncols=ncol, figsize=(ncol*3, nrow*3), squeeze=False, sharex=True, sharey=True) axes = axgrid.flatten() for ii in range(nwav): # stokes I if im.stokes: axii = axgrid[ii, 0] else: axii = axes[ii] dum = image.plotImage(ax=axii, image=im, au=True, cmap=plt.cm.jet, stokes='I', bunit='Tb', dpc=dis, vmin=vlim[0], vmax=vlim[1], ifreq=ii, clevs=[20,40,60,80, 100], clcol='k', oplotbeam='w', beamxy=[imxlim[0]*0.75, imylim[0]*0.75], titleplt='I') axii.set_xlim(imxlim) axii.set_ylim(imylim) # polarized intensity if im.stokes: axii = axgrid[ii,1] dum = image.plotImage(ax=axii, image=im, au=True, cmap=plt.cm.jet, stokes='PI', bunit='Tb', dpc=dis, ifreq=ii, oplotbeam='w', beamxy=[imxlim[0]*0.75, imylim[0]*0.75], titleplt='PI') axii.set_xlim(imxlim) axii.set_ylim(imylim) # polarization fraction if im.stokes: axii = axgrid[ii,2] dum = image.plotImage(ax=axii, image=im, au=True, cmap=plt.cm.jet, stokes='P', bunit='percent', dpc=dis, ifreq=ii, oplotbeam='w', beamxy=[imxlim[0]*0.75, imylim[0]*0.75], titleplt='PFrac') axii.set_xlim(imxlim) axii.set_ylim(imylim) # polarization angle if im.stokes: axii = axgrid[ii,3] dum = image.plotImage(ax=axii, image=im, au=True, cmap=plt.cm.bwr, #plt.get_cmap(angcmap), stokes='ang', bunit='deg', dpc=dis, ifreq=ii, oplotbeam='w', beamxy=[imxlim[0]*0.75, imylim[0]*0.75], titleplt='PA', vmin=anglim[0], vmax=anglim[1]) axii.set_xlim(imxlim) axii.set_ylim(imylim) image.plotPolDir(image=im, au=True, ax=axii, ifreq=ii, polunitlen=-2, nx=16, ny=16, color='k') if (opltr is not None) and (inc is not None): for axii in axes: for ir in opltr: ells = Ellipse(xy=(0,0), width=2*ir, height=np.cos(inc*natconst.rad)*2*ir, angle=0, fill=False, color='k', linestyle=':', linewidth=1) axii.axes.add_patch(ells) fig.tight_layout() fig.savefig(pngname) plt.close()
def getOutput_stokes(ifreq, dis, im, pngname, polmax=None): # plot stokes values: I, Q, U, V, Polarized Linear Intensity, fraction plt.figure(num=ifreq, figsize=(14,8)) # image plt.subplot(2,3,1) image.plotImage(image=im, cmap=plt.cm.jet, interpolation='bilinear', arcsec=False, au=True, dpc=dis, oplotbeam='w', stokes='I', bunit='inu',ifreq=ifreq,saturate='90percent') plt.subplot(2,3,2) image.plotImage(image=im, cmap=plt.cm.bwr, interpolation='bilinear', arcsec=False, au=True, dpc=dis, textcolor='k', stokes='Q', bunit='norm',ifreq=ifreq, vmin=-1, vmax=1) plt.subplot(2,3,3) image.plotImage(image=im, cmap=plt.cm.bwr, interpolation='bilinear', arcsec=False, au=True, dpc=dis, textcolor='k', stokes='U', bunit='norm',ifreq=ifreq, vmin=-1,vmax=1) plt.subplot(2,3,4) image.plotImage(image=im, cmap=plt.cm.bwr, interpolation='bilinear', arcsec=False, au=True, dpc=dis, textcolor='k', stokes='V', bunit='norm',ifreq=ifreq, vmin=-1, vmax=1) plt.subplot(2,3,5) image.plotImage(image=im, cmap=plt.cm.jet, interpolation='bilinear', arcsec=False, au=True, dpc=dis, stokes='PI', bunit='inu',ifreq=ifreq,saturate='90percent') image.plotPolDir(image=im, arcsec=False, au=True, dpc=dis, color='w', nx=16, ny=22, polunitlen=-2, ifreq=ifreq) plt.subplot(2,3,6) image.plotImage(image=im, cmap=plt.cm.jet, interpolation='bilinear', arcsec=False, au=True, dpc=dis, ifreq=ifreq, saturate='100percent', stokes='P',bunit='percent' , vmin=0,vmax=polmax, clevs=[5.0, 10., 20.], clcol='k') image.plotPolDir(image=im, arcsec=False, au=True, dpc=dis, color='w', nx=16, ny=22, polunitlen=-2, ifreq=ifreq) plt.tight_layout() plt.savefig(pngname) plt.close()
import radmc3dPy.image as image import subprocess output = 'img_rl_powerlaw.fits' subprocess.call(['rm', output]) dist = 2000. im = image.readImage() data = im.image #Image data, channels lie on axis 2. image.plotImage(im, dpc=dist, au=True, bunit='jy/pixel', ifreq=29, cmap='gnuplot') #plotting channel 29 im.writeFits(fname=output, dpc=dist, coord='03h10m05s -10d05m30s') #writting 3d fits cube