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

leif at geodynamics.org leif at geodynamics.org
Mon May 19 17:49:34 PDT 2008


Author: leif
Date: 2008-05-19 17:49:34 -0700 (Mon, 19 May 2008)
New Revision: 11984

Added:
   cs/portal/trunk/northridge/SeismoWebPortal/gmt.py
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_map.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_map.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_map.html
Modified:
   cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_detail.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_list.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_detail.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_detail.html
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/style.css
   cs/portal/trunk/northridge/SeismoWebPortal/urls.py
   cs/portal/trunk/northridge/SeismoWebPortal/views.py
Log:
Merged GMT stuff.


Copied: cs/portal/trunk/northridge/SeismoWebPortal/gmt.py (from rev 11983, cs/portal/trunk/seismo/SeismoWebPortal/gmt.py)
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/gmt.py	                        (rev 0)
+++ cs/portal/trunk/northridge/SeismoWebPortal/gmt.py	2008-05-20 00:49:34 UTC (rev 11984)
@@ -0,0 +1,755 @@
+
+
+import os
+import shutil
+
+from os.path import join, isdir
+from popen2 import Popen3
+from tempfile import mkdtemp, TemporaryFile
+from django.conf import settings
+from django.http import HttpResponse, Http404
+from django.shortcuts import get_object_or_404
+
+
+GMT_ROOT = os.path.join(settings.MEDIA_ROOT, 'SeismoWebPortal', 'gmt')
+gmt_bin = join(os.environ['WEBPORTAL_GMT_ROOT'], "bin")
+netCDF_lib = join(os.environ['WEBPORTAL_NETCDF_ROOT'], "lib")
+
+
+def psmeca(cmt, filename, args):
+
+    # Create a temporary directory and 'cd' there, so that '.gmt*'
+    # files get cleaned-up.
+    owd = os.getcwd()
+    workdir = mkdtemp()
+    os.chdir(workdir)
+    os.putenv("LD_LIBRARY_PATH", netCDF_lib)
+
+    # Spawn 'psmeca' to draw the beachball.
+    child = Popen3([join(gmt_bin, "psmeca"), '-R0/10/0/10', '-Jx1', '-G255/0/0', '-L2', '-K', '-V', '-P'] + args)
+    print >>child.tochild, "3 5 0 %f %f %f %f %f %f 1 0 0" % (
+        cmt.Mrr, cmt.Mtt, cmt.Mpp, cmt.Mrt, cmt.Mrp, cmt.Mtp)
+    child.tochild.close()
+
+    os.chdir(owd)
+
+    # Direct the PostScript output to a file.
+    ps = join(workdir, "beachball.ps")
+    stream = open(join(workdir, ps), 'w')
+    shutil.copyfileobj(child.fromchild, stream)
+    stream.close()
+    status = child.wait()
+    if not (os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0):
+        raise Http404
+
+    # Convert the PostScript to a GIF file.
+    spawn("/usr/bin/convert",
+          '+antialias',
+          '-fill', '#00F', '-draw', 'color 0,0 floodfill', '-transparent', '#00F',
+          '-trim', '+repage',
+          ps, filename)
+
+    shutil.rmtree(workdir)
+
+    return
+
+
+def stationsMap(stationList, filename):
+    # Based on:
+    #  globe_fig_CIG.pl
+    #  Carl Tape
+    #  03-Oct-2007
+
+    # Plots a global map.  The figure shows two perspectives of the
+    # globe, 180 degrees apart.
+
+    owd = os.getcwd()
+    workdir = mkdtemp()
+    os.chdir(workdir)
+    os.putenv("LD_LIBRARY_PATH", netCDF_lib)
+
+    #==========================================================
+    
+    # save stations to a file for plotting in GMT
+    stafile_gmt = join(workdir, "stations")
+    stream = open(stafile_gmt, "w")
+    nstation = 0
+    for station in stationList.station_set.all():
+        stream.write("%10.4f %8.4f %-5s %-3s %6.1f %6.1f\n" % 
+                     (station.longitude, station.latitude,
+                      station.code, station.network.code,
+                      station.elevation, station.bur))
+        nstation += 1
+    stream.close()
+
+    # plate boundaries
+    plate_boundary = "/home/leif/archive/CIG_fig/stations/bird_boundaries"
+
+    #==========================================================
+
+    # bounds and dimensions
+    wid = 7
+    R1 = "-Rg"; J1 = "-JK180/%si" % wid  # [0, 360]
+    R2 = "-Rd"; J2 = "-JK0/%si" % wid    # [-180, 180]
+    B = "-B60/30"               # tick marks on globe
+    Btop = "%s::WSEN" % B
+    Bbot = "%s::WSEN" % B
+    origin = "-X0.75 -Y1.5"
+
+    # plotting specifications
+    fsize1 = "18"
+    fsize2 = "12"
+    fontno = "1"
+    tick   = "0.2c"
+    fpen   = "2p"
+    tpen   = "2p"
+    
+    # plotting specificiations
+    
+    # A : smallest feature plotted, in km^2; D : resolution
+    coast_res       = "-A1000/0/1 -Dl"
+    coast_info      = coast_res + " -W0.5p -S220/255/255 -C220/255/255 -G200"
+    plate_infoR     = "-M -W1p,255/0/0"
+    stat_info      = "-N -W1p,0/0/0 -G255/0/0 -Si10p"
+    
+    # common to all figures
+    J_title = "-JM%s" % wid
+    R_title = "-R0/1/0/1"
+
+    #==================================================
+
+    # title and sub-title
+    title1 = "%s (%d stations)" % (stationList.name, nstation)
+    title2 = "(plate boundaries of Peter Bird, 2003)"
+
+    bin = gmt_bin
+    psfile = join(workdir, "map.ps")
+
+    # set GMT default commands
+    os.system("%(bin)s/gmtset BASEMAP_TYPE plain PLOT_DEGREE_FORMAT D TICK_LENGTH %(tick)s LABEL_FONT_SIZE %(fsize2)s ANOT_FONT_SIZE %(fsize2)s  HEADER_FONT %(fontno)s ANOT_FONT %(fontno)s LABEL_FONT %(fontno)s HEADER_FONT_SIZE %(fsize1)s FRAME_PEN %(fpen)s TICK_PEN %(tpen)s MEASURE_UNIT inch" % locals())
+
+    #--------------------
+    # lower plot
+
+    os.system("%(bin)s/psbasemap %(J2)s %(R2)s %(Bbot)s -K -V -P %(origin)s > %(psfile)s" % locals())  # START (no -O)
+    os.system("%(bin)s/pscoast %(J2)s %(R2)s %(Bbot)s %(coast_info)s -K -O -V >> %(psfile)s" % locals())              # coastlines
+    os.system("%(bin)s/psxy %(J2)s %(R2)s %(plate_boundary)s %(plate_infoR)s -K -O -V  >> %(psfile)s" % locals())     # plate boundaries
+    os.system("%(bin)s/psxy %(stafile_gmt)s %(J2)s %(R2)s %(stat_info)s -K -O -V >>%(psfile)s" % locals())          # stations
+
+    #--------------------
+    # upper plot
+
+    shift = "-Y4.25"
+    os.system("%(bin)s/psbasemap %(J1)s %(R1)s %(Btop)s -K -O -V %(shift)s >> %(psfile)s" % locals())
+    os.system("%(bin)s/pscoast %(J1)s %(R2)s %(Btop)s %(coast_info)s -K -O -V >> %(psfile)s" % locals())
+    os.system("%(bin)s/psxy %(J1)s %(R1)s %(plate_boundary)s %(plate_infoR)s -K -O -V  >> %(psfile)s" % locals())
+    os.system("%(bin)s/psxy %(stafile_gmt)s %(J1)s %(R1)s %(stat_info)s -K -O -V >>%(psfile)s" % locals())
+
+    inFile(" 0.5 0.6 %(fsize2)s 0 %(fontno)s CM %(title2)s\n" % locals())
+    os.system("%(bin)s/pstext -N %(J_title)s %(R_title)s -K -O -V >>%(psfile)s<inFile" % locals())
+
+    inFile(" 0.5 0.65 %(fsize1)s 0 %(fontno)s CM %(title1)s\n" % locals())
+    os.system("%(bin)s/pstext -N %(J_title)s %(R_title)s -O -V >>%(psfile)s<inFile" % locals()) # FINISH (no -K)
+
+
+    #==================================================
+
+    os.chdir(owd)
+    
+    # Convert the PostScript to a JPG file.
+    spawn("/usr/bin/convert", '-trim', '+repage', psfile, filename)
+
+    shutil.rmtree(workdir)
+
+    return
+
+
+def wiggleMap(cmt,
+              filename,
+              stationList = None,
+              opt_a=None,
+              opt_A=None,
+              opt_B=None,
+              opt_c=None,
+              opt_D=None,
+              opt_G=None,
+              opt_l=None,
+              opt_L=None,
+              opt_e=None, opt_m=None,
+              opt_M=None,
+              opt_R=None,
+              opt_s=None,
+              opt_S=None,
+              opt_t=None,
+              opt_W=None,
+              opt_V=None,
+              ):
+    # Based on:
+    #  plot_wig_map.pl
+    #  Vala Hjorleifsdottir
+    #  Feb 27 2003
+
+    # align_phase -- one of o,p,s,r,l,number, aligns phase with station loc.
+    align = None
+    if opt_a is not None:
+        if opt_a in "opsrl":
+            align = opt_a
+        else:
+            try:
+                align = float(opt_a)
+            except ValueError:
+                assert False, "Align on o,p,s,r,l or number, not: %r" % opt_a
+
+    # plot antipode [useful for global map]
+    if opt_A and not opt_R:
+        plot_antipode = True
+        arc_min = None
+        arc_max = None
+    elif not opt_A and not opt_R:
+        plot_antipode = False
+        arc_min = -1
+        arc_max = 90
+
+    # plot both sides of globe [also for global maps]
+    if opt_B:
+        nr_of_plots = 2
+    else:
+        nr_of_plots = 1
+
+    # cut0/cut1 -- plot data from cut1 to cut2 relative to align_phase [no cut]
+    if opt_c:
+        cut_option = "-C%s/%s" % opt_c
+    else:
+        cut_option = ""
+
+    # xshift/yshift -- shifts trace by these amounts of MEASURE_UNIT [no shift]
+    if opt_D:
+        shift_option = "-D%s" % opt_D
+    else:
+        shift_option = "-D0/0"
+
+    # plot great circle path
+    if opt_G:
+        plot_greatcircle = True
+    else:
+        plot_greatcircle = False
+
+    # tscale -- seconds/inch, controls length of trace [3600]
+    if opt_l:
+        tscale = opt_l
+    else:
+        tscale = "3600"
+
+    # Landscape
+    if opt_L:
+        landscape = True
+    else:
+        landscape = False
+
+    # Lat/Lon -- give either -e or -m to determine center of map
+    if not opt_m and not opt_e:
+        assert False, "You have to specify either -e Lat/Lon or -m CMTFILE"
+    if opt_e:
+        plot_mecha = False
+    # CMT-file -- CMT-file in HVD format, plots mechanism on map
+    if opt_m:
+        plot_mecha = True
+
+    # scale -- scale for seismograms, type pssac2 for options
+    if opt_M:
+        wig_scale = opt_M
+    else:
+        wig_scale = "N/A"
+
+    # lon1/lon2/lat1/lat2/tick_x/tick_y/width/x/y - regional map. Width of map and x and y of lower left corner [in inches].
+    if opt_R:
+        regional = True
+        min_lon, max_lon, min_lat, max_lat, tick_x, tick_y, scale, x, y = opt_R
+        plot_antipode = False
+        arc_min = 0
+        arc_max = 180
+    else:
+        regional = False
+        min_lon, max_lon, min_lat, max_lat, tick_x, tick_y, scale, x, y = None, None, None, None, None, None, None, None, None
+
+    # plot stations
+    if stationList:
+        plot_stations = True
+    else:
+        plot_stations = False
+    
+    # syndir,synsuff -- plot synthetics SYNDIR/*synsuff correpsonding to datafiles
+    if opt_S:
+        syn_dir, syn_suff = opt_S
+        assert isdir(syn_dir), "No such directory: %s" % syn_dir
+        plot_syn = True
+    else:
+        syn_dir, syn_suff = None, None
+        plot_syn = False
+
+    # title -- title of plot [no title]
+    if opt_t:
+        title = opt_t
+    else:
+        title = ""
+
+    # plot wiggles (give datafiles at the end)
+    if opt_W:
+        plot_wiggles = True
+    else:
+        plot_wiggles = False
+
+    assert not landscape or regional, "You can only use landscape for regional plots"
+    assert opt_M or not plot_wiggles, "Specify scale for wiggles"
+    if plot_wiggles and plot_syn and not '/' in opt_M:
+        assert False, "Don't use relative scale when plotting both data and synthetics -- change -M option"
+    assert plot_wiggles or not plot_syn, "Have to specify datafiles to pick corresponding synthetics"
+
+    # verbose
+    if opt_V:
+        if not opt_l and plot_wiggles:
+            print "Using default timescale, 1hour/inch"
+        print "Aligning on: %s" % align
+        print "Plotting antipode? %s" % plot_antipode
+        print "Cutting from/to sec: %s" % opt_c
+        #print "Moment tensor file: %s" % cmt_file
+        print "Scale for wiggles: %s" % wig_scale
+        print "Name of outputfile: %s" % PS_OUT
+        print "Plotting stations? %s" % plot_stations
+        print "Plotting synthetics? %s" % plot_syn
+        print "Title of plot: %s" % title
+        print "Plotting wiggles: %s" % plot_wiggles
+        print "Scale for wiggles: %s" % wig_scale
+        V_option=" -V "
+    else:
+        V_option = ""
+
+
+    if plot_mecha:
+        event_lat = cmt.latitude
+        event_lon = cmt.longitude
+    else:
+        event_lat, event_lon = opt_e
+
+    args = [
+        align, plot_antipode,
+        arc_min, arc_max,
+        cut_option, shift_option,
+        plot_greatcircle, tscale, landscape, plot_mecha,
+        wig_scale, regional,
+        min_lon, max_lon, min_lat, max_lat, tick_x, tick_y, scale, x, y,
+        plot_stations,
+        plot_syn, syn_dir, syn_suff,
+        title,
+        plot_wiggles,
+        V_option,
+        event_lat, event_lon,
+        opt_R,
+        ]
+
+    owd = os.getcwd()
+    workdir = mkdtemp()
+    os.chdir(workdir)
+    os.putenv("LD_LIBRARY_PATH", netCDF_lib)
+
+    PS_OUT = join(workdir, "map.ps")
+
+    plotWiggleMap(1, nr_of_plots, cmt, stationList, PS_OUT, *args)
+    if nr_of_plots == 2:
+        plotWiggleMap(2, nr_of_plots, cmt, stationList, PS_OUT, *args)
+
+    os.chdir(owd)
+    
+    # Convert the PostScript to a JPG file.
+    spawn("/usr/bin/convert", '-trim', '+repage', PS_OUT, filename)
+
+    shutil.rmtree(workdir)
+
+    return
+
+
+def plotWiggleMap(plot_nr, nr_of_plots,
+                  cmt, stationList, PS_OUT,
+                  # *args
+                  align, plot_antipode,
+                  arc_min, arc_max,
+                  cut_option, shift_option,
+                  plot_greatcircle, tscale, landscape, plot_mecha,
+                  wig_scale, regional,
+                  min_lon, max_lon, min_lat, max_lat, tick_x, tick_y, scale, x, y,
+                  plot_stations,
+                  plot_syn, syn_dir, syn_suff,
+                  title,
+                  plot_wiggles,
+                  V_option,
+                  event_lat, event_lon,
+                  opt_R,
+                  ):
+    
+    #########################
+    #Deciding on plot options
+    #########################
+
+    #@data_files=@data_files_original;
+
+    if nr_of_plots > 1:
+        landscape = True
+        if plot_nr == 1:
+            plot_antipode = False
+        elif plot_nr == 2:
+            plot_antipode = True
+        else:
+            assert False, "confusing plot_nr: $plot_nr - something broke in script"
+
+    if plot_antipode:
+        arc_min = 90
+        arc_max = 180
+        event_lat = -event_lat
+        if event_lon > 0:
+            event_lon = event_lon-180
+        else:
+            event_lon = event_lon+180
+    elif not regional:
+        arc_min = -1
+        arc_max = 90
+
+    if regional:
+        x=x+1
+        y=y+2
+        bounds="-R%s/%s/%s/%s" % (min_lon, max_lon, min_lat, max_lat)
+        proj = "-JM%s" % scale
+        tick   = "-B%s/%sSWen" % (tick_x, tick_y)
+        if max_lon-min_lon > 30:
+            resolution="-Dl -A1000"
+        elif max_lon-min_lon<=30 and max_lon-min_lon>5:
+            resolution="-Di -A100"
+        elif max_lon-min_lon<=5 and max_lon-min_lon>1:
+            resolution="-Dh -A10"
+        else:
+            resolution="-Df -A1"
+    else:
+        if nr_of_plots==1:
+            scale = 7.0
+            x=0.7
+            y=1.8
+        else:
+            scale=4.9
+            if plot_nr==1:
+                x=0.5
+                y=1.8
+            else:
+                x=5.6
+                y=1.8
+        proj = "-JA%s/%s/%s" % (event_lon, event_lat, scale)
+        bounds = "-R-180/180/-90/90"
+        tick   = "-B60/60"
+        resolution="-Dl -A1000"
+
+    if landscape:
+        p_option=""
+        #  l="-l4.8/-0.2/1/0.1/8"
+        if nr_of_plots==1:
+            lx=5.2-x
+            ly=1.2-y
+            time_loc=" 5.2 0.8 "
+            tit_loc=" 5.2 7.2 "
+        else:
+            lx=5.5-x
+            ly=1.9-y
+            time_loc=" 5.5 1.5 "
+            tit_loc=" 5.5 6.7 "
+        l="-l%s/%s/1/0.1/8" % (lx, ly)
+    else:
+        p_option="-P"
+        lx=4.2-x
+        ly=1.6-y
+        l="-l%s/%s/1/0.1/8" % (lx, ly)
+        time_loc=" 4.2 1.2 "
+        tit_loc=" 4.2 9.2 "
+  
+    scale2 = 1.10*scale/3
+    scale3 = 2.12*scale/3
+
+    bin = gmt_bin
+
+    # set GMT default commands
+    os.system("%(bin)s/gmtset MEASURE_UNIT inch DEGREE_FORMAT 3 BASEMAP_TYPE plain DOTS_PR_INCH 600 PAPER_MEDIA letter+" % locals())
+
+    if isinstance(align, float):
+        e_label = "-En%f" % align
+        time_label = "Time-distance/%f (km/s) [s]" % align
+    else:
+        alignMap = {
+            'o': ("-Ent-3", "Time (s) from event"),
+            'p': ("-Ent1",  "Time (s) (aligned on p)"),
+            's': ("-Ent2",  "Time (s) (aligned on s)"),
+            'r': ("-En3.8", "Time-distance/3.8(km/s) (s)"),
+            'l': ("-En4.4", "Time-distance/4.4(km/s) (s)"),
+            None: (None, None)
+            }
+        e_label, time_label = alignMap[align]
+  
+    if plot_stations or plot_wiggles:
+        if not opt_R:
+            #@data_files=sac_files_prune("gcarc",$arc_min,$arc_max, at data_files);
+            pass
+        else:
+            #@data_files=sac_files_prune("stla",$min_lat,$max_lat, at data_files);
+            #@data_files=sac_files_prune("stlo",$min_lon,$max_lon, at data_files);
+            pass
+
+        #foreach $file (@data_files){chomp($file);}
+        #@stlat=sac_files_get_values('stla', at data_files);
+        #@stlon=sac_files_get_values('stlo', at data_files);
+        #@stname = sac_files_get_values('kstnm', at data_files);
+        #@stnetwk = sac_files_get_values('knetwk', at data_files);
+        #@stcomp=sac_files_get_values('kcmpnm', at data_files);
+        if plot_wiggles and plot_nr==1:
+            title="$title $stcomp[0]"
+  
+    ### PLOTTING ###
+  
+    ##
+    #Plotting basemap (with equal distance rings)-S150/200/255 -G200/255/150 -G240/240/240 -S255/255/255
+    ##
+    if plot_nr==1:
+        O_option=""
+        output=">"
+    else:
+        O_option="-O"
+        output=">>"
+        
+    os.system("%(bin)s/pscoast %(bounds)s %(proj)s %(tick)s %(resolution)s -W1/0/0/255 -S150/200/255 -G200/255/150  -K %(O_option)s %(V_option)s -X%(x)s -Y%(y)s %(p_option)s %(output)s %(PS_OUT)s" % locals())
+    if not regional:
+        inFile("%s %s" % (event_lon, event_lat))
+        os.system("%(bin)s/psxy %(bounds)s %(proj)s -Sc%(scale2)s -W2/0 -K -O %(V_option)s >>%(PS_OUT)s <inFile" % locals())
+        os.system("%(bin)s/psxy %(bounds)s %(proj)s -Sc%(scale3)s -W2/0 -K -O %(V_option)s >>%(PS_OUT)s <inFile" % locals())
+
+    ##
+    #Plotting the event_location:
+    ##
+
+    if not plot_antipode and plot_mecha:
+        inFile("%f %f 0 %f %f %f %f %f %f 1 0 0" % (
+            event_lon, event_lat, cmt.Mrr, cmt.Mtt, cmt.Mpp, cmt.Mrt, cmt.Mrp, cmt.Mtp))
+        os.system("%(bin)s/psmeca %(bounds)s %(proj)s -Sm0.3 -L2 -G255/0/0 -T0 -K -O %(V_option)s >> %(PS_OUT)s <inFile" % locals())
+    else:
+        inFile("%s %s" % (event_lon, event_lat))
+        os.system("%(bin)s/psxy %(bounds)s %(proj)s -Sc0.1 -G255/255/0 -W2/0 -K -O %(V_option)s >>%(PS_OUT)s <inFile" % locals())
+
+    if plot_stations:
+        PSXYst = open("PSXYst", "w")
+        PSXYstn = open("PSXYstn", "w")
+        for station in stationList.station_set.all():
+            PSXYst.write("%10.4f %8.4f 8 0 4 CB  \n" %
+                         (station.longitude, station.latitude))
+            PSXYstn.write("%10.4f %8.4f 8 0 4 CB %s \n" %
+                          (station.longitude, station.latitude, station.code))
+        PSXYst.close()
+        PSXYstn.close()
+        
+        #Plotting the stations:
+        os.system("%(bin)s/psxy %(bounds)s %(proj)s -St0.1 -G255/0/0 -W2/0 -K -O %(V_option)s >> %(PS_OUT)s <PSXYst" % locals())
+
+        #Plotting the station-names:
+        if False:
+            # messy with full station list; would need to be pruned
+            os.system("%(bin)s/pstext %(bounds)s %(proj)s -D0/0.05 -N -K -O %(V_option)s >> %(PS_OUT)s <PSXYstn" % locals())
+  
+    if plot_greatcircle:
+        #open(PSXYgcarc,"|psxy $bounds $proj -W5/0 -K -M -O $V_option >> %(PS_OUT)s");
+        #for($i = 0; $i < @data_files; $i++){print PSXYgcarc ">\n$event_lon $event_lat\n$stlon[$i] $stlat[$i]\n";}
+        #close(PSXYgcarc);
+        pass
+
+    if plot_wiggles:
+        #print "Plotting data\n";
+        #print "$pssac2 $bounds $proj $shift_option $l -M$wig_scale -N $cut_option -W2p/0/0/0 -L$tscale  $e_label -P -O -K -V \n";
+        #open(PSSAC2, "| $pssac2 $bounds $proj $shift_option $l -M$wig_scale -N $cut_option -W2p/0/0/0 -L$tscale  $e_label -P -O -K -V >> %(PS_OUT)s;") or die "pssac2 failed";
+        #for($i = 0;$i<@data_files;$i++){print PSSAC2 "$data_files[$i] $stlon[$i] $stlat[$i] 0.5p/0/0/0\n";}
+        #close(PSSAC2);
+        pass
+
+    if plot_syn:
+        #print "Plotting synthetics \n";
+        #my(@syn_files);
+        #for($i=0; $i<@data_files; $i++){
+        #  $syn_file="${syn_dir}/$stname[$i].$stnetwk[$i].$stcomp[$i]$syn_suff";
+        #  if(-e $syn_file){
+        #    push @syn_files, $syn_file;
+        #  }
+        #}
+        #@sylat=sac_files_get_values('stla', at syn_files);
+        #@sylon=sac_files_get_values('stlo', at syn_files);
+        #open(PSSAC2, "| $pssac2 $bounds $proj $shift_option  -M$wig_scale -N $cut_option -W2p/0/0/0 -L$tscale $e_label -P -O -K -V >> $PS_OUT") or die "pssac2 failed";
+        #for($i = 0;$i<@syn_files;$i++){print PSSAC2 "$syn_files[$i] $sylon[$i] $sylat[$i] 0.5p/255/0/0\n";}
+        #close(PSSAC2);
+        pass
+  
+    if plot_wiggles or plot_syn:
+        #system("echo $time_loc 16 0 5 CM \"$time_label\" | pstext -R0/10/0/10 -Jx1 -X-$x -Y-$y -K -O $V_option>>%(PS_OUT)s");
+        #x=0
+        #y=0
+        pass
+
+
+    #Plotting title:
+    if title:
+        inFile('%s 24 0 5 CM %s' % (tit_loc, title))
+        os.system("%(bin)s/pstext -R0/10/0/10 -Jx1 -O %(V_option)s -X-%(x)s -Y-%(y)s >>%(PS_OUT)s <inFile" % locals())
+
+    return
+
+
+def spawn(*argv):
+    status = os.spawnvp(os.P_WAIT, argv[0], argv)
+    if status != 0:
+        raise Http404("%s: exit %d" % (argv[0], status))
+    return
+
+
+def inFile(text):
+    s = open("inFile", 'w')
+    s.write(text)
+    s.close()
+
+
+def intOr404(name):
+    try:
+        ret = int(name)
+    except ValueError:
+        raise Http404
+    return ret
+
+
+def serve(request, pathname):
+    from django.views.static import serve as staticServe
+    from os import makedirs
+    from models import Source, StationList
+
+    document_root = GMT_ROOT
+    
+    try:
+        return staticServe(request, pathname, document_root)
+    except Http404:
+        pass
+
+    path = pathname.split('/')
+    if not path: raise Http404
+    name = path.pop(0)
+
+    if name == "beachballs":
+        dirname = join(document_root, name)
+        if not path: raise Http404
+        name = path.pop(0)
+
+        objId = intOr404(name)
+        source = get_object_or_404(Source, id=objId)
+        dirname = join(dirname, name)
+
+        if not path: raise Http404
+        name = path.pop(0)
+        if path: raise Http404
+
+        if name == "icon_large.gif":
+            args = ['-M', '-Sm1.1']
+        elif name == "icon_small.gif":
+            args = ['-M', '-Sm0.5']
+        elif name == "detail.gif":
+            args = ['-M', '-Sm4.0']
+        elif name == "proportional.gif":
+            args = ['-Sm1.0']
+        else:
+            raise Http404
+
+        if not isdir(dirname):
+            makedirs(dirname)
+        filename = join(dirname, name)
+
+        psmeca(source, filename, args)
+
+    elif name == "maps":
+        dirname = join(document_root, name)
+        if not path: raise Http404
+        name = path.pop(0)
+
+        if name == "stations":
+            dirname = join(dirname, name)
+            if not path: raise Http404
+            name = path.pop(0)
+
+            objId = intOr404(name)
+            stationList = get_object_or_404(StationList, id=objId)
+            dirname = join(dirname, name)
+
+            if not path: raise Http404
+            name = path.pop(0)
+            if path: raise Http404
+            
+            if name != "mercator.jpg":
+                raise Http404
+
+            if not isdir(dirname):
+                makedirs(dirname)
+            filename = join(dirname, name)
+
+            stationsMap(stationList, filename)
+            
+        elif name == "events":
+            dirname = join(dirname, name)
+            if not path: raise Http404
+            name = path.pop(0)
+
+            objId = intOr404(name)
+            source = get_object_or_404(Source, id=objId)
+            dirname = join(dirname, name)
+
+            if not path: raise Http404
+            name = path.pop(0)
+
+            if name == "stations":
+                dirname = join(dirname, name)
+
+                if not path: raise Http404
+                name = path.pop(0)
+            
+                objId = intOr404(name)
+                stationList = get_object_or_404(StationList, id=objId)
+                dirname = join(dirname, name)
+
+                if not path: raise Http404
+                name = path.pop(0)
+
+            else:
+                stationList = None
+                
+            if name == "global":
+                dirname = join(dirname, name)
+
+                if not path: raise Http404
+                name = path.pop(0)
+                if path: raise Http404
+                
+                if name == "event.jpg":
+                    opts = dict()
+                elif name == "antipode.jpg":
+                    opts = dict(opt_A=True)
+                else:
+                    raise Http404
+
+                if not isdir(dirname):
+                    makedirs(dirname)
+                filename = join(dirname, name)
+
+                wiggleMap(source, filename, stationList, opt_m=True, **opts)
+
+            else:
+                raise Http404
+
+        else:
+            raise Http404
+
+    else:
+        raise Http404
+    
+    return staticServe(request, pathname, document_root)

