[cig-commits] r8349 - cs/portal/trunk
leif at geodynamics.org
leif at geodynamics.org
Wed Nov 28 16:15:05 PST 2007
Author: leif
Date: 2007-11-28 16:15:05 -0800 (Wed, 28 Nov 2007)
New Revision: 8349
Added:
cs/portal/trunk/mineos.cfg
Modified:
cs/portal/trunk/mineos.py
Log:
Wrote a Python script to run the various Mineos programs (minos_bran,
eigcon, green, and syndat) in the proper order for the requested
modes.
Added: cs/portal/trunk/mineos.cfg
===================================================================
--- cs/portal/trunk/mineos.cfg 2007-11-28 23:51:08 UTC (rev 8348)
+++ cs/portal/trunk/mineos.cfg 2007-11-29 00:15:05 UTC (rev 8349)
@@ -0,0 +1,32 @@
+
+[mineos]
+bin-directory = /home/leif/tmp/mineos/bin
+
+event = china_cmt_event
+model = prem_noocean.txt
+
+radial = True
+toroidal = True
+spheroidal = True
+inner-core-toroidal = True
+
+
+# minos_bran
+eps = 1.0e-10
+wgrav = 1*milli*hertz
+lmin = 2
+lmax = 8000
+wmin = 0.0*milli*hertz
+wmax = 200.0*milli*hertz
+nmin = 0
+nmax = 0
+
+# eigcon
+max-depth = 1000*km
+
+# green
+fmin = 10*milli*hertz
+fmax = 260*milli*hertz
+nsamples = 8000
+stations = short
+
Modified: cs/portal/trunk/mineos.py
===================================================================
--- cs/portal/trunk/mineos.py 2007-11-28 23:51:08 UTC (rev 8348)
+++ cs/portal/trunk/mineos.py 2007-11-29 00:15:05 UTC (rev 8349)
@@ -1,5 +1,268 @@
#!/usr/bin/env python
-f = open("output_mineos.txt", "w")
-print >>f, "Hello from Mineos!"
-f.close()
+
+from pyre.applications import Script
+from pyre.units.SI import milli, hertz
+from pyre.units.length import km
+import os, sys
+
+mHz = milli*hertz
+
+
+class Mode(object):
+ def __init__(self, jcom, id, desc):
+ self.jcom = jcom
+ self.id = id
+ self.desc = desc
+
+
+modes = [Mode(jcom, id, desc) for jcom, id, desc in [
+ (1, 'radial', 'radial'),
+ (2, 'toroidal', 'toroidal'),
+ (3, 'spheroidal', 'spheroidal'),
+ (4, 'ictoroidal', 'inner core toroidal'),
+ ]]
+del jcom, id, desc
+
+
+class Mineos(object):
+
+ def __init__(self, bin, model, event, stations):
+ self.bin = bin
+ self.model = model
+ self.event = event
+ self.stations = stations
+ self.eigcon_out = []
+ self.green_out = "green"
+ return
+
+
+ def minos_bran(self,
+ mode,
+ eps, wgrav,
+ lmin, lmax,
+ wmin, wmax,
+ nmin, nmax):
+ minos_bran_in = mode.id + "_mineos_bran.in"
+ s = open(minos_bran_in, "w")
+ print >>s, self.model
+ print >>s, self.listing(mode)
+ print >>s, self.eigenfunctions(mode)
+ print >>s, eps, wgrav
+ print >>s, mode.jcom
+ print >>s, lmin, lmax, wmin, wmax, nmin, nmax
+ s.close()
+ self.run("minos_bran", stdin=minos_bran_in)
+ return
+
+
+ def eigcon(self, mode, max_depth):
+ eigcon_in = mode.id + "_eigcon.in"
+ s = open(eigcon_in, "w")
+ print >>s, mode.jcom
+ print >>s, self.model
+ print >>s, max_depth
+ print >>s, self.listing(mode)
+ print >>s, self.eigenfunctions(mode)
+ dbname = mode.id #+ "_eigcon_out"
+ print >>s, dbname
+ s.close()
+ self.run("eigcon", stdin=eigcon_in)
+ self.eigcon_out.append(dbname)
+ return
+
+
+ def green(self, fmin, fmax, nsamples):
+ s = open("db_list", "w")
+ for dbname in self.eigcon_out:
+ print >>s, dbname
+ green_in = "green.in"
+ s = open(green_in, "w")
+ print >>s, self.stations
+ print >>s, "db_list"
+ print >>s, self.event
+ print >>s, fmin, fmax
+ print >>s, nsamples
+ print >>s, self.green_out
+ s.close()
+ self.run("green", stdin=green_in)
+ return
+
+
+ def syndat(self, plane, datatype):
+ syndat_in = "syndat.in"
+ s = open(syndat_in, "w")
+ print >>s, self.event
+ print >>s, plane # error in documentation!
+ print >>s, self.green_out
+ print >>s, "seismograms" #"syndat_out"
+ print >>s, datatype
+ s.close()
+ self.run("syndat", stdin=syndat_in)
+ return
+
+
+ def listing(self, mode):
+ return mode.id + "_listing"
+
+
+ def eigenfunctions(self, mode):
+ return mode.id + "_eigenfunctions"
+
+
+ def run(self, program, stdin=None, stdout=None, stderr=None):
+ argv = [program]
+ pid = os.fork()
+ if pid:
+ # parent
+ _, status = os.wait()
+ exitStatus = None
+ if (os.WIFSIGNALED(status)):
+ statusStr = "signal %d" % os.WTERMSIG(status)
+ elif (os.WIFEXITED(status)):
+ exitStatus = os.WEXITSTATUS(status)
+ statusStr = "exit %d" % exitStatus
+ else:
+ statusStr = "status %d" % status
+ statusMsg = "%s: %s" % (argv[0], statusStr)
+ if exitStatus != 0:
+ sys.exit(statusMsg)
+ else:
+ # child
+ if stdin is not None:
+ fd = os.open(stdin, os.O_RDONLY)
+ os.dup2(fd, 0)
+ if stdout is not None:
+ fd = os.open(stdout, os.O_WRONLY)
+ os.dup2(fd, 1)
+ if stderr is not None:
+ fd = os.open(stderr, os.O_WRONLY)
+ os.dup2(fd, 2)
+ executable = os.path.join(self.bin, argv[0])
+ try:
+ os.execvp(executable, argv)
+ except Exception, e:
+ sys.exit("%s: %s" % (executable, e))
+
+ return
+
+
+class MineosScript(Script):
+
+ name = "mineos"
+
+ import pyre.inventory as pyre
+
+ bin = pyre.str("bin-directory")
+
+
+ #------------------------------------------------------------------------
+ # common
+
+ model = pyre.str("model")
+
+ # jcom
+ radial = pyre.bool("radial")
+ toroidal = pyre.bool("toroidal")
+ spheroidal = pyre.bool("spheroidal")
+ ictoroidal = pyre.bool("inner-core-toroidal")
+
+ event = pyre.str("event")
+
+
+ #------------------------------------------------------------------------
+ # minos_bran
+
+ eps = pyre.float("eps")
+ wgrav = pyre.dimensional("wgrav", default=1*hertz)
+
+ lmin = pyre.int("lmin")
+ lmax = pyre.int("lmax")
+
+ wmin = pyre.dimensional("wmin", default=1*hertz)
+ wmax = pyre.dimensional("wmax", default=1*hertz)
+
+ nmin = pyre.int("nmin")
+ nmax = pyre.int("nmax")
+
+
+ #------------------------------------------------------------------------
+ # eigcon
+
+ max_depth = pyre.dimensional("max-depth", default=1*km)
+
+
+ #------------------------------------------------------------------------
+ # green
+
+ fmin = pyre.dimensional("fmin", default=1*hertz)
+ fmax = pyre.dimensional("fmax", default=1*hertz)
+
+ nsamples = pyre.int("nsamples")
+
+ stations = pyre.str("stations")
+
+ #------------------------------------------------------------------------
+ # syndat
+
+ plane = pyre.int("plane", default=0) # use CMT tensor components as-is
+ datatype = pyre.int("datatype", default=3) # displacement in nm
+
+
+ def main(self, *args, **kwds):
+ self._info.activate()
+
+ enabledModes = []
+ for mode in modes:
+ if getattr(self, mode.id):
+ enabledModes.append(mode)
+
+ self._info.log("modes: " + ' '.join(["'%s'" % mode.desc for mode in enabledModes]))
+ if not enabledModes:
+ self._info.log("nothing to do")
+ return
+
+ mineos = Mineos(self.bin, self.model, self.event, self.stations)
+
+ # minos_bran
+ for mode in enabledModes:
+ self._info.log("running program 'minos_bran' for '%s' mode" % mode.desc)
+ # convert to millihertz
+ wgrav = self.wgrav / mHz
+ wmin = self.wmin / mHz
+ wmax = self.wmax / mHz
+ mineos.minos_bran(mode, self.eps, wgrav,
+ self.lmin, self.lmax,
+ wmin, wmax,
+ self.nmin, self.nmax)
+
+ # eigcon
+ for mode in enabledModes:
+ self._info.log("running program 'eigcon' for '%s' mode" % mode.desc)
+ # convert to kilometers
+ max_depth = self.max_depth / km
+ mineos.eigcon(mode, max_depth)
+
+ # green
+ self._info.log("running program 'green'")
+ fmin = self.fmin / mHz
+ fmax = self.fmax / mHz
+ mineos.green(fmin, fmax, self.nsamples)
+
+ # syndat
+ self._info.log("running program 'syndat'")
+ mineos.syndat(self.plane, self.datatype)
+
+ return
+
+
+def main(*args, **kwds):
+ mineos = MineosScript()
+ mineos.run(*args, **kwds)
+
+
+if __name__ == "__main__":
+ main()
+
+
+# end of file
More information about the cig-commits
mailing list