Skip to content

Commit 876cd67

Browse files
authored
Merge pull request #8 from tclements/newAWS
New aws
2 parents 80a6f19 + 30e6d55 commit 876cd67

File tree

10 files changed

+114
-92
lines changed

10 files changed

+114
-92
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 1.0
7+
- 1.5
88
- nightly
99
notifications:
1010
email: false
@@ -14,7 +14,7 @@ jobs:
1414
fast_finish: true
1515
include:
1616
- stage: Documentation
17-
julia: 1.0
17+
julia: 1.5
1818
script: julia --project=docs -e '
1919
using Pkg;
2020
Pkg.develop(PackageSpec(path=pwd()));

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ authors = ["Tim Clements <[email protected]>"]
44
version = "0.1.0"
55

66
[deps]
7-
AWSCore = "4f1ea46c-232b-54a6-9b17-cc2d0f3e6598"
7+
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
88
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
9-
AWSSDK = "0d499d91-6ae5-5d63-9313-12987b87d5ad"
109
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
1110
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1211
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -17,6 +16,7 @@ SeisIO = "b372bb87-02dd-52bb-bcf6-c30dd83fd342"
1716

1817
[compat]
1918
julia = "1"
19+
SeisIO = "1.2"
2020

2121
[extras]
2222
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ SCEDC.jl supports direct download and file streaming for continuous data request
2929

3030
```julia
3131
# download data using SCEDC on AWS
32-
using SCEDC, Dates, AWSCore
33-
aws = aws_config(region="us-west-2")
32+
using SCEDC, Dates
3433
bucket = "scedc-pds"
3534
startdate = Date("2016-07-01")
3635
enddate = Date("2016-07-01")
@@ -39,20 +38,20 @@ channel = "LH?"
3938
OUTDIR = "~/data"
4039

4140
# query s3 for matching stations
42-
filelist = s3query(aws, startdate, enddate=enddate, network=network,channel=channel)
41+
filelist = s3query(startdate, enddate=enddate, network=network,channel=channel)
4342

4443
# download mseed files to disk
45-
ec2download(aws,bucket,filelist,OUTDIR)
44+
ec2download(bucket,filelist,OUTDIR)
4645

4746
# or stream to an Array of SeisIO.SeisData
48-
LHs = ec2stream(aws,bucket,filelist)
47+
LHs = ec2stream(bucket,filelist)
4948
```
5049

5150
To do parallel data transfers, use the `addprocs` function from the `Distributed` module:
5251
```julia
5352
using Distributed
5453
addprocs()
55-
ec2download(aws,bucket,filelist,"~/paralleldir")
54+
ec2download(bucket,filelist,"~/paralleldir")
5655
```
5756

5857
### Earthquake Catalog Requests
@@ -69,7 +68,6 @@ SCEDC.jl queries the SCSN earthquake catalog using these possible parameters:
6968

7069
```julia
7170
julia> df = catalogquery(
72-
aws,
7371
starttime = DateTime(1937,1,1),
7472
endtime=DateTime(1937,2,1),
7573
minlatitude=33.,
@@ -92,7 +90,7 @@ julia> df = catalogquery(
9290
SCEDC.jl can retrieve phase picks for an earthquake given the event's ID and date. Here is an example from the 1987 Elmore Ranch earthquake with data returned as a `SeisIO.SeisEvent`
9391

9492
```julia
95-
julia> phasequery(aws,628016,Date(1987,11,24))
93+
julia> phasequery(628016,Date(1987,11,24))
9694
Event 628016: SeisEvent with 70 channels
9795

9896
(.hdr)
@@ -138,7 +136,7 @@ SCEDC.jl can stream waveforms (with associated phase picks) from earthquakes goi
138136

139137
Here is an example of an requesting events from 2019, returned as an `Array` of `SeisEvent`
140138
```julia
141-
julia> EQ = eventstream(aws,starttime=Date(2019,1,1),endtime=Date(2019,1,2),minmagnitude=2.)
139+
julia> EQ = eventstream(starttime=Date(2019,1,1),endtime=Date(2019,1,2),minmagnitude=2.)
142140
julia> EQ[1].data
143141
SeisIO.Quake.EventTraceData with 2909 channels (3 shown)
144142
ID: AZ.BZN..BHE AZ.BZN..BHN AZ.BZN..BHZ

src/SCEDC.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module SCEDC
22

33
using Dates, DelimitedFiles, Distributed, Random
4-
using AWSCore, AWSS3, AWSSDK,CSV, DataFrames, SeisIO
4+
using AWS, AWSS3, CSV, DataFrames, SeisIO
55
using SeisIO.Quake
6+
@service S3
7+
@service Athena
68

79
# include modules
810
include("catalog.jl")
@@ -12,4 +14,4 @@ include("s3.jl")
1214
include("athena.jl")
1315
include("ec2.jl")
1416

15-
end
17+
end

src/athena.jl

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
export athenasetup, athenaquery
22
"""
3-
athenasetup(aws,bucket)
3+
athenasetup(bucket)
44
55
Create AWS Athena database and table for SQL queries.
66
77
# Arguments
8-
- `aws::AWSConfig`: AWSConfig configuration dictionary
98
- `bucket::String`: Name of AWS bucket to store query results
109
"""
1110
function athenasetup(aws::AWSConfig,bucket::String;
@@ -20,9 +19,9 @@ function athenasetup(aws::AWSConfig,bucket::String;
2019

2120
# create database
2221
println("Creating database '$database' ",now())
23-
AWSSDK.Athena.start_query_execution(aws,QueryString="create database $database",
24-
ResultConfiguration=["OutputLocation" => "s3://$bucket/queries/"],
25-
ClientRequestToken=randstring(32))
22+
Athena.start_query_execution("create database $database",
23+
Dict("ResultConfiguration"=>Dict("OutputLocation" => "s3://$bucket/queries/"),
24+
"ClientRequestToken"=>randstring(32)))
2625

2726
# string to create table
2827
tablestr = """CREATE EXTERNAL TABLE IF NOT EXISTS $table ( `ms_filename` string,""" *
@@ -36,25 +35,27 @@ function athenasetup(aws::AWSConfig,bucket::String;
3635

3736
# create table
3837
println("Creating table '$table' ",now())
39-
AWSSDK.Athena.start_query_execution(aws,QueryString=tablestr,
40-
ResultConfiguration=["OutputLocation" => "s3://$bucket/queries/"],
41-
ClientRequestToken=randstring(32),
42-
QueryExecutionContext = ["Database" => database])
38+
Athena.start_query_execution(tablestr,
39+
Dict("ResultConfiguration"=>Dict("OutputLocation" => "s3://$bucket/queries/"),
40+
"ClientRequestToken"=>randstring(32),
41+
"QueryExecutionContext" => Dict("Database" => database))
42+
)
4343

4444
sleep(1)
4545

4646
# update partitions
4747
println("Repairing table '$table' ",now())
48-
output = AWSSDK.Athena.start_query_execution(aws,QueryString="MSCK REPAIR TABLE $table",
49-
ResultConfiguration=["OutputLocation" => "s3://$bucket/queries/"],
50-
ClientRequestToken=randstring(32),
51-
QueryExecutionContext = ["Database" => database])
48+
output = Athena.start_query_execution("MSCK REPAIR TABLE $table",
49+
Dict("ResultConfiguration"=>Dict("OutputLocation" => "s3://$bucket/queries/"),
50+
"ClientRequestToken"=>randstring(32),
51+
"QueryExecutionContext"=>Dict("Database" => database))
52+
)
5253

5354
# wait until done
5455
finished = false
5556
while !finished
56-
queryresult = AWSSDK.Athena.get_query_execution(aws,output)
57-
if queryresult["QueryExecutionDetail"]["Status"] == "SUCCEEDED"
57+
queryresult = Athena.get_query_execution(output["QueryExecutionId"])
58+
if queryresult["QueryExecutionDetail"]["Status"]["State"] == "SUCCEEDED"
5859
finished = true
5960
println("REPAIR table $table finished ",now())
6061
elseif queryresult["QueryExecutionDetail"]["Status"]["State"] == "FAILED"
@@ -65,9 +66,11 @@ function athenasetup(aws::AWSConfig,bucket::String;
6566
end
6667
return nothing
6768
end
69+
athenasetup(a...;b...) = athenasetup(global_aws_config(region="us-west-2"),a...;b...)
70+
athenasetup(d::Dict,a...;b...) = athenasetup(global_aws_config(region=d[:region]),a...;b...)
6871

6972
"""
70-
athenaquery(aws,bucket,query)
73+
athenaquery(bucket,query)
7174
7275
Use AWS Athena to query SCEDC-pds database.
7376
@@ -90,7 +93,6 @@ See https://docs.aws.amazon.com/athena/latest/ug/presto-functions.html for possi
9093
9194
9295
# Arguments
93-
- `aws::AWSConfig`: AWSConfig configuration dictionary
9496
- `bucket::String`: Name of AWS bucket to store query results
9597
- `query::String`: SQL query for SCEDC-pds database.
9698
@@ -122,16 +124,17 @@ function athenaquery(aws::AWSConfig,bucket::String, query::String;
122124
end
123125

124126
# query the table
125-
output = AWSSDK.Athena.start_query_execution(aws,
126-
QueryString="select ms_filename from $table where $query order by ms_filename ",
127-
ResultConfiguration=["OutputLocation" => "s3://$bucket/queries/"],
128-
ClientRequestToken=randstring(32),
129-
QueryExecutionContext = ["Database" => database])
127+
output = Athena.start_query_execution(
128+
"select ms_filename from $table where $query order by ms_filename ",
129+
Dict("ResultConfiguration"=>Dict("OutputLocation" => "s3://$bucket/queries/"),
130+
"ClientRequestToken"=>randstring(32),
131+
"QueryExecutionContext" => Dict("Database" => database))
132+
)
130133

131134
# check when query is finished
132135
finished = false
133136
while !finished
134-
queryresult = AWSSDK.Athena.get_query_execution(aws,output)
137+
queryresult = Athena.get_query_execution(output["QueryExecutionId"])
135138
if queryresult["QueryExecutionDetail"]["Status"]["State"] == "SUCCEEDED"
136139
finished = true
137140
println("QUERY '$query' finished ",now())
@@ -160,3 +163,5 @@ function athenaquery(aws::AWSConfig,bucket::String, query::String;
160163
end
161164
return scedcpath.(filelist)
162165
end
166+
athenaquery(a...;b...) = athenaquery(global_aws_config(region="us-west-2"),a...;b...)
167+
athenaquery(d::Dict,a...;b...) = athenaquery(global_aws_config(region=d[:region]),a...;b...)

src/catalog.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,16 @@ function read_catalog(catalog)
5555

5656
# format dates
5757
dateformater = Dates.DateFormat("y/m/dTH:M:S.s")
58-
df["EVENTTIME"] = DateTime.(parse_hms.(df[!,"YYYY/MM/DD"],df[!,"HH:mm:SS.ss"]),dateformater)
58+
df[!,"EVENTTIME"] = DateTime.(parse_hms.(df[!,"YYYY/MM/DD"],df[!,"HH:mm:SS.ss"]),dateformater)
5959
select!(df,Not([Symbol("YYYY/MM/DD"),Symbol("HH:mm:SS.ss")]))
6060
return df
6161
end
6262

6363
"""
64-
catalogquery(aws)
64+
catalogquery()
6565
6666
Use S3 to query SCEDC-pds event catalog. Returns a DataFrame of events.
6767
68-
# Arguments
69-
- `aws::AWSConfig`: AWSConfig configuration dictionary
70-
7168
# Keywords
7269
- `starttime::TimeType`: The start time/day of the event query.
7370
- `endtime::TimeType`: The end time/day of the event query.
@@ -82,10 +79,9 @@ Use S3 to query SCEDC-pds event catalog. Returns a DataFrame of events.
8279
- `eventtype::String`: Event type: {"eq"=>"earthquake", "qb"=> "quarry blast",
8380
"sn"=>"sonic boom', "nt"=>"nuclear blast", "uk"=>"not reported","*"=>"all events"}
8481
"""
85-
function catalogquery(
86-
aws::AWSConfig;
87-
starttime::TimeType=Date(1932,1,1),
88-
endtime::TimeType=Today(),
82+
function catalogquery(aws::AWSConfig;
83+
starttime::TimeType=today(),
84+
endtime::TimeType=today(),
8985
minlatitude::Real=-90,
9086
maxlatitude::Real=90,
9187
minlongitude::Real=-180,
@@ -131,6 +127,8 @@ function catalogquery(
131127
end
132128
return alldf
133129
end
130+
catalogquery(a...;b...) = catalogquery(global_aws_config(region="us-west-2"), a...; b...)
131+
catalogquery(d::Dict, a...;b...) = catalogquery(global_aws_config(region=d[:region]), a...; b...)
134132

135133
function parse_hms(d::String,hms::String)
136134
# check that date matches HH:MM:SS.s syntax

0 commit comments

Comments
 (0)