Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jpjones76 committed May 24, 2016
1 parent 4d263f6 commit ed555ba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
34 changes: 19 additions & 15 deletions docs/src/seisdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,28 @@ Appending without merging

Deleting Data
=============
``-`` (the subtraction operator) is the standard way to delete unwanted data channels. It's generally safest to use e.g. ``T = S - i``, but in-place deletion (e.g. ``S -= i``) is valid. The exact behavior for a general operation ``S - K`` depends on the type of the addend:
``-`` (the subtraction operator) is the standard way to delete unwanted data channels. It's generally safest to use e.g. ``T = S - i``, but in-place deletion (e.g. ``S -= i``) is valid. The exact behavior for a general operation ``S - K`` depends on the data type of the addend:

* If K is an integer, channel k is deleted from S.
Methods
-------
``S - i``, where ``i`` is an integer, deletes the ``i``\ th channel of S.

* If K is a string, all channels whose names and ids match k are deleted.
``S - str``, where ``str`` is a string, deletes all channels whose names and ids match ``str``.

* If K is a SeisObj instance, all channels from S with the same id as k are deleted.
``S - U``, where ``U`` is a SeisObj instance, deletes all channels from ``S`` with the same id value as ``U.id``.

``deleteat!(S,i)`` is identical to ``S-=K`` for an integer K.
``deleteat!(S,i)`` is identical to ``S-=K`` for integer K.


Safe deletion with ``pull``
---------------------------
===========================
The ``pull`` command extracts a channel from a SeisData instance and returns it as a SeisObj.
```T = pull(S, name)``, where ``name`` is a string, creates a SeisObj ``T`` from the first channel with name=``name``. The channel is removed from `S`.
+ `T = pull(S, i)`, where `i` is an integer, creates a SeisObj `T` from
channel `i` and removes channel `i` from `S`.

Methods
-------
``T = pull(S, name)``, where ``name`` is a string, creates a SeisObj ``T`` from the first channel with name=``name``, then removes the matching channel from ``S``.

``T = pull(S, i)``, where ``i`` is an integer, creates a SeisObj ``T`` from channel ``i``, then removes channel ``i`` from ``S``.


Index, Search, Sort
Expand Down Expand Up @@ -123,20 +128,19 @@ SeisData and SeisObj are intended to be annotated as data are analyzed; the comm

Utility Functions
=================
* ``plotseis``: Plot time-aligned data from a SeisData object. Time series data are represented by straight lines; irregularly sampled data (``fs=0``) use normalized stem plots.
* ``autotap!``: Apply a cosine taper to non-gap subsequences of all time series data. Removes the mean of all time series channels. Calls ``ungap!``.

* ``plotseis``: Plot time-aligned data from a SeisData object. Time series data are represented by straight lines; irregularly sampled data (``fs=0``) use normalized stem plots. Data are labeled by channel id; change this with keyword ``use_name=true``.

* ``prune!, prune``: Merge channels with redundant header fields.

* ``purge!, purge``: Delete all channels with no data (defined for any channel ``i`` by ``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 ``autotap!``, which in turn de-means and calls ``ungap!``.

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

* ``autotap!``: Cosine taper time series data around time gaps.



Native File I/O
===============
Use ``rseis`` and ``wseis`` to read and save in native format. ``writesac(S)`` saves trace data in ``S`` to single-channel :ref:`SAC <sac1>` files. SAC is widely used and well-supported, but writes data in single-precision format with rudimentary time stamping. The last point merits brief discussion. Time stamps are written to SAC by default (change this with kw ``ts=false``). Tme stamped SAC data are treated by SAC itself as unevenly spaced, generic ``x-y`` data (``LEVEN=0, IFTYPE=4``). However, third-party SAC readers interpret such files less predictably: timestamped data *might* be loaded as the real part of a complex time series, with the time values themselves as the imaginary part...or the other way around...or not at all.
Use ``rseis`` and ``wseis`` to read and save in native format. ``writesac(S)`` saves trace data in ``S`` to single-channel :ref:`SAC <sac1>` files. SAC is widely used and well-supported, but writes data in single-precision format with rudimentary time stamping. The last point merits brief discussion. Time stamps are written to SAC by default (change this by setting ``ts=false``). Tme stamped SAC data are treated by SAC itself as unevenly spaced, generic ``x-y`` data (``LEVEN=0, IFTYPE=4``). However, third-party SAC readers interpret such files less predictably: timestamped data *might* be loaded as the real part of a complex time series, with the time values themselves as the imaginary part...or the other way around...or not at all.
7 changes: 4 additions & 3 deletions src/SeisData/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ purge(S::SeisData) = (T = deepcopy(S); purge!(T); return(T))
Fill gaps in x, as specified in t, assuming sampling rate fs
"""
function gapfill!(x::Array{Float64,1}, t::Array{Float64,2}, fs::Float64; m=true::Bool, w=true::Bool)
(fs == 0 || fs == Inf) && (return x)
mx = m ? mean(x[!isnan[x]]) : NaN
(fs == 0 || isempty(x)) && (return x)
mx = m ? mean(x[!isnan(x)]) : NaN
u = round(Int, max(20,0.2*fs))
for i = size(t,1):-1:2
g = t[i,2]
Expand Down Expand Up @@ -158,7 +158,8 @@ function sync!(S::SeisData; resample=false::Bool, fs=0::Real,
t="max"::Union{ASCIIString,Real,DateTime})

# Do not edit order of operations
ungap!(S)
ungap!(S, m=false, w=false)
autotap!(S)
start_times = zeros(S.n)
end_times = zeros(S.n)
c = find(S.fs .== 0)
Expand Down
2 changes: 1 addition & 1 deletion src/SeisData/randseis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function populate_seis!(S::SeisData; c=false::Bool)
end
end
end
populate_seis!(S::SeisData, N::Int; c=false::Bool) = ([append!(S,
populate_seis!(S::SeisData, N::Int; c=false::Bool) = ([push!(S,
randseisobj(c=c)) for n = 1:N])

"""
Expand Down
1 change: 1 addition & 0 deletions test/seisdata_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ ungap!(S, m=false, w=false)
# Auto-tapering after a merge
T = deepcopy(S)
ii = find(isnan(S.x[1]))
T.x[1] -= mean(T.x[1][!isnan(T.x[1])])
autotap!(S)
@test_approx_eq(0, length(find(isnan(S.x[1])))) # No more NaNs?
@test_approx_eq(sum(diff(S.x[1][ii])), 0) # All NaNs filled w/same val?
Expand Down

0 comments on commit ed555ba

Please sign in to comment.