[cig-commits] r11607 - cs/portal/trunk/seismo/SeismoWebPortal
leif at geodynamics.org
leif at geodynamics.org
Wed Mar 26 21:39:21 PDT 2008
Author: leif
Date: 2008-03-26 21:39:21 -0700 (Wed, 26 Mar 2008)
New Revision: 11607
Modified:
cs/portal/trunk/seismo/SeismoWebPortal/gmt.py
cs/portal/trunk/seismo/SeismoWebPortal/views.py
Log:
Added Carl Tape's station map.
Modified: cs/portal/trunk/seismo/SeismoWebPortal/gmt.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/gmt.py 2008-03-27 03:57:42 UTC (rev 11606)
+++ cs/portal/trunk/seismo/SeismoWebPortal/gmt.py 2008-03-27 04:39:21 UTC (rev 11607)
@@ -52,8 +52,126 @@
return gif
+def stationsMap(stationList):
+ # 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", "/home/leif/opt/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.fsNode.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.
+ jpg = join(workdir, "map.jpg")
+ spawn("/usr/bin/convert", '-trim', '+repage', psfile, jpg)
+
+ jpg = open(jpg, 'r')
+ shutil.rmtree(workdir)
+
+ return jpg
+
+
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()
Modified: cs/portal/trunk/seismo/SeismoWebPortal/views.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/views.py 2008-03-27 03:57:42 UTC (rev 11606)
+++ cs/portal/trunk/seismo/SeismoWebPortal/views.py 2008-03-27 04:39:21 UTC (rev 11607)
@@ -1379,6 +1379,7 @@
objId = stationList.id # Ouch!
view = gui.ChildWindow(url, "View")
+ map = gui.ChildWindow(url + "map/", "Map")
properties = gui.ChildWindow(url + "properties/", "Properties")
menuBar = [
gui.Menu("actionMenu", "actions", "Actions",
@@ -1388,6 +1389,7 @@
]
view.menuBar = properties.menuBar = menuBar
desktop.activeWindow.insertWindow(view)
+ desktop.activeWindow.insertWindow(map)
desktop.activeWindow.insertWindow(properties)
if not path:
@@ -1407,10 +1409,18 @@
follow = FSNode.follow,
)
+ if name == "map":
+ map.content = gui.StaticContent('<img src="%s">' % (url + "map.jpg"))
+ desktop.activeWindow.selectWindow(map)
+ return desktop
+
if name == "delete":
obj = get_object_or_404(StationList, id=objId)
return moveObjectToTrash(obj, request, "/specfem3dglobe/home/")
+ if name == "map.jpg":
+ return stations_map_jpg(stationList)
+
index = Index({
"stations.txt": stationlist_detail_txt,
"gearth.kml": stationlist_detail_gearth,
@@ -1546,6 +1556,17 @@
**kwds)
+def stations_map_jpg(stationList):
+ from gmt import stationsMap
+ import shutil
+
+ stream = stationsMap(stationList)
+ response = HttpResponse(mimetype='image/jpeg')
+ shutil.copyfileobj(stream, response)
+ stream.close()
+ return response
+
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Help
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the cig-commits
mailing list