No, no, I’m sure it’s *me* who’s confused.  I’m not sure I understand what 
you’re saying. Are you suggesting keeping the (full) range of timesteps in my 
script and then, somehow, only render the one of interest? If so, that would be 
great, except the way things are currently working for me, after loading the 
.pvsm initially, it renders the first requested tilmestep, but I cannot just 
enter a desired timestep value into the “Time” widget field. I can only single 
step through them via the up/down arrow widget.

Not sure if it’s related, but after loading the state file, in the Output 
Messages, I get the following error/warning, even though it does render the 
first one properly:

Traceback (most recent call last):
  File "<string>", line 20, in <module>
  File "<string>", line 34, in RequestInformation
TypeError: arguments do not match any overloaded methods
------- time=  100.0
fname= 
/Users/heiland/git/PhysiCell/run2_cancer_immune/output00000100_cells_physicell
num_cells_possible = 38080
num_cells = 38080

I’ve attached my Programmable Source Script and Script(RequestInfo), fwiw. Line 
34 of RequestInfo is the very last line in that script.
output.GetInformation().Set(output.DATA_TIME_STEP(), req_time)


thanks!
Randy
import scipy
from scipy import io
import math

outInfo = self.GetOutputInformation(0)
if outInfo.Has(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_TIME_STEP()):
  time = outInfo.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_TIME_STEP())
  fname = "output%08d_cells_physicell" % time
else:
  time = 0
  fname = "output%08d_cells_physicell" % time 
print "------- time= ",time 

cells_dict = {} 

  # fix file pathname for cross-platform?
dir = "/Users/heiland/git/PhysiCell"
dir += "/run2_cancer_immune/"

print "fname=",dir+fname 
scipy.io.loadmat(dir + fname, cells_dict)
val = cells_dict['cells']

  # Get a vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()

  # Get number of cells
num_cells_possible = val.shape[1]
print "num_cells_possible =",num_cells_possible

  # Create points (cells' centers)
newPts = vtk.vtkPoints()

  # We will create two scalar fields:
  #   cell_color_ID = integers that get mapped to colors (for cell types)
  #   cell_diam = floating point values of cell diameters
cell_color_ID = vtk.vtkIntArray()
cell_diam = vtk.vtkFloatArray()
cell_color_ID.SetName('cell_color_ID')
cell_diam.SetName('cell_diameter')

  #kdx=6
  #if (kdx == 5):
#  scalars.SetName('cell_type')
  #elif (kdx == 6):
  #  scalars.SetName('cycle_model')
  #elif (kdx == 7):
  #  scalars.SetName('current_phase')

  # This is a temporary hack to correct
  # for a shortcoming in ParaView's OSPRay
  # sphere scaling. Basically, we need to
  # move all cells closer to the origin.
first_pass = False
if (first_pass):
  maxDist = 0.0
else:
  maxDist = 4.0  # ~3.90

num_cells = 0
for idx in range(0, num_cells_possible):   # loop over all (possible) cells
    # rf. PhysiCell User Guide for interpretation of these array indices
    x = val[1,idx]
    y = -val[2,idx]  # invert Y (points down)
    z = val[3,idx]
    if (math.fabs(x) > 10000): # avoid bogus data
      print idx," skip x =", x
      continue
    elif (math.fabs(y) > 10000):
      print idx," skip y =", y
      continue
    elif (math.fabs(z) > 10000):
      print idx," skip z =", z
      continue

    # If reading a new .mat data file
    # of unknown spatial size, do this:
    if (first_pass):
      dist = math.sqrt(x*x + y*y + z*z)
      if dist > maxDist:
        maxDist = dist

    # insert new (only if valid) point
    # temporary hack: move cell centers closer to origin
    newPts.InsertPoint(num_cells, x/maxDist,y/maxDist,z/maxDist)
    num_cells += 1

    # The following lines assign an integer to represent
    # a color, defined in a Color Map.
    sval = 0   # immune cells are black?
    if val[5,idx] == 1:  # [5]=cell_type
      sval = 1   # lime green
    if (val[6,idx] == 6) or (val[6,idx] == 7):
      sval = 0
    if val[7,idx] == 100:  # [7]=current_phase
      sval = 3   # apoptotic: red
    if val[7,idx] > 100 and val[7,idx] < 104:
      sval = 2   # necrotic: brownish

    cell_color_ID.InsertNextValue(sval)

    # This is where we create another scalar field that
    # will determine how cells (spheres) are scaled.
    # V=(4/3)pi*r^3 -> r^3 = v*0.75/pi
    diam = (val[4,idx]*0.2387)**0.333 * 2.0
    cell_diam.InsertNextValue(diam)

  # If doing a 1st-pass to determine max distance
  # of a cell from the origin:
  #print 'maxDist = ',maxDist

  # Add the points and the scalar arrays to the vtkPolyData object.
pdo.SetPoints(newPts)
pdo.GetPointData().AddArray(cell_color_ID)
pdo.GetPointData().AddArray(cell_diam)

verts = vtk.vtkCellArray()
print "num_cells =",num_cells

for idx in range(0, num_cells):
    verts.InsertNextCell(1)
    verts.InsertCellPoint(idx)

pdo.SetVerts(verts)
def setOutputTimesteps (algorithm , timesteps):
  # "helper routine to set timestep information"
  executive = algorithm.GetExecutive()
  outInfo = executive.GetOutputInformation(0)

  outInfo.Remove(executive.TIME_STEPS())
  for timestep in timesteps:
    outInfo.Append(executive.TIME_STEPS(), timestep)

  outInfo.Remove(executive.TIME_RANGE())
  outInfo.Append(executive.TIME_RANGE(), timesteps[0])
  outInfo.Append(executive.TIME_RANGE(), timesteps[-1])

