/[escript]/trunk/modellib/py_src/tsunami.py
ViewVC logotype

Diff of /trunk/modellib/py_src/tsunami.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 276 by cochrane, Wed Nov 30 04:31:40 2005 UTC revision 281 by elspeth, Wed Nov 30 09:10:59 2005 UTC
# Line 9  from esys.escript.linearPDEs import Line Line 9  from esys.escript.linearPDEs import Line
9  from esys.escript.modelframe import Model  from esys.escript.modelframe import Model
10  import numarray  import numarray
11  import math  import math
12  import urllib  #import urllib
13    import urllib2
14    
15  EPS=1.e-5  EPS=1.e-5
16    
# Line 641  class OceanRegionCollector(Model): Line 642  class OceanRegionCollector(Model):
642             """             """
643             c=self.__mergeParameters(self.coastline_source)             c=self.__mergeParameters(self.coastline_source)
644             b=self.__mergeParameters(self.bathymetry_source)             b=self.__mergeParameters(self.bathymetry_source)
645             self.coastline_stream=urllib.urlopen(c)             self.coastline_stream=urllib2.urlopen(c)
646             self.bathymetry_stream=urllib.urlopen(b)             self.bathymetry_stream=urllib2.urlopen(b)
647    
648        def __mergeParameters(self,txt):        def __mergeParameters(self,txt):
649             return txt.replace("%%west%%",str(self.west))\             return txt.replace("%%west%%",str(self.west))\
# Line 881  class SurfMovie(Model): Line 882  class SurfMovie(Model):
882                                   north=5.,                                   north=5.,
883                                   east=3.,                                   east=3.,
884                                   west=15.,                                   west=15.,
885                                     max_height=1.0,
886                                   filename="movie.mpg")                                   filename="movie.mpg")
887    
888             self.paramsFileString = "REFERENCE_FRAME DECODED\n"             self.paramsFileString = "REFERENCE_FRAME DECODED\n"
# Line 903  class SurfMovie(Model): Line 905  class SurfMovie(Model):
905    
906             self.firstFrame = True             self.firstFrame = True
907    
908         self.imageFiles = []             self.imageFiles = []
909    
910         def doInitialization(self):         def doInitialization(self):
911            """            """
# Line 917  class SurfMovie(Model): Line 919  class SurfMovie(Model):
919            # wndow(south,west,north,east)            # wndow(south,west,north,east)
920    
921            # the bathymmetry colourmap            # the bathymmetry colourmap
922        data = []            data = []
923        data.append([-8000, 0,   0,   0])            data.append([-8000, 0,   0,   0])
924        data.append([-7000, 0,   5,   25])            data.append([-7000, 0,   5,   25])
925        data.append([-6000, 0,   10,  50])            data.append([-6000, 0,   10,  50])
926        data.append([-5000, 0,   80,  125])            data.append([-5000, 0,   80,  125])
927        data.append([-4000, 0,   150, 200])            data.append([-4000, 0,   150, 200])
928        data.append([-3000, 86,  197, 184])            data.append([-3000, 86,  197, 184])
929        data.append([-2000, 172, 245, 168])            data.append([-2000, 172, 245, 168])
930        data.append([-1000, 211, 250, 211])            data.append([-1000, 211, 250, 211])
931        data.append([0,     16,  48,  16])            data.append([0,     16,  48,  16])
932        data.append([300,   70,  150, 50])            data.append([300,   70,  150, 50])
933        data.append([500,   146, 126, 60])            data.append([500,   146, 126, 60])
934        data.append([1000,  198, 178, 80])            data.append([1000,  198, 178, 80])
935        data.append([1250,  250, 230, 100])            data.append([1250,  250, 230, 100])
936        data.append([1500,  250, 234, 126])            data.append([1500,  250, 234, 126])
937        data.append([1750,  252, 238, 152])            data.append([1750,  252, 238, 152])
938        data.append([2000,  252, 243, 177])            data.append([2000,  252, 243, 177])
939        data.append([2250,  253, 249, 216])            data.append([2250,  253, 249, 216])
940        data.append([2500,  255, 255, 255])            data.append([2500,  255, 255, 255])
941    
942        # the amount to scale the data by            # the amount to scale the data by
943            scale = 255.0            scale = 255.0
944            numColours = len(data)            numColours = len(data)
945    
946        # convert the colourmap into something vtk is more happy with            # convert the colourmap into something vtk is more happy with
947            height = numarray.zeros(numColours, numarray.Float)            height = numarray.zeros(numColours, numarray.Float)
948            red = numarray.zeros(numColours, numarray.Float)            red = numarray.zeros(numColours, numarray.Float)
949            green = numarray.zeros(numColours, numarray.Float)            green = numarray.zeros(numColours, numarray.Float)
# Line 1002  class SurfMovie(Model): Line 1004  class SurfMovie(Model):
1004                  h += 1                  h += 1
1005                  transFunc.AddRGBPoint(h, red[i], green[i], blue[i])                  transFunc.AddRGBPoint(h, red[i], green[i], blue[i])
1006    
1007        # set up the lookup table for the wave data            # set up the lookup table for the wave data
1008        refLut = vtk.vtkLookupTable()            refLut = vtk.vtkLookupTable()
1009        self.lutTrans = vtk.vtkLookupTable()            self.lutTrans = vtk.vtkLookupTable()
1010        refLut.Build()            refLut.Build()
1011        alpha = 0.4   # alpha channel value            alpha = 0.7   # alpha channel value
1012        for i in range(256):            for i in range(256):
1013            (r,g,b,a) = refLut.GetTableValue(255-i)                (r,g,b,a) = refLut.GetTableValue(255-i)
1014            if g == 1.0 and b < 0.5 and r < 0.5:                if g == 1.0 and b < 0.5 and r < 0.5:
1015            self.lutTrans.SetTableValue(i, r, g, b, 0.0)                    self.lutTrans.SetTableValue(i, r, g, b, 0.0)
1016            else:                else:
1017            self.lutTrans.SetTableValue(i, r, g-0.2, b, alpha)                    self.lutTrans.SetTableValue(i, r, g-0.2, b, alpha)
1018    
1019            print "Generating the bathymmetry vtk object..."            print "Generating the bathymmetry vtk object..."
1020    
# Line 1064  class SurfMovie(Model): Line 1066  class SurfMovie(Model):
1066    
1067            self.ren.AddActor(bathActor)            self.ren.AddActor(bathActor)
1068    
1069        ### now add the coastline            ### now add the coastline
1070            print "Loading the coastline data..."            print "Loading the coastline data..."
1071    
1072        # make the coastline points            # make the coastline points
1073        coastPoints = vtk.vtkPoints()            coastPoints = vtk.vtkPoints()
1074    
1075        # make the coastline grid            # make the coastline grid
1076        coastGrid = vtk.vtkUnstructuredGrid()            coastGrid = vtk.vtkUnstructuredGrid()
1077    
1078        # now point the points and lines into the grid            # now point the points and lines into the grid
1079        totalCoastPoints = 0            totalCoastPoints = 0
1080        for polyline in self.coastline.polylines:            for polyline in self.coastline.polylines:
1081            numPoints = len(polyline)                numPoints = len(polyline)
1082            coastLine = vtk.vtkPolyLine()                coastLine = vtk.vtkPolyLine()
1083            coastLine.GetPointIds().SetNumberOfIds(numPoints)                coastLine.GetPointIds().SetNumberOfIds(numPoints)
1084            j = 0                j = 0
1085            for point in polyline:                for point in polyline:
1086            coastLine.GetPointIds().SetId(j, j+totalCoastPoints)                    coastLine.GetPointIds().SetId(j, j+totalCoastPoints)
1087            coastPoints.InsertNextPoint(point.long, point.lat, 0.0)                    coastPoints.InsertNextPoint(point.long, point.lat, 0.0)
1088            j += 1                    j += 1
1089            coastGrid.InsertNextCell(coastLine.GetCellType(),                coastGrid.InsertNextCell(coastLine.GetCellType(),
1090                coastLine.GetPointIds())                        coastLine.GetPointIds())
1091            totalCoastPoints += numPoints                totalCoastPoints += numPoints
1092    
1093        coastGrid.SetPoints(coastPoints)            coastGrid.SetPoints(coastPoints)
1094    
1095        # make the coast's mapper            # make the coast's mapper
1096        coastMapper = vtk.vtkDataSetMapper()            coastMapper = vtk.vtkDataSetMapper()
1097        coastMapper.SetInput(coastGrid)            coastMapper.SetInput(coastGrid)
1098    
1099        # make its actor            # make its actor
1100        coastActor = vtk.vtkActor()            coastActor = vtk.vtkActor()
1101        coastActor.SetMapper(coastMapper)            coastActor.SetMapper(coastMapper)
1102        coastActor.GetProperty().SetColor(0,0,0)            coastActor.GetProperty().SetColor(0,0,0)
1103    
1104        # add the actor to the renderer            # add the actor to the renderer
1105        self.ren.AddActor(coastActor)            self.ren.AddActor(coastActor)
1106    
1107            # set up the actor for the wave            # set up the actor for the wave
1108            self.waveActor = vtk.vtkActor()            self.waveActor = vtk.vtkActor()
# Line 1122  class SurfMovie(Model): Line 1124  class SurfMovie(Model):
1124               # vtkobj=...               # vtkobj=...
1125               # save(self.__frame_name)               # save(self.__frame_name)
1126    
1127           # make a reader for the data               # make a reader for the data
1128           waveReader = vtk.vtkXMLUnstructuredGridReader()               waveReader = vtk.vtkXMLUnstructuredGridReader()
1129           waveReader.SetFileName(self.__fn)               waveReader.SetFileName(self.__fn)
1130           waveReader.Update()               waveReader.Update()
1131    
1132               # make the grid               # make the grid
1133               waveGrid = waveReader.GetOutput()               waveGrid = waveReader.GetOutput()
1134           waveGrid.Update()               waveGrid.Update()
1135    
1136               (zMin, zMax) = waveGrid.GetPointData().GetScalars().GetRange()               (zMin, zMax) = waveGrid.GetPointData().GetScalars().GetRange()
1137               print "Wave height range %f - %f" % (zMin, zMax)               print "Wave height range %f - %f" % (zMin, zMax)
# Line 1137  class SurfMovie(Model): Line 1139  class SurfMovie(Model):
1139               # make a mapper for the grid               # make a mapper for the grid
1140               waveMapper = vtk.vtkDataSetMapper()               waveMapper = vtk.vtkDataSetMapper()
1141               waveMapper.SetInput(waveGrid)               waveMapper.SetInput(waveGrid)
1142           waveMapper.SetLookupTable(self.lutTrans)               waveMapper.SetLookupTable(self.lutTrans)
1143               waveMapper.SetScalarRange(zMin, zMax)               waveMapper.SetScalarRange(-self.max_height, self.max_height)
1144    
1145               self.waveActor.SetMapper(waveMapper)               self.waveActor.SetMapper(waveMapper)
1146    
# Line 1165  class SurfMovie(Model): Line 1167  class SurfMovie(Model):
1167               outWriter.Write()               outWriter.Write()
1168               print "Wrote %s" % imgFname               print "Wrote %s" % imgFname
1169    
1170           # helpful for debugging:               # helpful for debugging:
1171           #os.system("display %s" % imgFname)               #os.system("display %s" % imgFname)
1172    
1173               self.paramsFileString += "%s\n" % imgFname               self.paramsFileString += "%s\n" % imgFname
1174           self.imageFiles.append(imgFname)               self.imageFiles.append(imgFname)
1175    
1176               self.__next_t+=self.dt               self.__next_t+=self.dt
1177    
# Line 1205  class SurfMovie(Model): Line 1207  class SurfMovie(Model):
1207            if result != 0:            if result != 0:
1208                print "An error occurred in mpeg conversion"                print "An error occurred in mpeg conversion"
1209    
1210        # now clean up the image files            # now clean up the image files
1211        print "Removing temporary image files"            print "Removing temporary image files"
1212        os.unlink("%s.params" % self.filename)            os.unlink("%s.params" % self.filename)
1213        for fname in self.imageFiles:            for fname in self.imageFiles:
1214            os.unlink(fname)                os.unlink(fname)
1215    
1216  if __name__=="__main__":  def main():
1217     from esys.escript.modelframe import Link,Simulation     from esys.escript.modelframe import Link,Simulation
1218     from esys.modellib.input import Sequencer     from esys.modellib.input import Sequencer
1219    
# Line 1262  if __name__=="__main__": Line 1264  if __name__=="__main__":
1264     sm.t=Link(sq,"t")     sm.t=Link(sq,"t")
1265     sm.dt=5000.     sm.dt=5000.
1266     sm.filename="movie.mpg"     sm.filename="movie.mpg"
1267       sm.max_height=Link(src,"amplitude")
1268        
1269     s=Simulation([sq,oc,b,oreg,src,ts,sm])     s=Simulation([sq,oc,b,oreg,src,ts,sm])
1270     # s.writeXML()     s.writeXML()
1271     s.run()     s.run()
1272    
1273    if __name__=="__main__":
1274        from esys.modellib import tsunami
1275        tsunami.main()
1276    
1277  # vim: expandtab shiftwidth=4:  # vim: expandtab shiftwidth=4:

Legend:
Removed from v.276  
changed lines
  Added in v.281

  ViewVC Help
Powered by ViewVC 1.1.26