[cig-commits] r13325 - in cs/portal/trunk/northridge/SeismoWebPortal: . templates/SeismoWebPortal
leif at geodynamics.org
leif at geodynamics.org
Mon Nov 17 19:00:11 PST 2008
Author: leif
Date: 2008-11-17 19:00:11 -0800 (Mon, 17 Nov 2008)
New Revision: 13325
Modified:
cs/portal/trunk/northridge/SeismoWebPortal/fformats.py
cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
cs/portal/trunk/northridge/SeismoWebPortal/models.py
cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_detail.html
cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_list.html
cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobeparameters_form.html
Log:
A 3D model file is simply a compressed 'tar' file containing
Fortran-90 source and data. Extract the descriptions of 3D models
from the 3D model files. Display archive contents on the detail page.
Modified: cs/portal/trunk/northridge/SeismoWebPortal/fformats.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/fformats.py 2008-11-18 00:53:50 UTC (rev 13324)
+++ cs/portal/trunk/northridge/SeismoWebPortal/fformats.py 2008-11-18 03:00:11 UTC (rev 13325)
@@ -6,6 +6,7 @@
import cmt
import models
+import tarfile
class FormatException(Exception):
@@ -110,15 +111,50 @@
class Specfem3DGlobeModelFormat:
def parse(self, stream):
+ try:
+ tgz = tarfile.open("model", 'r:gz', stream)
+ for tarinfo in tgz:
+ pass
+ except tarfile.ReadError:
+ raise FormatException('Please select a file in SPECFEM model format.')
return
def create(self, filename, stream):
- model = models.Specfem3DGlobeModel(name = filename)
+ name = filename
+ if name.endswith(".tgz"):
+ name = name[:-4]
+ elif name.endswith(".tar.gz"):
+ name = name[:-7]
+ model = models.Specfem3DGlobeModel(name = name)
model.save_pathname_file(filename, stream.read(), False)
+ tgz = tarfile.open(model.get_pathname_filename(), 'r:gz')
+ desc = self.extractDescription(tgz)
+ if desc:
+ model.description = desc
+ else:
+ assert False
model.save()
return model
+ def extractDescription(self, tgz):
+ from django.utils.html import escape, linebreaks
+
+ descHtml = None
+ descText = None
+ for tarinfo in tgz:
+ if tarinfo.isreg():
+ name = tarinfo.name
+ if name.endswith("/description.html"):
+ descHtml = tgz.extractfile(tarinfo).read()
+ elif name.endswith("/description.txt"):
+ descText = tgz.extractfile(tarinfo).read()
+ if not descHtml and descText:
+ descHtml = linebreaks(escape(descText))
+
+ return descHtml
+
+
class MineosModelFormat:
def parse(self, stream):
Modified: cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py 2008-11-18 00:53:50 UTC (rev 13324)
+++ cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py 2008-11-18 03:00:11 UTC (rev 13325)
@@ -806,8 +806,25 @@
class Specfem3DGlobeParameters(Object):
Model = models.Specfem3DGlobeParameters
+ @classmethod
+ def create(cls, request):
+ return super(Specfem3DGlobeParameters, cls).create(
+ request,
+ extra_context = cls.extraContext(request)
+ )
+ def update(self, request):
+ return super(Specfem3DGlobeParameters, self).update(
+ request,
+ extra_context = self.extraContext(request)
+ )
+ @classmethod
+ def extraContext(cls, request):
+ return {
+ 'model_choices': Specfem3DGlobeModel.userObjectList(request.user)[0]
+ }
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Mineos
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: cs/portal/trunk/northridge/SeismoWebPortal/models.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/models.py 2008-11-18 00:53:50 UTC (rev 13324)
+++ cs/portal/trunk/northridge/SeismoWebPortal/models.py 2008-11-18 03:00:11 UTC (rev 13325)
@@ -405,10 +405,42 @@
name = models.CharField(maxlength=100)
pathname = models.FileField(upload_to="SeismoWebPortal/models")
+ description = models.TextField(blank=True)
def __str__(self): return self.name
+ def list(self, verbose=True):
+ import tarfile, time
+ from StringIO import StringIO
+ tgz = tarfile.open(self.get_pathname_filename(), 'r:gz')
+ stream = StringIO()
+
+ for tarinfo in tgz:
+ if verbose:
+ print >>stream, tarfile.filemode(tarinfo.mode),
+ print >>stream, "%s/%s" % (tarinfo.uname or tarinfo.uid,
+ tarinfo.gname or tarinfo.gid),
+ if tarinfo.ischr() or tarinfo.isblk():
+ print >>stream, "%10s" % ("%d,%d" \
+ % (tarinfo.devmajor, tarinfo.devminor)),
+ else:
+ print >>stream, "%10d" % tarinfo.size,
+ print >>stream, "%d-%02d-%02d %02d:%02d:%02d" \
+ % time.localtime(tarinfo.mtime)[:6],
+
+ print >>stream, tarinfo.name,
+
+ if verbose:
+ if tarinfo.issym():
+ print >>stream, "->", tarinfo.linkname,
+ if tarinfo.islnk():
+ print >>stream, "link to", tarinfo.linkname,
+ print >>stream
+
+ return stream.getvalue()
+
+
class Specfem3DGlobeParameters(Model, EditableObject):
name = models.CharField(maxlength=100)
Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_detail.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_detail.html 2008-11-18 00:53:50 UTC (rev 13324)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_detail.html 2008-11-18 03:00:11 UTC (rev 13325)
@@ -1,6 +1,8 @@
<h2><img src="{{root}}/images/s20rts.gif" width=32 height=32> {{ object }}</h2>
+{{ object.description }}
+
<pre>
-{{ object.pathname }}
+{{ object.list }}
</pre>
Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_list.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_list.html 2008-11-18 00:53:50 UTC (rev 13324)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_list.html 2008-11-18 03:00:11 UTC (rev 13325)
@@ -7,6 +7,7 @@
<thead>
<tr>
<th>name</th>
+ <th>description</th>
</tr>
</thead>
@@ -14,6 +15,7 @@
{% for object in object_list %}
<tr class="{% cycle odd,even %}" id="o{{object.id}}" onclick="location.href='{{root}}/?class=Specfem3DGlobeModel&object={{object.id}}'">
<td><a href="{{root}}/?class=Specfem3DGlobeModel&object={{object.id}}">{{ object }}</a></td>
+ <td>{{ object.description }}</td>
</tr>
{% endfor %}
</tbody>
Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobeparameters_form.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobeparameters_form.html 2008-11-18 00:53:50 UTC (rev 13324)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobeparameters_form.html 2008-11-18 03:00:11 UTC (rev 13325)
@@ -53,15 +53,11 @@
<dl class="help inline collapsible collapsedOnLoad"><dt class="collapsibleHeader"><img src="{{root}}/images/help-small.gif"></dt>
<dd class="collapsibleContent">
<dl>
- <dt>crust2.0+prem</dt><dd>This model has CRUST2.0 [Bassin et al., 2000] on top of a transversely isotropic PREM. We first extrapolate PREM mantle velocity up to the surface, then overwrite the model with CRUST2.0.</dd>
-
- <dt>s20rts</dt><dd>By default, the code uses 3D mantle model S20RTS [Ritsema et al., 1999] and 3D crustal model Crust2.0 [Bassin et al., 2000]. Note that S20RTS uses transversely isotropic PREM as a background model, and that we use the PREM radial attenuation model when 'attenuation' is selected.</dd>
-
- <dt>s362ani</dt><dd>A global shear-wave speed model developed by Kustowski et al. [2006]. In this model, radial anisotropy is confined to the uppermost mantle. The model (and the corresponding mesh) incorporate tomography on the 650~km and 410~km discontinuities in the 1D reference model REF.</dd>
-
- <dt>s362wmani</dt><dd>A version of S362ANI with anisotropy allowed throughout the mantle.</dd>
- <dt>s362ani+prem</dt><dd>A version of S362ANI calculated using PREM as the 1D reference model.</dd>
- <dt>s29ea</dt><dd>A global model with higher resolution in the upper mantle beneath Eurasia calculated using REF as the 1D reference model.</dd>
+ {% for model in model_choices %}
+ {% if model.description %}
+ <dt>{{ model }}</dt><dd>{{ model.description }}</dd>
+ {% endif %}
+ {% endfor %}
</dl>
</dd>
</dl>
More information about the CIG-COMMITS
mailing list