earthquake-viewer_2009-in-progress


Information

Created with NetLogo version NetLogo 4.1beta1
Running with NetLogoLite.jar version 411.


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 4.1beta1

;; 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
  yyy mmm ddd
  hh mm ss
  
]  

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

to get-data
   let filename "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
     ]
   ]
   [ user-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

   let first-event first data

   let first-date item 0 first-event
   let date-list extract-date first-date

   set yyy item 0 date-list   
   set mmm item 1 date-list
   set ddd item 2 date-list

   let first-time item 1 first-event
   let time-list extract-time first-time

   set hh item 0 time-list
   set mm item 1 time-list
   set ss item 2 time-list

   

   (foreach rev-data (n-values length data [?])
   [ if stop? = true [ set stop? false stop ]
     let currdate (word yyy "/" mmm "/" ddd )
     let currtime (word hh ":" mm ":" ss )
     
     
     let date-list extract-date first-date

   set yyy item 0 date-list   
   set mmm item 1 date-list
   set ddd item 2 date-list

   let first-time item 1 first-event
   let time-list extract-time first-time

   set hh item 0 time-list
   set mm item 1 time-list
   set ss item 2 time-list
     
     
     
     
     
     ; 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 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"
         setxy long lat
       ]
     ]
     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
   let map-file "eq-world-map-2.png"
   if file-exists? map-file
   [ import-drawing map-file ]
   ;; clear overlay so plabel data shows
   crt 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 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"
         setxy long lat
       ]
     ]
     
   ])
   display
end   

   
to-report hms [ #hh #mm #ss ]
    set #hh :00 #hh 
    set #mm :00 #mm
    set #ss :00 #ss
    report (word #hh ":" #mm ":" #ss )
end

to-report :00 [ #tt ]
   let #ll length #tt
   if #ll = 2 [ report #tt ]
   if #ll = 1 [ report (word "0" #tt) ]
   report "00"
end

   
to-report extract-date [ #date ]
   let result []
   set result fput substring #date 8 11 result
   set result fput substring #date 5 7 result
   set result fput substring #date 0 4 result
   report result
end

to-report extract-time [ #time ]
   let result []
   set result fput substring #time 7 9 result
   set result fput substring #time 4 6 result
   set result fput substring #time 0 3 result
   report result
end

      

                    


Download Link

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