earthquake-viewer_2


Information

Created with NetLogo version NetLogo 3.1.1
Running with NetLogoLite.jar version 314.


WHAT IS IT?


-------
This model graphically displays seismagraph data.

HOW IT WORKS


--------
The data is in a text file. The model loads the data, then converts the latitude and logitude into patch coordinates.
A world-map overlay helps visualize the location.
The seismic activity data is plotted on the map as circles. Quake magnitude is shown by the size of the circle. The depth of the epicenter is shown by the brightness of the circle.

READING DATA


--------
The file is called "eq-data.ndata"
This format is in NetLogo LIST format, and can be read, in its entirety, into a NetLogo list variable with three statements.

;; open the file

file-open "eq-data.ndata"

;; read the entire file into variable "data"

let data file-read

;; close the file

file-close

DATA FORMAT


-------
[ "DATE" "UTC-TIME" "Latitude" "Longitude" "Depth" "Magnitude" "Comments" ]
[ "2005/01/02" "21:56:22" "18.74N" "64.70W" "14" "3.7" "VIRGIN ISLANDS" ]
[ "2005/01/02" "21:04:09" "35.66N" "121.11W" "7" "2.9" "CENTRAL CALIFORNIA" ]
[ "2005/01/02" "20:58:48" "32.37N" "115.21W" "33" "4.0" "BAJA CALIFORNIA, MEXICO" ]
[ "2005/01/02" "18:23:17" "2.14N" "126.74E" "30" "5.4" "MOLUCCA SEA" ]

Procedures

NetLogo Version: NetLogo 3.1.1

;; SUMMARY
;;;;  A visualization of seismic data.
;; COPYRIGHT & LICENSE
;;;; Copyright (C) 2005 James P. Steiner
;;;; Some Rights Reserved.
;;;; Creative Commons Attribution-NonCommercial-ShareAlike License v. 2.0.
;;;; Visit http://creativecommons.org/licenses/by-nc-sa/2.0/ for more information.

globals
[ data
  
]  

to startup
   ca
   get-data
   get-map
   set stop? false
end

to get-data
   let filename "data/eq-data.ndata"
   
   if not is-string? filename
   [ stop ]
   
   set data []
   let line-num 0
   carefully
   [ print (word "reading " filename )
     file-open filename
     while [ not file-at-end? ]
     [ set line-num line-num + 1
       let new-line file-read 
       if length new-line != 7
       [ set new-line (sentence (but-last new-line) "0.0" (last new-line) )
       ]
       set data lput new-line data
     ]
   ]
   [ message (word "Error opening or reading file at line " line-num " !") ]
   file-close
   print "Data Read:"
   print length data
   if length data > 0
   [ print first data
     print last data
     print "discarding header row"
     set data but-first data
   ]
end

to plot-data
   ct cp
   let rev-data reverse data
   (foreach rev-data (n-values length data [?])
   [ if stop? = true [ set stop? false stop ]
     ; lat, long, depth, mag
     let lat item 2 ?1
     let long item 3 ?1
     let depth ( item 4 ?1)
     let mag (item 5 ?1)
     carefully
     [ set depth read-from-string depth
       set mag read-from-string mag
     ]
     [ print (word "problem with record " ?2  )
       print mag
       print depth
       stop
     ]
     set lat parse-degrees lat
     set long parse-degrees long
     ; no-display 
     ifelse persistance?
     [ ask turtles 
       [ ifelse size * .90 < .25
         [ die ] [ set size size * .90 ]
       ]
     ]
     [ ask turtles [ die ] 
     ]
     ask patch-at long lat
     [ sprout 1
       [ set size 3 + (scale-color gray mag 0 10 ) ^ 2
         set color scale-color red (- (sqrt depth)) -30 4
         set shape "circle"
       ]
     ]
     ask patch -100 0
     [ set plabel first ? ]
     ask patch -100 -10
     [ set plabel item 1 ? ]
     
     wait .05
     ; display 

   ])
   wait 3
end


to-report date-serial [ date-string ]
   let year read-from-string substring date-string 0 4
   let month read-from-string substring date-string 5 7
   let day read-from-string substring date-string 8 10
   let month-length [ 0  31  28  31  30  31  30  31  31  30  31  30  31 ]
   let year-depth   [ 0   0  31  59  90 120 151 181 212 243 273 304 334 ]
   let date-num (year * 365 + (item month year-depth) + day + int( ( year   ) / 4) )
   report date-num
end
   
to-report parse-degrees [ deg-string ]
   ;; expects nnn.nn N|E|S|W 
   let dir 0
   let compass last deg-string
   ifelse compass = "N" or compass = "E"
   [ set dir 1 ]
   [ set dir -1 ]
   let value but-last deg-string
   set value read-from-string value
   report (dir * value)
end

to get-map
   if file-exists? "data/eq-world-map-2.png"
   [ import-drawing "data/eq-world-map-2.png" ]
   ;; clear overlay so plabel data shows
   cct 1
   [ set shape "block"
     set pen-size 2
     let top 10
     let rows 35
     let left-side min-pxcor
     let right-side (- 100)
     let xx left-side
     let yy top
     setxy xx yy
     pe
     repeat rows
     [ setxy left-side yy
       setxy (right-side) yy
       set yy yy - 1
     ]
     die
   ]
   ask patch -100   0 [ set plabel "Click GO"]
   ask patch -100 -10 [ set plabel "to begin." ] 
         
end
   
   
to show-all
   cp ct
   display
   no-display
   (foreach data (n-values length data [?])
   [ ; lat, long, depth, mag
     let lat item 2 ?1
     let long item 3 ?1
     let depth ( item 4 ?1)
     let mag (item 5 ?1)
     carefully
     [ set depth read-from-string depth
       set mag read-from-string mag
     ]
     [ print (word "problem with record " ?2  )
       print mag
       print depth
       stop
     ]
     set lat parse-degrees lat
     set long parse-degrees long
     ; no-display 
     ask patch-at long lat
     [ sprout 1
       [ set size 1 + (scale-color gray mag 0 10 ) 
         set color scale-color red (- (sqrt depth)) -30 4
         set shape "dot"
       ]
     ]
     
   ])
   display
end   

   

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download earthquake-viewer_2 --