[Numpy-discussion] how to efficiently build an array of x, y, z points
Thu Mar 4 16:52:42 CST 2010
Christopher Barker wrote:
> Bruce Southey wrote:
>> Christopher Barker provided some code last last year on appending
>> ndarrays eg:
> yup, I"d love someone else to pick that up and test/improve it.
> Anyway, that code only handles 1-d arrays, though that can be structured
> arrays. I"d like to extend it to handlw n-d arrays, though you could
> only grow them in the first dimension, which may work for your case.
> As for performance:
> My numpy code is a bit slower than using python lists, if you add
> elements one at a time, and the elements are a standard python data
> type. It should use less memory though, if that matters.
> If you add the data in big enough chunks, my method gets better performance.
Currently I'm adding all my corner point xyz's into a list and then
converting to an array of shape (npoints,3)
And I'm creating a celllist with the point indices for each cell and
then converting that into an array of shape (nactivecells,8)
Then I'm creating an unstructured grid.
>> Ultimately I'm trying to build a tvtk unstructured grid to view in a
>> Traits/tvtk/Mayavi app.
> I'd love to see that working, once you've got it!
So will I.
> > The grid is ni*nj*nk cells with 8 xyz's per cell
>> (hexahedral cell with 6 faces). However some cells are inactive and
>> therefore don't have geometry. Cells also have "connectivity" to other
>> cells, usually to adjacent cells (e.g. cell i,j,k connected to cell
>> i-1,j,k) but not always.
> I'm confused now -- what does the array need to look like in the end? Maybe:
> ni*nj*nk X 8 X 3 ?
> How is inactive indicated?
I made a typo in my first posting. Each cell has 8 corners, each corner
an x,y,z so yes, if all the cells in the grid
are active then ni*nj*nk*8*3 but usually not all cells are active and it
is optional whether to have inactive cell
geometry written out to the grid file so it is actually nactivecells*8*3
> Is the connectivity somehow in the same array, or is that stored separately?
Bit of both - there is separate connectivity info and also implicit
connectivity info. Often a cell will be fully connected to its adjacent
cell(s) as they
share a common face. But also, often there is not connectivity (e.g. a
fault) and the +I face of a cell does not match up against the -I face
At the moment, I'm not removing duplicate points (of which there are a
lot, probably 25-50% depending on the degree of faulting).
One other thing I need to do is to re-order my xyz coordinates - in the
attached image taken from the VTK file format pdf you can see the 0,1,2,3
and 4,5,6,7 node ordering. In my grid it is 0,1,3,2 and 4,5,7,6 so
you can see that I need to swap round some of the coordinates. I need to
for each cell and there may be 10,000 of them but there may be
2,000,000 of them.
So I think it is probably best not to do it on a cell by cell basis but
wait until I've built my full pointlist, then convert it to an array,
probably of shape (nactivecells,8,3) and then somehow rearrange/reorder
the 8 "columns". Sound the right way to go?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 6219 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100305/6d7d46e0/attachment.png
More information about the NumPy-Discussion