frames = range(100,801,100) # do every 100th file: 0,100,...,800 
setOutputTimesteps (self, frames)

# Code for ’Script’  
def GetUpdateTimestep(algorithm):
  #""" Returns the requested time value , or None if not present """
  executive = algorithm.GetExecutive()
  outInfo = executive.GetOutputInformation(0)
  return outInfo.Get(executive.UPDATE_TIME_STEP()) \
      if outInfo.Has(executive.UPDATE_TIME_STEP()) else None

 # This is the requested time-step. This may not be exactly equal to the
 # timesteps published in RequestInformation(). Your code must handle that
 # correctly
req_time = GetUpdateTimestep (self)
#print "req_time = ",req_time 

# Now mark the timestep produced.
output.GetInformation().Set(output.DATA_TIME_STEP(), req_time)


 
> On Dec 8, 2017, at 10:10 AM, Utkarsh Ayachit <utkarsh.ayac...@kitware.com> 
> wrote:
> 
> Oops. I meant to say -- "I am a little confused here" :).
> 
> On Fri, Dec 8, 2017 at 10:10 AM, Utkarsh Ayachit
> <utkarsh.ayac...@kitware.com> wrote:
>> Hmm, little confused here? Why not keep the timesteps in the reader
>> unchanged and explcitly do the timestep of interest and save
>> screenshot?
>> 
>> On Thu, Dec 7, 2017 at 10:51 AM, Heiland, Randy <heil...@iu.edu> wrote:
>>> Utkarsh,
>>> 
>>> Thanks very much for that!  Yes, after some fiddling, I got it to work, 
>>> i.e., I can save .png files for an animation! So now that I’m using the 
>>> Programmable Source(RequestInfo) script to accomplish the animation, how do 
>>> I, during a PV session, *easily* switch back to render a single file?
>>> 
>>> For example, I can do:
>>> frames = range(0,801,100)   #  render every 100th frame, including 800
>>> setOutputTimesteps (self, frames)
>>> 
>>> or, I can explicitly list specific frames:
>>> frames = [100,101]
>>> 
>>> so, I thought this would do a single file, but it doesn’t (my previous 
>>> frames are still there):
>>> frames = [600,]
>>> 
>>> -Randy
>>> 
>>> 
>>> 
>>>> On Dec 6, 2017, at 10:44 PM, Utkarsh Ayachit <utkarsh.ayac...@kitware.com> 
>>>> wrote:
>>>> 
>>>> Randy,
>>>> 
>>>> You attempting to mix the Python scripting for data processing and
>>>> Python scripting for batch scripting. The two environments are
>>>> separate. Here's how I'd tackle it.
>>>> 
>>>> 1. Make your "Programmable Source" become a temporal source i.e.
>>>> report to ParaView that it can produce timesteps matching the files
>>>> your file series. See [i]. If you get this right, you shuold be able
>>>> to render through all the files by hitting "Play" in the VCR control
>>>> in the UI.
>>>> 2. Now you can write a batch script that either loads the predefined
>>>> pvsm state file or builds up the pipeline in Python itself and the
>>>> either uses `SaveScreenshot` or `SaveAnimation` to save out the
>>>> animation.
>>>> 
>>>> You can then mix in camera animations too. You can always use the
>>>> Python tracing in UI to figure out how to save images and/or animation
>>>> in the batch scripting environment.
>>>> 
>>>> Hope that helps.
>>>> Utkarsh
>>>> 
>>>> [i] 
>>>> https://blog.kitware.com/defining-time-varying-sources-with-paraviews-programmable-source/
>>>> 
>>>> On Wed, Dec 6, 2017 at 11:15 AM, Heiland, Randy <heil...@iu.edu> wrote:
>>>>> I’m probably missing a basic concept and hoping someone can enlighten 
>>>>> me. I
>>>>> have a pipeline with a Programmable Source that reads in a (non-VTK
>>>>> formatted) file, I process it and then I have filters in my pipeline that
>>>>> act on that data. I want to be able to feed multiple files to the 
>>>>> pipeline,
>>>>> save images and/or create animations. I naively created a Python function 
>>>>> in
>>>>> the Pgmable Source, then save the PV State to a Python script, thinking I
>>>>> could call the function from the end of that script. Doesn’t seem to be
>>>>> possible. And I confess I’ve not given this deep thought - it’s 
>>>>> easier to
>>>>> ask the experts :-)  Bottom line, we want to make this as dead simple for
>>>>> our own users.
>>>>> 
>>>>> Fwiw, I’ve zipped up 2 files - a .pvsm and a sample data file here:
>>>>> http://pages.iu.edu/~heiland/physicell/pv_pcell.zip . You’d need to 
>>>>> edit the
>>>>> “dir” path in the Pgmable Source.
>>>>> 
>>>>> Initially, I just want to save images/animation (over multiple files) 
>>>>> with a
>>>>> fixed camera view; later, it’d be nice to have simultaneous camera 
>>>>> movement.
>>>>> 
>>>>> thanks, Randy
>>>>> 
>>>>> _______________________________________________
>>>>> Powered by www.kitware.com
>>>>> 
>>>>> Visit other Kitware open-source projects at
>>>>> http://www.kitware.com/opensource/opensource.html
>>>>> 
>>>>> Please keep messages on-topic and check the ParaView Wiki at:
>>>>> http://paraview.org/Wiki/ParaView
>>>>> 
>>>>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>>>> 
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://public.kitware.com/mailman/listinfo/paraview
>>>>> 
>>> 

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to