[cig-commits] r11758 - cs/portal/trunk/seismo/SeismoWebPortal

leif at geodynamics.org leif at geodynamics.org
Mon Apr 7 01:36:09 PDT 2008


Author: leif
Date: 2008-04-07 01:36:09 -0700 (Mon, 07 Apr 2008)
New Revision: 11758

Modified:
   cs/portal/trunk/seismo/SeismoWebPortal/management.py
   cs/portal/trunk/seismo/SeismoWebPortal/models.py
   cs/portal/trunk/seismo/SeismoWebPortal/views.py
Log:
Implemented snapshot() methods.  Further perfected Request objects &
seismogram table.  Limit Specfem parameter sets to one per model.


Modified: cs/portal/trunk/seismo/SeismoWebPortal/management.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/management.py	2008-04-06 21:58:45 UTC (rev 11757)
+++ cs/portal/trunk/seismo/SeismoWebPortal/management.py	2008-04-07 08:36:09 UTC (rev 11758)
@@ -90,9 +90,22 @@
 
 
 def createSpecfem3DGlobeParameters():
-    # Create a parameter set for every mesh/model combination.
+    # Create a parameter set for desired mesh/model combinations.
+    if False:
+        meshList = models.Specfem3DGlobeMesh.objects.all()
+    else:
+        defaultMesh = models.Specfem3DGlobeMesh.objects.get(
+            nchunks = 6,
+            nproc_xi = 5,
+            nproc_eta = 5,
+            nex_xi_c = 6,
+            nex_eta_c = 6,
+            fsNode__owner__isnull = True,
+            )
+        assert defaultMesh.nex_xi() == defaultMesh.nex_xi() == 240
+        meshList = [defaultMesh]
     for model in models.Specfem3DGlobeModel.objects.all():
