BHAC Python tools
Public Member Functions | Public Attributes | List of all members
amrplot.rgplot Class Reference

As polyplot, but use regridded data to display. More...

Inheritance diagram for amrplot.rgplot:
amrplot.polyplot

Public Member Functions

def show (self, var=None, data=None, min=None, max=None, reset=None, fixrange=None, filenameout=None)
 Draw the plotting-window. More...
 
- Public Member Functions inherited from amrplot.polyplot
def __init__ (self, value, data, nlevels=256, grid=None, blocks=None, blockWidth=8, blockHeight=8, nlevel1=0, cmap='jet', min=None, max=None, xrange=None, yrange=None, orientation='vertical', right=True, fixzoom=None, fixrange=None, fig=None, axis=None, filenameout=None, clear=True, edgecolor='k', smooth=0, swap=0, kwargs)
 
def setValue (self, value, min=None, max=None)
 Sets the min and max values of the data to saturate the display. More...
 
def update (self, var=None, data=None, min=None, max=None, reset=None, fixrange=None, filenameout=None)
 Prepare to re-draw the window, check if data was updated. More...
 
def info (self)
 Print info to the console. More...
 
def show (self, var=None, data=None, min=None, max=None, reset=None, fixrange=None, filenameout=None)
 Draw the plotting-window. More...
 
def colorbar (self, cax=None)
 Draw the colorbar. More...
 
def save (self, filenameout=None)
 Save the figure. More...
 
def onkey (self, event)
 

Public Attributes

 viewXrange
 
 viewYrange
 
 ax
 
 fixzoom
 
 valueClip
 
 swap
 
 image
 
 filenameout
 
- Public Attributes inherited from amrplot.polyplot
 swap
 
 nlevels
 
 grid
 
 blocks
 
 blockWidth
 
 blockHeight
 
 nlevel1
 
 cmap
 
 orientation
 
 right
 
 cbarwidth
 
 cbarpad
 
 fixzoom
 
 fixrange
 
 filenameout
 
 clear
 
 fontsize
 
 fig_w
 
 fig_h
 
 dpi
 
 maxXticks
 
 maxYticks
 
 cbarticks
 
 edgecolor
 
 smooth
 
 xrange
 
 yrange
 
 figure
 
 ax
 
 value
 
 min
 
 max
 
 data
 
 viewXrange
 
 viewYrange
 
 valueClip
 
 xlist
 
 ylist
 
 xlistspecial
 
 ylistspecial
 
 cax
 
 cbar
 
 selection
 

Detailed Description

As polyplot, but use regridded data to display.

Definition at line 336 of file amrplot.py.

Member Function Documentation

◆ show()

def amrplot.rgplot.show (   self,
  var = None,
  data = None,
  min = None,
  max = None,
  reset = None,
  fixrange = None,
  filenameout = None 
)

Draw the plotting-window.

Definition at line 339 of file amrplot.py.

