meta-data

that’s when tian becomes protian

Archive for the ‘python script’ Category

python, declare your own class.

without comments

well, it is ashamed to say that after 2 years of using python, I only use its text-processing ability. Now is its object-oriented part:

 class MyClass:

“A simple example class”

i = 12345

def f(self):

return ‘hello world’

and

x = MyClass()

ok

Written by protian

February 15, 2008 at 2:38 pm

Posted in python script

numpy

without comments

from numpy import *

z = zeros(nglobal)

z[nnow]=coe1*float(gelev[nnode1])+coe2*float(gelev[nnode2])+coe3*float(gelev[nnode3])

numpy tutorial

mycode:

xarray = array(xlist)
xarray.shape = cgmxc+1,cgmyc+1
print xarray.shape
print xarray[cgmxc, cgmyc]

yarray = array(ylist)
yarray.shape = cgmxc+1,cgmyc+1
print yarray.shape
print yarray[cgmxc, cgmyc]

results:

(361, 271)
-80.0
(361, 271)
33.0

good.

A frequent error consists in calling array with a set of elements as argument, that is,

>>> a = array(1,2,3,4)   # WRONG

This does not do what we expect. The first argument of array must be the entire set of data. Thus, it must be called like that:

>>> a = array([1,2,3,4])  # RIGHT   >>> y.shape = 3,4              # does not modify the total number of elements
>>> y
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])

The way numpy arranges its array is strange, which goes (j,i) , where j is the row number, i is the number of column. This is contrary to CFD grid index.

Written by protian

February 4, 2008 at 10:02 pm

Posted in python script

Output wave isosurface in whatever format

without comments

how to output wave profile in whatever format so that arcGIS and maya and Terragen can display?

in maya and Terragen, it can serve as a displacement map? but then that requires extracting only the land potion of the whole SWAN domain.

What about arcGIS?

Ok, now start converting SWAN output to STL then VRML. first, extract only positive Hsign points and triangulate them.

The output of this procedure is two files: 1. triangles in adcirc format. 2. triangles in stl format.

SWAN outputted data is written in layout 4 format: (from lower-left to upper-right, row by row)

1,1 2,1 … mxc+1, 1 1,2 2,2 … mxc+1,2 …

Writing python script “filter_swanoutput.py” which is derived from “extractswanpts.py”.

giarray[i,j] = global index of point i,j, =-999 for dry points

ilist[] = list of i indices of wet points

jlist[] = list of j indices of wet points

trianglelist[n] = array[global1, global2, global3] : a list of arrays, which contains the global indices of 3 vertices.

output as adcirc grid first for viewing and checking purpose

filename = “adcircout.grd”

adcirc grid format:

AGRID
NE, NP

for k=1 to NP
JN, X(JN), Y(JN), DP(JN)
end k loop

for k=1 to NE
JE, NHY, NM(JE,1), NM(JE,2), NM(JE,3)
end k loop

NOPE
NETA

for k=1 to NOPE
NVDLL(k), IBTYPEE(k)
for j=1 to NVDLL(k)
NBDV(k,j)
end j loop
end k loop

NBOU
NVEL

for k=1 to NBOU
NVELL(k), IBTYPE(k)
for j=1,NVELL(k)
NBVV(k,j) – include this line only if IBTYPE(k) = 0, 1, 2, 10, 11, 12, 20, 21, 22, 30
NBVV(k,j), BARLANHT(k,j), BARLANCFSP(k,j) – include this line only if IBTYPE(k) = 3, 13, 23
NBVV(k,j), IBCONN(k,j), BARINHT(k,j), BARINCFSB(k,j), BARINCFSP(k,j) – include this line only if IBTYPE(k) = 4, 24
end j loop
end k loop

ADCIRC output successful! by filtering out hsign = 0.

Next STL format:

STLA Examples:

solid MYSOLID
facet normal 0.4 0.4 0.2
outerloop
vertex  1.0 2.1 3.2
vertex  2.1 3.7 4.5
vertex  3.1 4.5 6.7
endloop
endfacet
...
facet normal 0.2 0.2 0.4
outerloop
vertex  2.0 2.3 3.4
vertex  3.1 3.2 6.5
vertex  4.1 5.5 9.0
endloop
endfacet

endsolid MYSOLID
Converted to VRML file iso-surface.wrl using IVCON. The converted file goes like:
#VRML V2.0 utf8

  WorldInfo {
    title "isosurface.wrl"
    info "WRL file generated by IVREAD."
    info "Original data in isosurface.stl"
  }

  Viewpoint {
    description "Initial view"
    position 0.000000 0.000000 9.000000
  }

  Group {
    children [
      Shape {
        appearance Appearance {
          material Material {
            diffuseColor   0.700000 0.700000 0.700000
            emissiveColor  0.700000 0.700000 0.700000
            shininess      1.000000
          }
        }
        geometry IndexedFaceSet {
          coord Coordinate {
            point [
              -92.000000 25.033333 -1.955000,
              -91.966667 25.033333 -1.959000,
              -91.966667 25.066668 -1.956000,
              -92.000000 25.033333 -1.955000,
              -91.966667 25.066668 -1.956000,
              -92.000000 25.066668 -1.950000,
              -92.000000 25.066668 -1.950000,
              -91.966667 25.066668 -1.956000,
              -91.966667 25.100000 -1.949000,
              -92.000000 25.066668 -1.950000,
              -91.966667 25.100000 -1.949000,
              -92.000000 25.100000 -1.941000,
              -92.000000 25.100000 -1.941000,
...
NOW, download a VRML editor to edit color, texture and stuff. First check if IVCON has this ability.

 

 

vrml_firstattempt.png

Now, how to color map and texture it?

VRML texture library

If the file you need is on the same server as your VRML files you can skip the “http://www.foo.com/” part. Here’s what that might look like if the file was in the same directory as your VRML files…

        url "someimage.jpg"

Written by protian

February 4, 2008 at 4:53 pm

Posted in python script, visualization

Tagged with