[cig-commits] r12983 - in cs/portal/trunk/northridge/SeismoWebPortal: . templates/SeismoWebPortal

leif at geodynamics.org leif at geodynamics.org
Wed Oct 1 18:07:36 PDT 2008


Author: leif
Date: 2008-10-01 18:07:36 -0700 (Wed, 01 Oct 2008)
New Revision: 12983

Modified:
   cs/portal/trunk/northridge/SeismoWebPortal/fformats.py
   cs/portal/trunk/northridge/SeismoWebPortal/forms.py
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_upload.html
Log:
Fixed station list issues raised by Phil Cummins: updated stale
STATIONS documentation; implemented precise error messages which
pinpoint the first bad line in an illegal STATIONS file.


Modified: cs/portal/trunk/northridge/SeismoWebPortal/fformats.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/fformats.py	2008-10-01 23:18:35 UTC (rev 12982)
+++ cs/portal/trunk/northridge/SeismoWebPortal/fformats.py	2008-10-02 01:07:36 UTC (rev 12983)
@@ -8,10 +8,18 @@
 import models
 
 
+class FormatException(Exception):
+    pass
+
+
 class CMTSolutionFormat:
 
     def parse(self, stream):
-        cmt.CMTSolution.parse(stream)
+        # XXX: Improve error reporting.
+        try:
+            cmt.CMTSolution.parse(stream)
+        except Exception:
+            raise FormatException('Please select a file in CMTSOLUTION format.')
         return
 
     def create(self, filename, stream):
@@ -28,9 +36,7 @@
 
         return event
 
-    uploadError = 'Please select a file in CMTSOLUTION format.'
 
-
 class StationListFormat:
     
     def parse(self, stream):
@@ -39,6 +45,8 @@
 
     def _parse(self, stationList, stream):
 
+        tally = 0
+
         for i, line in enumerate(stream):
 
             # parse the line
@@ -48,12 +56,25 @@
                 continue
 
             if len(line) != 6:
-                raise Exception
+                raise FormatException('Line %d has %d fields instead of 6.' % (i + 1, len(line)))
 
             code, network, latitude, longitude, elevation, bur = line
-            latitude, longitude = float(latitude), float(longitude)
-            elevation, bur = float(elevation), float(bur)
 
+            if len(code) > 32:
+                 raise FormatException('Line %d, field 1: length of station name "%s" exceeds 32 characters.' % (i + 1, code))
+            if len(network) > 8:
+                 raise FormatException('Line %d, field 2: length of network name "%s" exceeds 8 characters.' % (i + 1, network))
+            
+            convertedValues = []
+            for j, value in enumerate((latitude, longitude, elevation, bur)):
+                try:
+                    convertedValues.append(float(value))
+                except ValueError:
+                    raise FormatException('Line %d, field %d: expected real number, found "%s".' % (i + 1, j + 3, value))
+            latitude, longitude, elevation, bur = convertedValues
+
+            tally += 1
+
             if stationList is None:
                 continue
 
@@ -72,6 +93,10 @@
                 elevation = elevation,
                 bur = bur,
                 )
+
+        if tally == 0:
+            raise FormatException('Empty station list.')
+        
         return
 
     def create(self, filename, stream):
@@ -81,9 +106,7 @@
         self._parse(stationList, stream)
         return stationList
 
-    uploadError = 'Please select a file in STATIONS format.'
 
-
 class MineosModelFormat:
 
     def parse(self, stream):
@@ -96,7 +119,5 @@
             )
         return mineosModel
 
-    uploadError = 'Please select a file in Mineos model format.'
 
-
 # end of file

Modified: cs/portal/trunk/northridge/SeismoWebPortal/forms.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/forms.py	2008-10-01 23:18:35 UTC (rev 12982)
+++ cs/portal/trunk/northridge/SeismoWebPortal/forms.py	2008-10-02 01:07:36 UTC (rev 12983)
@@ -588,8 +588,8 @@
                 content = new_data['file']['content']
                 stream = StringIO(content)
                 self.format.parse(stream)
-            except Exception:
-                errors['file'] = [self.format.uploadError]
+            except Exception, e:
+                errors['file'] = [str(e)]
 
         return errors
 

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_upload.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_upload.html	2008-10-01 23:18:35 UTC (rev 12982)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_upload.html	2008-10-02 01:07:36 UTC (rev 12983)
@@ -33,9 +33,9 @@
 
 <h3><code>STATIONS</code> file format</h3>
 
-<p>The solver can calculate seismograms at any number of stations for
-basically the same numerical cost, so the user is encouraged to
-include as many stations as conceivably useful in the
+<p>The Specfem solver can calculate seismograms at any number of
+stations for basically the same numerical cost, so the user is
+encouraged to include as many stations as conceivably useful in the
 <code>STATIONS</code> file, which looks like this:</p>
 
 <div class=illustration id=stations>
@@ -43,26 +43,24 @@
     <p class=caption>Sample <code>STATIONS</code> file.</p>
 </div>
 
-<p>Station latitude and longitude should be provided in geographical
-coordinates. The width of the station label should be no more than 32
-characters, and the network label should be no more than 8
-characters.</p>
-
-<p>The first line in this file should indicate the number of stations
-listed.  Each subsequent line represents one station in the following
+<p>Each line in this file represents one station in the following
 format:</p>
 
 <code>Station Network Latitude (degrees) Longitude (degrees) Elevation (m) burial (m)</code>
 
-<p>To accommodate stations with instruments that are buried, select
-"receivers at depth" on the simulation form.  This causes the solver
-to calculate seismograms at the burial depth specified in the
-<code>STATIONS</code> file.</p>
+<p>The width of the station label should be no more than 32
+characters, and the network label should be no more than 8
+characters. Station latitude and longitude should be provided in
+geographical coordinates.</p>
 
 <p>Currently, the code ignores the elevation specified in the
 <code>STATIONS</code> file.  Instead, station elevation is computed
 based upon topography data.</p>
 
+<p>The <code>burial</code> field accommodates stations with
+instruments that are buried.  The solver will calculate seismograms at
+the burial depth specified.</p>
+
 <p><a href="{{root}}/samples/STATIONS.txt">Click here</a> to
 download a sample <code>STATIONS</code> file.</p>
 



More information about the cig-commits mailing list