Skip to content

Commit

Permalink
added append! method for SeisData
Browse files Browse the repository at this point in the history
  • Loading branch information
jpjones76 committed May 24, 2016
1 parent 7e5a429 commit 0992039
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
40 changes: 13 additions & 27 deletions docs/src/seisdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,36 @@
***************
:mod:`SeisData`
***************
SeisData is a minimalist class (type) designed for discretely sampled sequential signals, including (but not limited to) time-series data. It can hold both regularly sampled (time series) data and irregularly sampled measurements.
SeisData is a minimalist container type designed for discretely sampled sequential signals, including (but not limited to) time-series data. It can hold both regularly sampled (time series) data and irregularly sampled measurements.

SeisData and SeisObj instances can be manipulated using standard Julia commands. The rest of this section explains this functionality in detail.
SeisData and SeisObj containers can be manipulated using standard Julia commands. The rest of this section explains this functionality in detail.


Creating Data Containers
========================
* ``S = SeisData()``
SeisData and SeisObj containers can be created in three ways:

initialize an empty SeisData container
#. ``S = SeisData()`` initializes an empty SeisData container

* ``S = SeisObj()``
#. ``S = SeisObj()`` initializes a new SeisObj container

initialize a new SeisObj container
#. ``S = SeisData(s1, s2, s3)`` creates a SeisData container by merging s1, s2, s3. If a merge variable isn't of type SeisData or SeisObj, it's ignored and a warning is given to STDOUT.

* ``S = SeisData(s1, s2, s3)``

create a SeisData container by merging s1, s2, s3.

When using the third syntax, if a merge variable isn't of class SeisData or SeisObj, it's ignored with a warning.

Fields can be initialized by name when a new SeisObj container is created.

* ``S = SeisObj(name="DEAD CHANNEL", fs=50)``

initialize a SeisObj with name "DEAD CHANNEL", fs = 50.
Fields can be initialized by name when a new SeisObj container is created; for example,``S = SeisObj(name="DEAD CHANNEL", fs=50)`` initialize a SeisObj with name "DEAD CHANNEL", fs = 50.



Adding Data
===========
``+`` (the addition operator) is the standard way to add data channels. Addition attempts to merge data with matching channel IDs. Channels with unique IDs are simply assigned as new channels. ``merge!`` and ``+`` work identically on SeisData and SeisObj containers.

Data can be merged from any file read or data acquisition command that outputs a SeisData or SeisObj structure.

* ``S += r_sac(sacfile.sac)``
``+`` (the addition operator) is the standard way to add data channels. Addition attempts to merge data with matching channel IDs. Channels with unique IDs are simply assigned to new channels. ``merge!`` and ``+`` are identical commands for SeisData and SeisObj instances.

merge data from sacfile.sac into S in place.
Data can be merged directly from the output of any SeisIO command that outputs a compatible structure. For example:

* ``T = S + SeedLink("myconfig", t=300)``
``S += r_sac(sacfile.sac)`` merges data from sacfile.sac into S in place.

merge 300 seconds of SeedLink data into S using config file "myconfig".
``T = S + SeedLink("myconfig", t=300)`` merges 300 seconds of SeedLink data into S, where the data are acquired using config file "myconfig".

* In a merge operation, pairs of data `x`:sub:`i`, `x`:sub:`j` with overlapping time stamps (i.e. `t`:sub:`i` - `t`:sub:`j` < 1/fs) are *averaged*.
In a merge operation, pairs of non-NaN data `x`:sub:`i`, `x`:sub:`j` with overlapping time stamps (i.e. `t`:sub:`i` - `t`:sub:`j` < 1/fs) are *averaged*.


Appending without merging
Expand Down Expand Up @@ -131,7 +117,7 @@ Utility Functions

* ``purge!, purge``: Deletes all channels with no data (defined for any channel i as isempty(S.x[i]) == true).

* ``sync!, sync``: Synchronize time windows for all channels and fill time gaps. Calls ungap at invocation.
* ``sync!, sync``: Synchronize time windows for all channels and fill time gaps. Calls ungap at invocation.

* ``ungap!, ungap``: Fill all time gaps in each channel of regularly sampled data.

Expand Down
6 changes: 1 addition & 5 deletions src/SeisData/SeisData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ samehdr(S::SeisData, T::SeisObj, i) = (
# Append, delete
push!(S::SeisData, T::SeisObj; n=true::Bool) = ([push!(S.(i),T.(i)) for i in fieldnames(T)];
S.n += 1; n && (note(S, S.n, @sprintf("Channel added."));))
append!(S::SeisData, T::SeisObj; n=true::Bool) = push!(S, T, n=n)
append!(S::SeisData, T::SeisData; n=true::Bool) = ([push!(S,T[i],n=n) for i = 1:S.n])
deleteat!(S::SeisData, j::Int) = ([deleteat!(S.(i),j) for i in datafields(S)];
S.n -= 1;)
deleteat!(S::SeisData, J::Range) = (collect(J); [deleteat!(S, j)
Expand Down Expand Up @@ -427,8 +427,6 @@ function merge!(S::SeisObj, U::SeisObj)

# Two full channels
S.fs != U.fs && error("Sampling frequency mismatch; correct manually.")
# ungap!(S, m=false, w=false)
# T = ungap(U, m=false, w=false)
T = deepcopy(U)
if !isapprox(S.gain,T.gain)
(T.x .*= (S.gain/T.gain); T.gain = copy(S.gain)) # rescale T.x to match S.x
Expand All @@ -453,8 +451,6 @@ function merge!(S::SeisData, U::SeisObj)
i = i[1]
S.fs[i] != U.fs && return push!(S,U)
T = deepcopy(U)
#ungap!(S[i], m=false, w=false)
#ungap!(T, m=false, w=false)
if !isapprox(S.gain[i],T.gain)
(T.x .*= (S.gain[i]/T.gain); T.gain = copy(S.gain[i])) # rescale T.x to match S.x
end
Expand Down

0 comments on commit 0992039

Please sign in to comment.