Modified: cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py	2008-05-20 00:49:34 UTC (rev 11984)
@@ -24,6 +24,9 @@
     downloadableAsKML = False
     duplicatable = True
 
+    views = []
+    defaultView = 'detail'
+
     @classmethod
     def create(cls, request, template_name=None,
                template_loader=loader, extra_context=None, post_save_redirect=None,
@@ -289,7 +292,7 @@
         t = template_loader.get_template(template_name)
         return t.render(c)
 
-    def detail(self, request,
+    def detail(self, request, view,
                template_name=None, template_name_field=None,
                template_loader=loader, extra_context=None,
                context_processors=None, template_object_name='object',
@@ -306,7 +309,7 @@
         model = self.Model
         obj = self.obj
         if not template_name:
-            template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower())
+            template_name = "%s/%s_%s.html" % (model._meta.app_label, model._meta.object_name.lower(), view)
         if template_name_field:
             template_name_list = [getattr(obj, template_name_field), template_name]
             t = template_loader.select_template(template_name_list)
@@ -417,6 +420,8 @@
     downloadableAsKML = True
     duplicatable = property(lambda self: bool(self.obj.singleSource))
 
+    views = [('detail', "Mechanism"), ('map', "Map")]
+
     @classmethod
     def create(cls, request):
         from forms import SingleSourceEventAddManipulator
@@ -537,6 +542,8 @@
     downloadableAsText = True
     downloadableAsKML = True
 
+    views = [('detail', "Mechanism"), ('map', "Map")]
+
     def postDeleteRedirect(self, root):
         return "%s/?class=Event&object=%d" % (root, self.obj.event.id)
 
@@ -619,6 +626,9 @@
     downloadableAsKML = True
     duplicatable = False
 
+    views = [('map', "Map"), ('detail', "List")]
+    defaultView = 'map'
+
     def downloadAsText(self, request):
         response = HttpResponse(mimetype='text/plain')
         response['Content-Disposition'] = 'attachment; filename=%s' % self.obj.name

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_detail.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_detail.html	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_detail.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -3,7 +3,7 @@
 
 {% if object.singleSource %}
 
-<p id=sourceBeachballMw>{{ object.singleSource.beachball }} M<sub>w</sub> &cong; {{ object.singleSource.momentMagnitude|stringformat:".2f" }}</p>
+<p id=sourceBeachballMw><img src="{{root}}/beachballs/{{object.singleSource.id}}/detail.gif"> M<sub>w</sub> &cong; {{ object.singleSource.momentMagnitude|stringformat:".2f" }}</p>
 
 <div class=cmtsolution>
     <h3><code>CMTSOLUTION</code></h3>

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_list.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_list.html	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_list.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -19,7 +19,7 @@
             <td><a href="{{root}}/?class=Event&object={{object.id}}">{{ object.name }}</a></td>
             {% if object.singleSource %}
             <td>point-source</td>
-            <td>{{ object.singleSource.beachball }}</td>
+            <td><img src="{{root}}/beachballs/{{object.singleSource.id}}/icon_large.gif"></td>
             <td class=float>{{ object.singleSource.momentMagnitude|stringformat:".2f" }}</td>
             <td class=float>{{ object.singleSource.latitude|stringformat:".4f" }}&deg;</td>
             <td class=float>{{ object.singleSource.longitude|stringformat:".4f" }}&deg;</td>

Added: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_map.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_map.html	                        (rev 0)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_map.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -0,0 +1,14 @@
+
+{% if object.singleSource %}
+
+<center><p><img src="{{root}}/maps/events/{{object.singleSource.id}}/global/event.jpg">
+           <img src="{{root}}/maps/events/{{object.singleSource.id}}/global/antipode.jpg"></p></center>
+
+{% else %}
+
+<!-- NYI: kinematic rupture -->
+<center><p><img src="{{root}}/maps/events/{{object.sources.0.id}}/global/event.jpg">
+           <img src="{{root}}/maps/events/{{object.sources.0.id}}/global/antipode.jpg"></p></center>
+
+
+{% endif %}

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -26,7 +26,7 @@
         <tr class="{% cycle odd,even %}">
             <td>
                 <!-- an inline event creation form, already filled-out -->
-	        <form method="post" action="{{root}}">
+	        <form method="post" action="{{root}}/">
                     <input type="hidden" name="class" value="Event">
                     <input type="hidden" name="action" value="new">
 		    <input type="hidden" name="name"             value="{{ event.eventName }}"/>

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -175,7 +175,22 @@
                         {% endif %}
                     </td>
                     <td>
+                        {% if views %}
+                        <dl class="actionMenu alignRight" id="showMenu">
+                            <dt class="actionMenuHeader">
+                                <a href="some_destination">Show <img src="{{root}}/images/menu-arrow.gif" width=13 height=8></a>
+                            </dt>
+                            <dd class="actionMenuContent">
+                                <ul>
+                                    {% for view in views %}
+                                        <li><a href="{{root}}/?class={{klass}}&object={{object.id}}&view={{view.0}}">{% ifequal view.0 activeView %}&radic;{% endifequal %}&nbsp;{{view.1}}</a></li>
+                                    {% endfor %}
+                                </ul>
+                            </dd>
+                        </dl>
+                        {% else %}
                         <span class="actionButton disabled">Show</span>
+                        {% endif %}
                     </td>
                 </tr>
             </table>

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_detail.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_detail.html	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_detail.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -1,7 +1,7 @@
 
 <h2>{{ object }}</h2>
 
-<p id=sourceBeachballMw>{{ object.beachball }} M<sub>w</sub> &cong; {{ object.momentMagnitude|stringformat:".2f" }}</p>
+<p id=sourceBeachballMw><img src="{{root}}/beachballs/{{object.id}}/detail.gif"> M<sub>w</sub> &cong; {{ object.momentMagnitude|stringformat:".2f" }}</p>
 
 <div class=cmtsolution>
     <h3><code>CMTSOLUTION</code></h3>

Added: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_map.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_map.html	                        (rev 0)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/source_map.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -0,0 +1,3 @@
+
+<center><p><img src="{{root}}/maps/events/{{object.id}}/global/event.jpg">
+           <img src="{{root}}/maps/events/{{object.id}}/global/antipode.jpg"></p></center>

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_detail.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_detail.html	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_detail.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -4,7 +4,7 @@
 <p class=infobar>{{ object.station_set.count }} station{{ object.station_set.count|pluralize }}
 
 {% if object.station_set.count %}
-    <table rules=groups>
+    <table rules=cols>
         <colgroup><col class=odd></colgroup>
         <colgroup><col class=even><col class=odd></colgroup>
         <colgroup><col class=even><col class=odd></colgroup>
@@ -21,7 +21,7 @@
 
         <tbody>
         {% for station in object.station_set.all %}
-        <tr>
+        <tr class="{% cycle odd,even %}" id="o{{object.id}}">
             <td>{{ station.code }}</td>
             <td class=float>{{ station.latitude|stringformat:".4f" }}</td>
             <td class=float>{{ station.longitude|stringformat:".4f" }}</td>

Added: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_map.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_map.html	                        (rev 0)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/stationlist_map.html	2008-05-20 00:49:34 UTC (rev 11984)
@@ -0,0 +1,2 @@
+
+<center><p><img src="{{root}}/maps/stations/{{object.id}}/mercator.jpg"></p></center>

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/style.css
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/style.css	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/style.css	2008-05-20 00:49:34 UTC (rev 11984)
@@ -106,6 +106,10 @@
     border: 0;
 }
 
+.actionMenu.alignRight .actionMenuContent {
+    right: -1px;
+}
+
 .actionMenu .actionMenuContent ul {
     padding: 0;
     margin: 0;

Modified: cs/portal/trunk/northridge/SeismoWebPortal/urls.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/urls.py	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/urls.py	2008-05-20 00:49:34 UTC (rev 11984)
@@ -44,7 +44,12 @@
     # output files
     (r'^output/create/$', 'SeismoWebPortal.views.daemon_post', dict(modelName='OutputFile', action='create')),
 
-    (r'^(.*)', 'django.views.static.serve', dict(document_root = STATIC_ROOT)),
+    # GMT
+    (r'^(?P<pathname>beachballs/.*)$', 'SeismoWebPortal.gmt.serve'),
+    (r'^(?P<pathname>maps/.*)$', 'SeismoWebPortal.gmt.serve'),
+
+    # static files
+    (r'^(.*)$', 'django.views.static.serve', dict(document_root = STATIC_ROOT)),
 )
 
 

Modified: cs/portal/trunk/northridge/SeismoWebPortal/views.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/views.py	2008-05-19 17:29:57 UTC (rev 11983)
+++ cs/portal/trunk/northridge/SeismoWebPortal/views.py	2008-05-20 00:49:34 UTC (rev 11984)
@@ -42,6 +42,8 @@
     downloadableAsText = False
     downloadableAsKML = False
     duplicatable = False
+    views = []
+    activeView = None
     klass = None
     
     if className is None:
@@ -79,9 +81,11 @@
             downloadableAsKML = obj.downloadableAsKML
             downloadable = downloadableAsText or downloadableAsKML
             duplicatable = obj.duplicatable
+            views = obj.views
 
             if action is None:
-                ret = obj.detail(request)
+                activeView = request.REQUEST.get('view', obj.defaultView)
+                ret = obj.detail(request, activeView)
             elif action == 'edit':
                 ret = obj.update(request)
             elif action == 'duplicate':
@@ -115,6 +119,8 @@
         downloadableAsText = downloadableAsText,
         downloadableAsKML = downloadableAsKML,
         duplicatable = duplicatable,
+        views = views,
+        activeView = activeView,
         root = root,
         ))
     response.write(t.render(c))



More information about the cig-commits mailing list