-        for mesh in models.Specfem3DGlobeMesh.objects.all():
+        for mesh in meshList:
             parameters = models.Specfem3DGlobeParameters.objects.create(
                 model = model,
                 mesh = mesh,

Modified: cs/portal/trunk/seismo/SeismoWebPortal/models.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/models.py	2008-04-06 21:58:45 UTC (rev 11757)
+++ cs/portal/trunk/seismo/SeismoWebPortal/models.py	2008-04-07 08:36:09 UTC (rev 11758)
@@ -110,6 +110,10 @@
     latitude = models.FloatField(max_digits=19, decimal_places=10, db_index=True)
     longitude = models.FloatField(max_digits=19, decimal_places=10, db_index=True)
 
+    def snapshot(self):
+        # locations are immutable
+        return self.id
+
     @classmethod
     def getLocation(cls, latitude, longitude):
         obj, created = cls.objects.get_or_create(latitude=latitude, longitude=longitude)
@@ -419,6 +423,23 @@
             self.fsNode.save() # touch
         return
 
+    def snapshot(self):
+        if self.location:
+            location = self.location.snapshot()
+        else:
+            location = None
+        return dict(
+            nchunks = self.nchunks,
+            nproc_xi = self.nproc_xi,
+            nproc_eta = self.nproc_eta,
+            nex_xi_c = self.nex_xi_c,
+            nex_eta_c = self.nex_eta_c,
+            angular_width_eta = self.angular_width_eta,
+            angular_width_xi = self.angular_width_xi,
+            location = location,
+            gamma_rotation_azimuth = self.gamma_rotation_azimuth,
+            )
+
     class Admin:
         pass
 
@@ -453,6 +474,17 @@
     def get_type_id(self):
         return model_types[self.type-1][0]
 
+    def snapshot(self):
+        return dict(
+            type = self.type,
+            oceans = self.oceans,
+            gravity = self.gravity,
+            attenuation = self.attenuation,
+            topography = self.topography,
+            rotation = self.rotation,
+            ellipticity = self.ellipticity,
+            )
+
     class Admin:
         pass
 
@@ -496,6 +528,13 @@
             self.fsNode.save() # touch
         return
 
+    def snapshot(self):
+        return dict(
+            mesh = self.mesh.snapshot(),
+            model = self.model.snapshot(),
+            receivers_can_be_buried = self.receivers_can_be_buried,
+            )
+
     class Admin:
         pass
 
@@ -548,8 +587,21 @@
         else:
             self.fsNode.save() # touch
         return
-    
 
+    def snapshot(self):
+        return dict(
+            eps = self.eps,
+            wgrav = self.wgrav,
+            lmin = self.lmin,
+            lmax = self.lmax,
+            wmin = self.wmin,
+            wmax = self.wmax,
+            nmin = self.nmin,
+            nmax = self.nmax,
+            max_depth = self.max_depth,
+            )
+
+
 class MineosModel(models.Model):
 
     fsNode = models.ForeignKey(FSNode, null=True)
@@ -571,7 +623,11 @@
             self.fsNode.save() # touch
         return
 
+    def snapshot(self):
+        # models are immutable
+        return self.id
 
+
 class MineosParameters(models.Model):
 
     fsNode = models.ForeignKey(FSNode, null=True)
@@ -612,7 +668,20 @@
             self.fsNode.save() # touch
         return
 
+    def snapshot(self):
+        return dict(
+            catalog = self.catalog.snapshot(),
+            model = self.model.snapshot(),
+            radial = self.radial,
+            toroidal = self.toroidal,
+            spheroidal = self.spheroidal,
+            ictoroidal = self.ictoroidal,
+            fmin = self.fmin,
+            fmax = self.fmax,
+            step = self.step,
+            )
 
+
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # Event Workspaces
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -636,6 +705,8 @@
     record_length = models.FloatField(max_digits=19, decimal_places=10, core=True, default=20.0,
                                       validator_list=[isValidRecordLength])
 
+    zero_half_duration = models.BooleanField(default=True)
+
     follow = dict(fsNode = False,
                   event = False)
     
@@ -723,32 +794,46 @@
 # Requests
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+CODE_CHOICES = (
+    (1, 'Specfem 3D Globe'),
+    (2, 'Mineos'),
+)
 
-class Specfem3DGlobeRequest(models.Model):
+
+class Request(models.Model):
+
+    # Multi-source Events are immutable.  Point-source Events are
+    # mutable, but the underlying CMTSolution is not.  Therefore:
+    #     event > 0: a CMTSolution.id for a point-source event
+    #     event < 0: a (negated) Event.id for a multi-source event
+    event = models.IntegerField(db_index=True)
     
-    event = models.ForeignKey(Event)
     stations = models.ForeignKey(StationList)
-
-    parameters = models.ForeignKey(Specfem3DGlobeParameters)
-    zero_half_duration = models.BooleanField(default=True)
     record_length = models.FloatField(max_digits=19, decimal_places=10, core=True, default=20.0,
                                       validator_list=[isValidRecordLength])
 
-    runs = models.GenericRelation(Run, db_index=True)
+    code = models.IntegerField(choices=CODE_CHOICES)
+    parameterData = models.TextField()
+
+    runs = models.ForeignKey(Run, db_index=True)
     status = models.ForeignKey(Status, db_index=True)
 
+    def _getParameters(self):
+        import base64
+        import cPickle as pickle
+        p = base64.decodestring(self.parameterData)
+        return pickle.loads(p)
+    parameters = property(lambda self: self._getParameters())
 
-class MineosRequest(models.Model):
-    
-    event = models.ForeignKey(Event)
-    stations = models.ForeignKey(StationList)
+    @classmethod
+    def encodeParameters(cls, parameters):
+        import base64
+        import cPickle as pickle
+        p = pickle.dumps(parameters)
+        return base64.encodestring(p)
 
-    parameters = models.ForeignKey(MineosParameters)
-    record_length = models.FloatField(max_digits=19, decimal_places=10, core=True, default=20.0,
-                                      validator_list=[isValidRecordLength])
 
-    runs = models.GenericRelation(Run, db_index=True)
-    status = models.ForeignKey(Status, db_index=True)
+class Foo:
     
     def nsamples(self):
         from math import ceil

Modified: cs/portal/trunk/seismo/SeismoWebPortal/views.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/views.py	2008-04-06 21:58:45 UTC (rev 11757)
+++ cs/portal/trunk/seismo/SeismoWebPortal/views.py	2008-04-07 08:36:09 UTC (rev 11758)
@@ -1277,41 +1277,31 @@
     html = StringIO()
     print >>html, '<h2>%s - Seismograms</h2>' % workspace
 
-    # 1D Synthetics
-    print >>html, '<h3>1D Synthetics</h3>'
-    print >>html, '<table rules="groups" class="cool">'
-    print >>html, '<thead>'
-    print >>html, '<tr><th>model</th><th>catalog</th><th>status</th></tr>'
-    print >>html, '</thead>'
-    print >>html, '<tbody>'
-    print >>html, '</tbody>'
-    print >>html, '</table>'
+    if event.singleSource:
+        # 1D Synthetics
+        print >>html, '<h3>1D Synthetics</h3>'
+        print >>html, '<table rules="groups" class="cool">'
+        print >>html, '<thead>'
+        print >>html, '<tr><th>parameter set</th><th>status</th><th></th></tr>'
+        print >>html, '</thead>'
+        print >>html, '<tbody>'
+        for i, ps in enumerate(MineosParameters.objects.all()):
+            print >>html, '<tr class=%s><td><a href="%s">%s</a></td><td>unavailable</td><td>%s</td></tr>' % (
+                (i % 2 and 'even' or 'odd'), ps.fsNode.url(), ps, requestForm())
+        print >>html, '</tbody>'
+        print >>html, '</table>'
 
-    print >>html, "<p></p>"
+        print >>html, "<p></p>"
 
     # 3D Synthetics
-    table = {}
-    for ps in Specfem3DGlobeParameters.objects.all():
-        modelGroup = table.setdefault(ps.model.id, {})
-        meshGroup = modelGroup.setdefault(ps.mesh.id, [])
-        meshGroup.append(ps)
-    
     print >>html, '<h3>3D Synthetics</h3>'
     print >>html, '<table rules=groups class=cool>'
     print >>html, '<thead>'
-    print >>html, '<tr><th>model</th><th>mesh</th><th>shortest period (s)</th><th>receivers at depth</th><th>parameter set</th><th>status</th></tr>'
+    print >>html, '<tr><th>parameter set</th><th>status</th><th></th></tr>'
     print >>html, '</thead>'
-    
-    for i, modelGroup in enumerate(table.itervalues()):
-        print >>html, '<tbody class=%s>' % (i % 2 and 'even' or 'odd')
-        for meshGroup in modelGroup.itervalues():
-            for ps in meshGroup:
-                atDepth = img(config.root + "/pics/icon-%s.gif" % (ps.receivers_can_be_buried and "yes" or "no"))
-                print >>html, ('<tr><td>%s</td><td>%s</td><td>%.0f</td><td>%s</td><td>%s</td><td>unavailable</td></tr>' %
-                               (ps.model, ps.mesh, ps.mesh.shortestPeriod(), atDepth, ps)
-                               )
-        print >>html, '</tbody>'
-    
+    for i, ps in enumerate(Specfem3DGlobeParameters.objects.all()):
+        print >>html, '<tr class=%s><td><a href="%s">%s</a></td><td>unavailable</td><td>%s</td></tr>' % (
+            (i % 2 and 'even' or 'odd'), ps.fsNode.url(), ps, requestForm())
     print >>html, '</table>'
     
     window.content = gui.StaticContent(html.getvalue())
@@ -1320,6 +1310,11 @@
     return desktop
 
 
+def requestForm():
+    # NYI
+    return '<form method="post" action="%s/requests/new/"><input type="submit" value="Request" /></form>' % config.root
+
+
 def eventFiles(name, event, request):
     index = Index({
         "CMTSOLUTION.txt": (event_detail_cmtsolution_txt, (), dict(event = event)),



More information about the cig-commits mailing list