Title: Re: [Paraview] compute min/max of data array and annotate max and min values for each time step
Utkarsh,
 
Thanks! The script had one small error (for a non MultiBlockDataSet), which I fixed -- see attached. It now works just fine for the two test cases I tried -- files in the regular legacy *.vtk format and the multi-block *.exo format.
 
I saved the Python script as a Custom Filter in case anyone else wants to use it. Thanks again for your help.
 
Cheers,
Emily
 


From: Utkarsh Ayachit [mailto:[email protected]]
Sent: Wed 9/14/2011 7:53 PM
To: Guzas, Emily L CIV NUWC NWPT
Cc: [email protected]
Subject: Re: [Paraview] compute min/max of data array and annotate max and min values for each time step

Emily,

Attached is the python script to use in the filer. I've added a new
MODE that can be used to set to use min or max.

Utkarsh

On Wed, Sep 14, 2011 at 11:51 AM, Guzas, Emily L CIV NUWC NWPT
<[email protected]> wrote:
> Utkarsh,
>
> Thanks! This works pretty well in serial. However, I took your
> MaxLabelFilter and tried to modify it to calculate and display minimum
> (instead of maximum) array values for each time step and for some reason it
> isn't working -- just assigns a zero value as the minimum. Could you take a
> quick look? I saved the XML file as a *.txt file in case my email tries to
> strip the attachment.
>
> And yes, I will be working in parallel, but not right now.
>
> Thanks again,
> Emily
>
> ________________________________
> From: Utkarsh Ayachit
> Sent: Wed 9/14/2011 10:08 AM
> To: Guzas, Emily L CIV NUWC NWPT
> Cc: [email protected]
> Subject: Re: [Paraview] compute min/max of data array and annotate max and
> min values for each time step
>
> Emily,
>
> Attached is a custom filter that you can use to label using maximum
> for point array named ACCL. You change the "ARRAYNAME" and
> "ARRAYASSOCIATION" variable to pick the array of choice. Also, though
> I've only implemented getting the max value for the magnitude of the
> array, you can change the python script to do a min or a particular
> component, for example.
>
> To test,
> 1) Import the attached file using Tools | Manage Custom Filters dialog
> (click Import).
> 2) The open can.ex2 from ParaViewData. Enable all arrays in the array
> selection widget on the properties panel. Hit apply.
> 3) Create "MaxLabelFilter". Hit apply. You'll see a label in the 3D
> view that updates as you animate.
>
> Are you running with a parallel pvserver? If so, I'll have to update
> the filter. It should work in serial though.
>
> Utkarsh
>
> On Tue, Sep 13, 2011 at 2:28 PM, Guzas, Emily L CIV NUWC NWPT
> <[email protected]> wrote:
>> Hello,
>>
>> I am a ParaView newbie and I am trying to compute the maximum and minimum
>> values of one array (e.g. pressure or density) in a multi-block dataset
>> (*.exo) file in ParaView, and then display those maximum and minimum
>> values
>> on screen with text. To make this more fun, the dataset includes time
>> data,
>> and so what I really want to be able to do is to compute the maximum and
>> minimum values of the array and display them on-screen for each time step
>> so
>> that when I animate the data, the max/min values update as the animation
>> runs.
>>
>> Could someone point me in the right direction for how to do this?
>>
>> I looked at the Calculator filter, but I don't see any maximum and minimum
>> functions there (not that I expected to see them). And I just started
>> looking at the Python Programmable Filter, but I am not familiar with the
>> vtk class and so this route will involve a bit of a learning curve to
>> figure
>> out the syntax for what I need to accomplish.
>>
>> Thanks,
>> Emily
>>
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.paraview.org/mailman/listinfo/paraview
>>
>>
>

Attachment: maxmin.py
Description: maxmin.py

