diff --git a/Project.toml b/Project.toml index 2334aa46..c35ce00d 100644 --- a/Project.toml +++ b/Project.toml @@ -15,6 +15,7 @@ Glob = "c27321d9-0574-5035-807b-f59d2c89b15c" ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MeshIO = "7269a6da-0436-5bbc-96c2-40638cbb6118" NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce" @@ -59,4 +60,4 @@ GMT = "5752ebe1-31b9-557e-87aa-f909b540aa54" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test","GMT"] +test = ["Test", "GMT"] diff --git a/src/data_import.jl b/src/data_import.jl index 247ac27f..f29d1a60 100644 --- a/src/data_import.jl +++ b/src/data_import.jl @@ -4,7 +4,9 @@ # # Author: Marcel Thielmann, 05/2021 -export Screenshot_To_GeoData, Screenshot_To_CartData, Screenshot_To_UTMData +using LightXML + +export Screenshot_To_GeoData, Screenshot_To_CartData, Screenshot_To_UTMData, GetLonLatDepthMag_QuakeML # import CSV data using standard library functions # here we assume that the data is indeed comma separated and that comments are preceded with a "#" @@ -309,7 +311,43 @@ function Screenshot_To_UTMData(filename::String, Corner_LowerLeft, Corner_UpperR # first create a GeoData struct Data_UTM = Screenshot_To_GeoData(filename, Corner_LowerLeft, Corner_UpperRight; Corner_LowerRight=Corner_LowerRight, Corner_UpperLeft=Corner_UpperLeft, Cartesian=false, UTM=true, UTMzone=UTMzone, isnorth=isnorth, fieldname=fieldname) - return Data_UTM +end +""" + Data = GetLonLatDepthMag_QuakeML(filename::String) + +Extracts longitude, latitude, depth and magnitude from a QuakeML file that has been e.g. downloaded from ISC. The data is then returned in GeoData format. +""" +function GetLonLatDepthMag_QuakeML(filename::String) + # The QuakeML format consists of a tree with quite a lot of branches, so we have to traverse it to quite some extent to get the desired values + # using LightXML: extension??? + xdoc = parse_file(filename); # parse the whole file + xroot =root(xdoc); + catalogues = get_elements_by_tagname(xroot,"eventParameters"); + catalogue = catalogues[1]; + events = get_elements_by_tagname(catalogue,"event"); # now those are all events + num_events = size(events,1); + + # allocate, lat,lon,depth,magnitude + lon = zeros(num_events,1); + lat = zeros(num_events,1); + depth = zeros(num_events,1); + mag = zeros(num_events,1); + + # now loop over the events and assign the respective values + for ievent = 1:num_events + tmp_event = events[ievent]; + origin = get_elements_by_tagname(events[ievent], "origin"); + magnitude = get_elements_by_tagname(events[ievent], "magnitude"); + + # this is a bit dirty, if you find a better/cleaner way, be my guest... + lon[ievent] = parse(Float64,string(collect(child_nodes(collect(child_elements(get_elements_by_tagname(origin[1], "longitude")[1]))[1]))[1])) + lat[ievent] = parse(Float64,string(collect(child_nodes(collect(child_elements(get_elements_by_tagname(origin[1], "latitude")[1]))[1]))[1])) + depth[ievent] = parse(Float64,string(collect(child_nodes(collect(child_elements(get_elements_by_tagname(origin[1], "depth")[1]))[1]))[1])) + mag[ievent] = parse(Float64,string(collect(child_nodes(get_elements_by_tagname(get_elements_by_tagname(magnitude[1],"mag")[1],"value")[1]))[1])); + end + + Data_ISC = GeoData(lon,lat,depth,(Magnitude=mag,Depth=depth)); + return Data_ISC end