All,
My final complication is that I am having trouble assigning String Element
Variables.
When I run the following code (assuming my earlier code):
def process_block(block):
numElems=block.GetNumberOfCells()
block_id=block.FieldData.GetArray('ElementBlockIds')
#print block_id
name=Blk_names[block_id-1]
name_length=name.__len__()
#print name
#print name_length
Block_Names=numpy.chararray( (numElems),itemsize=name_length )
Block_Names.fill(name)
#print Block_Names
block.CellData.append(Block_Names,"Block Name")
I end up with a character array the size of numElems and holding the BlockName
for every element.
The append fails with the error shown below. It looks like it doesn't want me
to append a string variable to block.CellData. Is there a way to do this?
Thanks, yet again, for the umpteenth time!
Dennis
Traceback (most recent call last):
File "<string>", line 21, in <module>
File "<string>", line 45, in RequestData
File "<string>", line 15, in process_block
File
"/apps/share/paraview/4.3.1/Linux/lib/paraview-4.3/site-packages/vtk/numpy_interface/dataset_adapter.py",
line 649, in append
arr = numpyTovtkDataArray(copy, name)
File
"/apps/share/paraview/4.3.1/Linux/lib/paraview-4.3/site-packages/vtk/numpy_interface/dataset_adapter.py",
line 148, in numpyTovtkDataArray
vtkarray = numpy_support.numpy_to_vtk(array)
File
"/apps/share/paraview/4.3.1/Linux/lib/paraview-4.3/site-packages/vtk/util/numpy_support.py",
line 166, in numpy_to_vtk
z_flat = numpy.ravel(z).astype(arr_dtype)
ValueError: invalid literal for int() with base 10: 'Apex_1'
-----Original Message-----
From: Dennis Conklin
Sent: Monday, August 31, 2015 2:47 PM
To: 'David Thompson'
Cc: Shawn Waldon; Paraview ([email protected])
Subject: RE: [Paraview] [EXT] Re: Exodus Block Names
All,
Just to wrap this up for the benefit of anyone who searches on this later:
From a python script, it's pretty easy
# Get a pointer to Exodus Reader, either open a file or get Active Source
rdr=GetActiveSource()
Block1=rdr.ElementBlocks[0]
Print Block1
# output will be block name
In a Programmable Filter, things are a little more complicated:
# First create list of Block_names
#
Input=self.GetInput()
# Element Block data is in DataBlock(0) of composite database
ElementBlocks=input.GetBlock(0)
#Number of ElementBlocks
numElemBlocks=ElementBlocks.GetNumberOfBlocks()
#
Block_names=[] #list
#
# names for all blocks in file are available
# normally only care about blocks that are loaded
# make a list of all and index blocks of interest later
For blk in range(numElemBlocks):
meta=ElementBlocks.GetMetaData(blk)
Name=meta.Get(vtk.vtkCompositeDataSet.NAME())
Block_names.append(Name)
#
# Loop over all loaded blocks and find associated names For block in output:
Blk_id=block.FieldData.GetArray('ElementBlockIds')
Blk_name=Block_names[Blk_id-1]
Thanks to everyone for their help.
Dennis
-----Original Message-----
From: David Thompson [mailto:[email protected]]
Sent: Monday, August 31, 2015 10:50 AM
To: Dennis Conklin
Cc: Shawn Waldon; Paraview ([email protected])
Subject: Re: [Paraview] [EXT] Re: Exodus Block Names
Hi all,
The Exodus reader creates 8 top-level blocks to identify different types of
data present in each file (corresponding to the names you see for 0-7). Each of
these blocks contains child blocks for the actual data loaded from the file
(which may be a subset of the data present in the file). It is these sub-blocks
whose metadata will hold the names from the Exodus file.
David
> On Aug 31, 2015, at 10:40 AM, Dennis Conklin <[email protected]>
> wrote:
>
> Shawn,
>
> Ok, I’m dense.
>
> When I run your code inside the Programmable Filter, I see some confusing
> things:
> mbi.GetNumberOfBlocks returns 8, which is NOT the number of blocks in my
> model but IS the number of MetaData blocks.
>
> The mbi.GetMetaData[i].Get(vtk.vtkCompositeDataSet.NAME()) then is
> Value of i Name
> 0 Element Blocks
> 1 Face Blocks
> 2 Edge Blocks
> 3 Element Sets
> 4 Side Sets
> 5 Face Sets
> 6 Edge Sets
> 7 Node Sets
> 8 <out of range>
>
> I am poking around mbi.GetMetaData[0] (Element Blocks) but I still haven’t
> found any Block Names there. I feel like I am completely missing something
> here, but I have no idea what it is.
>
> Dennis
>
>
> From: Shawn Waldon [mailto:[email protected]]
> Sent: Monday, August 31, 2015 9:46 AM
> To: Dennis Conklin
> Cc: Paraview ([email protected])
> Subject: Re: [EXT] Re: [Paraview] Exodus Block Names
>
> Hi Dennis,
>
> The metadata is on the reader's output, which is a vtkMultiBlockDataSet.
> reader.GetOutput() should get you the dataset in your python script. Inside
> the programmable filter you will need to get the input dataset
> (self.GetInput() should get you the input dataset and self.GetOutput() should
> get you the output dataset). So something like the following for your
> programmable filter:
>
> mbi = self.GetInput()
> mbo = self.GetOutput()
>
> mbo.ShallowCopy(mbi)
>
> for i in range(mbo.GetNumberOfBlocks()):
> metadata = mbo.GetMetaData(i)
> name = metadata.Get(vtk.vtkCompositeDataSet.NAME())
> # do something with the name
>
>
> HTH,
> Shawn
>
> On Mon, Aug 31, 2015 at 8:31 AM, Dennis Conklin <[email protected]>
> wrote:
> Shawn,
>
> Thanks for that tip but I can’t seem to access this structure. Really, I
> need it within the Programmable Filter, but even when I run a Python script
> and try to find it directly in an Exodus reader, I can’t seem to locate this
> metadata.
>
> If I print dir(ExodusReader), there doesn’t seem to be anything about
> metadata.
> Dennis
>
> From: Shawn Waldon [mailto:[email protected]]
> Sent: Friday, August 28, 2015 4:44 PM
> To: Dennis Conklin
> Cc: Paraview ([email protected])
> Subject: [EXT] Re: [Paraview] Exodus Block Names
>
> Hi Dennis,
>
> The block name is in the block metadata, which is not where I looked the
> first time either. Here is a code snippet that shows how to access it.
>
> mb = vtk.vtkMultiBlockDataSet()
> ...
> for i in range(mb.GetNumberOfBlocks):
> metadata = mb.GetMetaData(i)
> name = metadata.Get(vtk.vtkCompositeDataSet.NAME())
>
> HTH,
> Shawn
>
> On Fri, Aug 28, 2015 at 4:13 PM, Dennis Conklin <[email protected]>
> wrote:
> All,
>
> Once again, I need help. We are starting to assign names to our Exodus
> blocks (outside of Paraview). This is very useful for ease and clarity of
> post processing and allows convenient reference to actual components. The
> good news is that Paraview seems perfectly happy to read in the Block Names
> and use them in the Properties Panel and the Multi-block Inspector and the
> Find Data screen if they exist (no action or programming required for this).
> So, for instance, instead of Paraview generating the non-useful name of
> “Unnamed block ID: 13 Type: hex” when the blockname is empty, it will
> automagically use the more useful Blockname of “Tread” if that is in the
> Exodus file.
>
> However, there has been an unintended consequence of this change. If I
> select some elements and examine them in Spreadsheet View, I see Block Number
> 14( the +1 offset from Block_ID and Block Number is NOT the problem!). And
> now I can no longer associate the element (Block Number 14) with it’s block
> in the Properties Panel or the Multi-block Inspector or the Find Data panel –
> where the same block is called “Tread”.
>
> So, to remedy this situation I would like to add an element variable of
> BlockName, which would contain “Tread” for all the elements in BlockID 13,
> etc., etc. for all the blocks.
>
> My only problem is I can’t seem to find the list of Block Names. I’m pretty
> weak at vtk, so it must be available but I surrender – I can’t seem to find
> it. If someone can help me find the list of Block Names from inside the
> Programmable Filter, I’ll be happy to add the element variable myself.
>
> Thanks for any help, again!
>
> Dennis
>
> _______________________________________________
> 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
_______________________________________________
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