<CustomFilterDefinitions>
  <CustomProxyDefinition name="MinMaxLabelFilter" group="filters">
    <CompoundSourceProxy id="401" servers="1">
      <Proxy group="filters" type="ProgrammableFilter" id="396" servers="1" compound_name="ProgrammableFilter2">
        <Property name="CopyArrays" id="396.CopyArrays" number_of_elements="1">
          <Element index="0" value="0"/>
          <Domain name="bool" id="396.CopyArrays.bool"/>
        </Property>
        <Property name="InformationScript" id="396.InformationScript" number_of_elements="1">
          <Element index="0" value=""/>
        </Property>
        <Property name="Input" id="396.Input" number_of_elements="1">
          <Domain name="groups" id="396.Input.groups"/>
          <Domain name="input_type" id="396.Input.input_type"/>
        </Property>
        <Property name="OutputDataSetType" id="396.OutputDataSetType" number_of_elements="1">
          <Element index="0" value="19"/>
          <Domain name="enum" id="396.OutputDataSetType.enum">
            <Entry value="8" text="Same as Input"/>
            <Entry value="0" text="vtkPolyData"/>
            <Entry value="2" text="vtkStructuredGrid"/>
            <Entry value="3" text="vtkRectilinearGrid"/>
            <Entry value="4" text="vtkUnstructuredGrid"/>
            <Entry value="6" text="vtkImageData"/>
            <Entry value="10" text="vtkUniformGrid"/>
            <Entry value="13" text="vtkMultiblockDataSet"/>
            <Entry value="15" text="vtkHierarchicalBoxDataSet"/>
            <Entry value="19" text="vtkTable"/>
          </Domain>
        </Property>
        <Property name="PythonPath" id="396.PythonPath" number_of_elements="1">
          <Element index="0" value=""/>
        </Property>
        <Property name="Script" id="396.Script" number_of_elements="1">
          <Element index="0" value="ARRAYNAME = &#x22;pressure&#x22;  # pressure, density, EPS, EFFSTR, DISP, etc.&#xa;ARRAYASSOCIATION = &#x22;Point&#x22; # &#x22;Point&#x22; or &#x22;Cell&#x22;&#xa;UNITS = &#x22;dyne/cm^2&#x22; # specify units for display &#xa;MODE = &#x22;Min&#x22; # &#x22;Min&#x22; or &#x22;Max&#x22;&#xa;&#xa;def get_value(dataset):&#xa;    &#x22;&#x22;&#x22;Function that returns the Min or Max value for ARRAYNAME in the current&#xa;    dataset&#x22;&#x22;&#x22;&#xa;    if ARRAYASSOCIATION == &#x22;Point&#x22;:&#xa;        dsa = dataset.GetPointData()&#xa;    elif ARRAYASSOCIATION == &#x22;Cell&#x22;:&#xa;        dsa = dataset.GetCellData()&#xa;    else:&#xa;        raise RuntimeError, &#x22;Unknown assoctiation %s&#x22; % ARRAYASSOCIATION&#xa;    array = dsa.GetArray(ARRAYNAME)&#xa;    # if arrayname is missing, we silently ignore.&#xa;    if array:&#xa;        if MODE == &#x22;Min&#x22;:&#xa;            return array.GetRange(-1)[0]&#xa;        elif MODE == &#x22;Max&#x22;:&#xa;            return array.GetRange(-1)[1]&#xa;        else:&#xa;            raise RuntimeError, &#x22;Unknown MODE %s&#x22; % MODE&#xa;    return None&#xa;&#xa;input = self.GetInputDataObject(0, 0)&#xa;output = self.GetOutputDataObject(0)&#xa;&#xa;chosen_value = None&#xa;&#xa;if input.IsA(&#x22;vtkMultiBlockDataSet&#x22;):&#xa;    iter = input.NewIterator()&#xa;    iter.UnRegister(None)&#xa;    iter.InitTraversal()&#xa;    while not iter.IsDoneWithTraversal():&#xa;        curInput = iter.GetCurrentDataObject()&#xa;        cur_value = get_value(curInput)&#xa;        if MODE == &#x22;Min&#x22;:&#xa;            test_result = (chosen_value == None) or (cur_value &#x3c; chosen_value)&#xa;        elif MODE == &#x22;Max&#x22;:&#xa;            test_result = (chosen_value == None) or (cur_value &#x3e; chosen_value)&#xa;        else:&#xa;            raise RuntimeError, &#x22;Unknown MODE %s&#x22; % MODE&#xa;        if test_result:&#xa;            chosen_value = cur_value&#xa;        iter.GoToNextItem();&#xa;else:&#xa;    chosen_value = get_value(input)&#xa;&#xa;# FIXME: Determine Min/Max in parallel.&#xa;&#xa;if chosen_value == None:&#xa;    print &#x22;ERROR&#x3A; Could not determine value, using 0&#x22;&#xa;    print &#x22;Check data type &#x28;ARRAYASSOCIATION&#x29; and array name&#x28;ARRAYNAME&#x29;&#x22;&#xa;    chosen_value = 0&#xa;outputarray = vtk.vtkStringArray()&#xa;outputarray.SetName(&#x22;%s&#x22; % MODE)&#xa;outputarray.SetNumberOfTuples(1)&#xa;outputarray.SetValue(0, &#x22;%s %s = %g %s.&#x22; % (MODE, ARRAYNAME, chosen_value,UNITS))&#xa;output.GetRowData().AddArray(outputarray)&#xa;"/>
        </Property>
        <Property name="UpdateExtentScript" id="396.UpdateExtentScript" number_of_elements="1">
          <Element index="0" value=""/>
        </Property>
      </Proxy>
      <ExposedProperties>
        <Property name="Input" proxy_name="ProgrammableFilter2" exposed_name="Input"/>
        <Property name="Script" proxy_name="ProgrammableFilter2" exposed_name="Script"/>
      </ExposedProperties>
      <OutputPort name="Output" proxy="ProgrammableFilter2" port_index="0"/>
      <Hints>
        <ShowInMenu/>
        <OutputPort name="Output" index="0" type="text" />
      </Hints>
    </CompoundSourceProxy>
  </CustomProxyDefinition>
</CustomFilterDefinitions>

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
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

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to