339  '''Draw the plotting-window'''
340 
341  t0 = default_timer()
342 
343  self.update(var=var,data=data,min=min,max=max,reset=reset,fixrange=fixrange,filenameout=filenameout)
344 
345  self.viewXrange=self.ax.xaxis.get_view_interval()
346  self.viewYrange=self.ax.yaxis.get_view_interval()
347  self.figure.clf()
348  self.ax = self.figure.gca()
349  self.ax.set_rasterization_zorder(-9)
350  self.info()
351 
352  if self.fixzoom==None:
353  self.ax.set_xlim(self.xrange[0],self.xrange[1])
354  self.ax.set_ylim(self.yrange[0],self.yrange[1])
355  else:
356  self.ax.set_xlim(self.viewXrange)
357  self.ax.set_ylim(self.viewYrange)
358  self.ax.set_aspect('equal')
359 
360 
361  valueRange=self.max-self.min
362  if valueRange == 0.:
363  valueRange = 1
364 
365  self.valueClip = np.clip(self.value,self.min,self.max)
366 
367 # Now regrid and imshow:
368  tdata0= default_timer()
369  xrange=[self.ax.get_xlim()[0],self.ax.get_xlim()[1]]
370  yrange=[self.ax.get_ylim()[0],self.ax.get_ylim()[1]]
371 
372  nregrid = [self.dpi*self.fig_w,self.dpi*self.fig_h]
373 
374  if (self.swap == 0):
375  CC=self.data.getCenterPoints()
376  else:
377  CC=self.data.getCenterPoints()[:,[1,0]]
378  tmp0=np.complex(0,nregrid[0])
379  tmp1=np.complex(0,nregrid[1])
380  grid_x, grid_y = np.mgrid[xrange[0]:xrange[1]:tmp0, yrange[0]:yrange[1]:tmp1]
381 
382 # regrid with linear interpolation and fall back to nearest neighbor at NaN, which should just be the borders.
383  gridvar = griddata(CC, self.valueClip, (grid_x, grid_y), method='cubic',fill_value=float(np.NaN))
384  isnan=np.isnan(gridvar)
385  gridvar[isnan] = griddata(CC, self.value, (grid_x[isnan], grid_y[isnan]), method='nearest',fill_value=float(np.NaN))
386 
387 # smooth the data slightly:
388  gridvar = ndimage.gaussian_filter(gridvar, sigma=self.smooth)
389 
390  extent = xrange[0], xrange[1], yrange[0], yrange[1]
391  gridvarClip = np.clip(gridvar,self.min,self.max)
392  self.image=gridvarClip
393  tdata1=default_timer()
394 
395 
396  im2 = self.ax.imshow(gridvarClip.transpose(), cmap=plt.cm.get_cmap(self.cmap, self.nlevels), interpolation='bicubic',extent=extent,origin='lower',zorder=-10)
397  norm = colors.Normalize(vmin=self.min, vmax=self.max)
398  im2.set_norm(norm)
399 # Q=velovect(self.data.u1,self.data.u2,self.data,nvect=[20,20],scale=30,fig=self)
400 
401  if self.grid != None:
402  if (self.swap == 0):
403  [myxlist,myylist]=self.data.getPointList()
404  else:
405  [myylist,myxlist]=self.data.getPointList()
406  self.ax.fill(myxlist,myylist,
407  facecolor='none', edgecolor=self.edgecolor,aa=True,linewidth=0.2,alpha=0.8)
408 
409  if self.blocks != None:
410  [myxBlockList,myyBlockList] = self.data.getPieces(self.blockWidth,self.blockHeight,self.nlevel1)
411  self.ax.fill(myxBlockList,myyBlockList,
412  facecolor='none', edgecolor=self.edgecolor,aa=True,linewidth=0.4,alpha=0.5)
413 
414  if self.orientation != None:
415  self.colorbar()
416 
417 # ticks:
418  if self.maxXticks != None:
419  self.ax.xaxis.set_major_locator(MaxNLocator(self.maxXticks-1))
420  if self.maxYticks != None:
421  self.ax.yaxis.set_major_locator(MaxNLocator(self.maxYticks-1))
422 
423  for tick in self.ax.xaxis.get_major_ticks():
424  tick.label1.set_fontsize(self.fontsize)
425  for tick in self.ax.yaxis.get_major_ticks():
426  tick.label1.set_fontsize(self.fontsize)
427  self.ax.xaxis.get_offset_text().set_fontsize(self.fontsize-2)
428  self.ax.yaxis.get_offset_text().set_fontsize(self.fontsize-2)
429 
430  tend = default_timer()
431  print('time for arranging the data= %f sec' % (tdata1-tdata0))
432  print('Execution time = %f sec' % (tend-t0))
433  print('=======================================================')
434  if self.filenameout == None:
435  plt.draw()
436 
437 # Make the main axis active:
438  plt.sca(self.ax)
439 
440 #=============================================================================
default_timer
Definition: read.py:14

Member Data Documentation

◆ ax

amrplot.rgplot.ax

Definition at line 348 of file amrplot.py.

◆ filenameout

amrplot.rgplot.filenameout

Definition at line 434 of file amrplot.py.

◆ fixzoom

amrplot.rgplot.fixzoom

Definition at line 352 of file amrplot.py.

◆ image

amrplot.rgplot.image

Definition at line 392 of file amrplot.py.

◆ swap

amrplot.rgplot.swap

Definition at line 374 of file amrplot.py.

◆ valueClip

amrplot.rgplot.valueClip

Definition at line 365 of file amrplot.py.

◆ viewXrange

amrplot.rgplot.viewXrange

Definition at line 345 of file amrplot.py.

◆ viewYrange

amrplot.rgplot.viewYrange

Definition at line 346 of file amrplot.py.


The documentation for this class was generated from the following file: