Skip to content

Commit

Permalink
removed dependency on SeisIO (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepholinger committed Nov 21, 2023
1 parent fd41066 commit d359fdb
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 90 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SeisIO = "b372bb87-02dd-52bb-bcf6-c30dd83fd342"
SeisBase = "8b7dfb90-41a7-4c72-9751-87603311c074"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -28,6 +28,6 @@ GPUArrays = "3.1, 4.0, 5.0, 6.2, 7.0, 8.0"
Glob = "1.2"
JLD2 = "0.1, 0.2, 0.3, 0.4"
RecipesBase = "1.1"
SeisIO = "1.0, 1.1, 1.2"
SeisBase = "0.1.0"
StatsBase = "0.32,0.33"
julia = "1"
Binary file added docs/.DS_Store
Binary file not shown.
Binary file added docs/src/.DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ArrayFuncs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SeisIO: demean, demean!, taper, taper!,detrend, detrend!
import SeisBase: demean, demean!, taper, taper!,detrend, detrend!
export detrend, detrend!, taper, taper!, demean, demean!, hanningwindow
# Signal processing functions for arrays (rather than SeisData or SeisChannel)

Expand Down
2 changes: 1 addition & 1 deletion src/SeisNoise.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SeisNoise

using Dates, DSP, FFTW, Glob, JLD2, LinearAlgebra, SeisIO, SeisIO.Nodal
using Dates, DSP, FFTW, Glob, JLD2, LinearAlgebra, SeisBase, SeisBase.Nodal
using Statistics, StatsBase, CUDA, Adapt, GPUArrays, RecipesBase

# check use of cuda
Expand Down
10 changes: 5 additions & 5 deletions src/Types/NoiseData.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Base: in, +, -, *, ==, convert, isempty, isequal, length, push!, sizeof, append!
import Base: lastindex, firstindex, getindex, setindex!, sort, sort!
import SeisIO: GeoLoc, PZResp, InstrumentResponse
import SeisBase: GeoLoc, PZResp, InstrumentResponse
export RawData, FFTData, CorrData, gpu, cpu, sort, sort!, append!
export isequal, isempty, length, +, ==

# Many thanks to SeisIO for inspiration for NoiseData objects
# Many thanks to SeisBase for inspiration for NoiseData objects

const datafields = (:x,:fft,:corr)

Expand All @@ -28,7 +28,7 @@ A structure for raw ambient noise data.
| :cc_len | Raw data window length in seconds. |
| :cc_step | Spacing between windows in seconds. |
| :time_norm | Apply one-bit whitening with "one_bit". |
| :resp | SeisIO InstrumentResponse object |
| :resp | SeisBase InstrumentResponse object |
| :misc | Dictionary for non-critical information. |
| :notes | Timestamped notes; includes automatically-logged acquisition and |
| | processing information. |
Expand Down Expand Up @@ -185,7 +185,7 @@ A structure for fourier transforms (FFT) of ambient noise data.
| :cc_step | Spacing between windows in number of points. |
| :whitened | Whitening applied.
| :time_norm | Apply one-bit whitening with "one_bit". |
| :resp | SeisIO InstrumentResponse object |
| :resp | SeisBase InstrumentResponse object |
| :misc | Dictionary for non-critical information. |
| :notes | Timestamped notes; includes automatically-logged acquisition and |
| | processing information. |
Expand Down Expand Up @@ -282,7 +282,7 @@ A structure for cross-correlations of ambient noise data.
| :cc_step | Spacing between windows in number of points. |
| :whitened | Whitening applied.
| :time_norm | Apply one-bit whitening with "one_bit". |
| :resp | SeisIO InstrumentResponse object |
| :resp | SeisBase InstrumentResponse object |
| :misc | Dictionary for non-critical information. |
| :notes | Timestamped notes; includes automatically-logged acquisition and |
| | processing information. |
Expand Down
30 changes: 15 additions & 15 deletions src/Types/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ function show(io::IO, R::RawData)
fstr = uppercase(String(f))
print(io, lpad(fstr, show_os-2), ": ")
if f == :notes || f == :misc
SeisIO.show_str(io, String[string(length(targ), " entries")], w, N)
SeisBase.show_str(io, String[string(length(targ), " entries")], w, N)
elseif (t <: AbstractFloat || t <: InstrumentPosition || t<: InstrumentResponse)
println(io, repr("text/plain", targ, context=:compact=>true))
elseif f == :t
if length(R.t) > 0
SeisIO.show_str(io, String[timestamp(R.t[1]), " (", string(length(R.t)), " windows)"], w, N)
SeisBase.show_str(io, String[timestamp(R.t[1]), " (", string(length(R.t)), " windows)"], w, N)
else
SeisIO.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
SeisBase.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
end
elseif f == :x
SeisIO.show_str(io, String[summary(targ)], w, N)
SeisBase.show_str(io, String[summary(targ)], w, N)
else
SeisIO.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
SeisBase.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
end
end
end
Expand All @@ -63,19 +63,19 @@ function show(io::IO, F::FFTData)
fstr = uppercase(String(f))
print(io, lpad(fstr, show_os-2), ": ")
if f == :notes || f == :misc
SeisIO.show_str(io, String[string(length(targ), " entries")], w, N)
SeisBase.show_str(io, String[string(length(targ), " entries")], w, N)
elseif (t <: AbstractFloat || t <: InstrumentPosition || t<: InstrumentResponse)
println(io, repr("text/plain", targ, context=:compact=>true))
elseif f == :t
if length(F.t) > 0
SeisIO.show_str(io, String[timestamp(F.t[1]), " (", string(length(F.t)), " FFTs)"], w, N)
SeisBase.show_str(io, String[timestamp(F.t[1]), " (", string(length(F.t)), " FFTs)"], w, N)
else
SeisIO.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
SeisBase.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
end
elseif f == :fft
SeisIO.show_str(io, String[summary(targ)], w, N)
SeisBase.show_str(io, String[summary(targ)], w, N)
else
SeisIO.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
SeisBase.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
end
end
end
Expand All @@ -99,19 +99,19 @@ function show(io::IO, C::CorrData)
fstr = uppercase(String(f))
print(io, lpad(fstr, show_os-2), ": ")
if f == :notes || f == :misc
SeisIO.show_str(io, String[string(length(targ), " entries")], w, N)
SeisBase.show_str(io, String[string(length(targ), " entries")], w, N)
elseif (t <: AbstractFloat || t <: InstrumentPosition || t<: InstrumentResponse)
println(io, repr("text/plain", targ, context=:compact=>true))
elseif f == :t
if length(C.t) > 0
SeisIO.show_str(io, String[timestamp(C.t[1]), " (", string(length(C.t)), " Corrs)"], w, N)
SeisBase.show_str(io, String[timestamp(C.t[1]), " (", string(length(C.t)), " Corrs)"], w, N)
else
SeisIO.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
SeisBase.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
end
elseif f == :corr
SeisIO.show_str(io, String[summary(targ)], w, N)
SeisBase.show_str(io, String[summary(targ)], w, N)
else
SeisIO.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
SeisBase.show_str(io, String[repr("text/plain", targ, context=:compact=>true)], w, N)
end
end
end
Expand Down
26 changes: 13 additions & 13 deletions src/filter.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DSP: resample
import SeisIO: resample, resample!
import SeisBase: resample, resample!
export bandpass, bandpass!, bandstop, bandstop!, lowpass, lowpass!
export highpass, highpass!, taper, taper!, envelope
export resample, resample!
Expand Down Expand Up @@ -409,23 +409,23 @@ end
"""
resample!(R, fs)
Resample data in `RawData` R to new sampling rate `fs`.
Resample data in `RawData` R to new sampling rate `fs`.
# Arguments
- `R::RawData`: RawData to resample.
- `R::RawData`: RawData to resample.
- `fs::Real`: New sampling frequency.
"""
function resample!(R::RawData,fs::Real)
@assert fs > 0 "New fs must be greater than 0!"
if R.fs == fs
return nothing
return nothing
end
T = eltype(R.x)
rate = T(fs / R.fs)
R.x = resample_kernel(R.x, rate)
R.fs = Float64(fs)
if (R.freqmax < fs / 2) && (rate < 1.0)
R.freqmax = Float64(fs / 2)
R.freqmax = Float64(fs / 2)
end
return nothing
end
Expand All @@ -434,30 +434,30 @@ resample(R::RawData,fs::Real) = (U = deepcopy(R); resample!(U,fs); return U)
"""
resample!(C, fs)
Resample data in CorrData` C to new sampling rate `fs`.
Resample data in CorrData` C to new sampling rate `fs`.
# Arguments
- `C::CorrData`: CorrData to resample.
- `C::CorrData`: CorrData to resample.
- `fs::Real`: New sampling frequency.
"""
function resample!(C::CorrData,fs::Real)
@assert fs > 0 "New fs must be greater than 0!"
if C.fs == fs
return nothing
if C.fs == fs
return nothing
end
T = eltype(C.corr)
rate = T(fs / C.fs)
C.corr = resample_kernel(C.corr, rate)
C.fs = Float64(fs)
if (C.freqmax < fs / 2) && (rate < 1.0)
C.freqmax = Float64(fs / 2)
C.freqmax = Float64(fs / 2)
end
return nothing
end
resample(C::CorrData,fs::Real) = (U = deepcopy(C); resample!(U,fs); return U)

function resample_kernel(x::AbstractMatrix,rate::Real)
T = eltype(x)
T = eltype(x)
h = resample_filter(rate)
self = FIRFilter(h, rate)

Expand All @@ -469,7 +469,7 @@ function resample_kernel(x::AbstractMatrix,rate::Real)
# b) set the ϕ index of the PFB (fractional part of τ)
setphase!(self, τ)

# calculate number of zeros
# calculate number of zeros
Nrows, Ncols = size(x)
outLen = ceil(Int, Nrows*rate)
reqInlen = inputlength(self, outLen)
Expand All @@ -485,4 +485,4 @@ function resample_kernel(x::AbstractMatrix,rate::Real)
out[1:xlength,ii] .= filt(deepcopy(self), xPadded[:,ii])
end
return out
end
end
6 changes: 3 additions & 3 deletions src/slicing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SeisIO: sync
import SeisBase: sync
export start_end, slide, nearest_start_end, slide_ind, sync
const μs = 1.0e-6
const= 1000000.0
Expand All @@ -9,7 +9,7 @@ const sμ = 1000000.0
Return start and endtimes of SeisChannel in DateTime format.
"""
function start_end(C::SeisChannel)
return u2d.(SeisIO.t_win(C.t,C.fs) * 1e-6)
return u2d.(SeisBase.t_win(C.t,C.fs) * 1e-6)
end

"""
Expand Down Expand Up @@ -101,7 +101,7 @@ slide(C::SeisChannel, cc_len::Real, cc_step::Real) = slide(C.x,cc_len,cc_step,C.
Return best possible start, end times for data in `C` given the `cc_step` and `cc_len`.
"""
function nearest_start_end(C::SeisChannel, cc_len::Float64, cc_step::Float64)
su,eu = SeisIO.t_win(C.t,C.fs) * μs
su,eu = SeisBase.t_win(C.t,C.fs) * μs
su = round(su,digits=4) # round due to numerical roundoff error
eu = round(eu,digits=4) # round due to numerical roundoff error
ideal_start = d2u(DateTime(Date(u2d(su)))) # midnight of same day
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Dates
using Dates
using FFTW
using Glob
using SeisIO
using SeisBase
using SeisNoise
using Statistics
using Test
import StatsBase: sample

include("test_NoiseData.jl")
include("test_show.jl")
Expand Down
16 changes: 8 additions & 8 deletions test/test_correlation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ rand_id() = string(rand_net(), ".", rand_sta(), ".", rand_loc(), ".HH", rand('A'
@test Cclean.freqmin == freqmin
@test Cclean.freqmax == freqmax
@test CInt.freqmin == freqmin
@test CInt.freqmax == freqmax
@test CInt.freqmax == freqmax

# test in-place
clean_up!(C,freqmin,freqmax)
Expand Down Expand Up @@ -107,7 +107,7 @@ end
@test all([t[maxinds[ii][1]] == 0 for ii in length(maxinds)])

# test correlation with FFTData
Ch = SeisIO.RandSeis.randSeisChannel(c=false,s=true)
Ch = SeisBase.RandSeis.randSeisChannel(c=false,s=true)
ungap!(Ch)
Ch.x = rand(T,Int(cc_len*Nwin*fs +1)) .- T(0.5)
Ch.fs = fs
Expand All @@ -125,7 +125,7 @@ end
@test all([t[maxinds[ii][1]] == 0 for ii in length(maxinds)]) # test max args
@test C.rotated == false # test rotation
@test C.corr_type == "CC" # test cross-correlation
@test C.maxlag == CInt.maxlag
@test C.maxlag == CInt.maxlag
@test C.corr == CInt.corr

# test windows that do not overlap
Expand Down Expand Up @@ -186,7 +186,7 @@ end
Fhigh = whiten(F,freqmin,fs/2,fs,N,pad=pad)
@test all(abs.(Fhigh[end-pad:end,:]) .< 1.)

# test with integer arguments
# test with integer arguments
FInt = whiten(F,Int(freqmin),Int(freqmax),Int(fs),N,pad=pad)

# test in-place
Expand All @@ -195,7 +195,7 @@ end
@test F == FInt

# test FFTData
Ch = SeisIO.RandSeis.randSeisChannel(c=false,s=true)
Ch = SeisBase.RandSeis.randSeisChannel(c=false,s=true)
Ch.loc = GeoLoc()
ungap!(Ch)
Ch.x = rand(T,Int(cc_len*Nwin*fs +1)) .- T(0.5)
Expand Down Expand Up @@ -230,7 +230,7 @@ end
@test Fhigh.freqmin == freqmin
@test Fhigh.freqmax == F.freqmax

# test with integer input
# test with integer input
FInt = whiten(F,Int(freqmin),Int(freqmax))
@test FInt.freqmin == freqmin
@test FInt.freqmax == freqmax
Expand Down Expand Up @@ -270,9 +270,9 @@ end
@test Rhigh.freqmin == freqmin
@test Rhigh.freqmax == R.freqmax

# test with integer input
# test with integer input
RInt = whiten(R,Int(freqmin),Int(freqmax))
@test RInt.freqmin == freqmin
@test RInt.freqmin == freqmin
@test RInt.freqmax == freqmax

# test in-place
Expand Down
2 changes: 1 addition & 1 deletion test/test_deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
@testset "compute cc" begin
cc_len = 40.96 # length of noise window
cc_step = 40.96 # step between windows
Ch = SeisIO.RandSeis.randSeisChannel(c=false,s=true)
Ch = SeisBase.RandSeis.randSeisChannel(c=false,s=true)
ungap!(Ch)
Ch.x = rand(T,Int(cc_len*Nwin*fs +1)) .- T(0.5)
Ch.fs = fs
Expand Down
2 changes: 1 addition & 1 deletion test/test_rotation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ starttime = d2u(DateTime(Date(now()))) # starttime for SeisChanel / SeisData

@testset "rotation" begin

Ch = SeisIO.RandSeis.randSeisChannel(c=false,s=true)
Ch = SeisBase.RandSeis.randSeisChannel(c=false,s=true)
ungap!(Ch)
Ch.x = rand(T,Int(cc_len*Nwin*fs +1)) .- T(0.5)
Ch.fs = fs
Expand Down

0 comments on commit d359fdb

Please sign in to comment.