Skip to content

Commit

Permalink
For 'stem's ymin must always be <= 0 (#1681)
Browse files Browse the repository at this point in the history
* Unccoment the two tests that were failing due to a edit bug.

* For 'stem's ymin must always be <= 0

* Fix copy-past error that was testing a wrong dimension.
  • Loading branch information
joa-quim authored Mar 1, 2025
1 parent fa05338 commit ffab0c7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ function stem(cmd0::String="", arg1=nothing; first=true, kwargs...)
end
if (!haveR)
t = round_wesn(mimas) # Add a pad. Also sets the CTRL.limits plot values
(t[3] > 0) && (t[3] = 0) # Stems, when all positives, must start at zero
CTRL.limits[1:4] = mimas # These are the data limits
opt_R::String = @sprintf(" -R%.12g/%.12g/%.12g/%.12g", t[1], t[2], t[3], t[4])
_opt_R::String = merge_R_and_xyzlims(d, opt_R) # See if a x or ylim is used
Expand Down
70 changes: 29 additions & 41 deletions src/signalcorr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
# autocorrelation
# cross-correlation

function xcorr(x::AbstractVector{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
_lags = !isempty(lags) ? lags : (maxlags == 0 ? default_autolags(length(x)) : 0:minimum(maxlags, length(x)-1))
out = Vector{float(eltype(x))}(undef, length(_lags))
autocor!(out, x, _lags; demean=demean)
end

function xcorr(x::AbstractMatrix{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
_lags = !isempty(lags) ? lags : (maxlags == 0 ? default_autolags(size(x,1)) : 0:minimum(maxlags, size(x,1)-1))
out = Matrix{float(eltype(x))}(undef, length(_lags), size(x,2))
autocor!(out, x, _lags; demean=demean)
end

#---------------------------------------------------------------------------------------------------------------------
"""
xcorr(x::AbstractVecOrMat{<:Real}, y::AbstractVecOrMat{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
Expand All @@ -39,8 +26,17 @@ a function of the lag.
`-min(size(x,1)-1, 10*log10(size(x,1))) to min(size(x,1), 10*log10(size(x,1)))`
- `maxlags`: limits the lag range from `-maxlag` to `maxlag`.
"""
xcorr(x::AbstractVecOrMat{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0) =
xcorr(x, demean=demean, lags=lags, maxlags=maxlags)
function xcorr(x::AbstractVector{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
_lags = !isempty(lags) ? lags : (maxlags == 0 ? default_autolags(length(x)) : 0:minimum(maxlags, length(x)-1))
out = Vector{float(eltype(x))}(undef, length(_lags))
autocor!(out, x, _lags; demean=demean)
end

function xcorr(x::AbstractMatrix{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
_lags = !isempty(lags) ? lags : (maxlags == 0 ? default_autolags(size(x,1)) : 0:minimum(maxlags, size(x,1)-1))
out = Matrix{float(eltype(x))}(undef, length(_lags), size(x,2))
autocor!(out, x, _lags; demean=demean)
end

#---------------------------------------------------------------------------------------------------------------------
function xcorr(x::AbstractVector{<:Real}, y::AbstractVector{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
Expand Down Expand Up @@ -68,10 +64,24 @@ function xcorr(x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}; lags::Abstr
end

#---------------------------------------------------------------------------------------------------------------------
xcorr(x::AbstractVecOrMat{<:Real}, y::AbstractVecOrMat{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0) =
xcorr(x, y, demean=demean, lags=lags, maxlags=maxlags)
"""
xcov(x, y, [lags]; demean=true)
#---------------------------------------------------------------------------------------------------------------------
Compute the cross covariance function (CCF) between real-valued vectors or
matrices `x` and `y`, optionally specifying the `lags`. `demean` specifies
whether the respective means of `x` and `y` should be subtracted from them
before computing their CCF.
If both x and y are vectors, return a vector of the same length as lags. Otherwise,
compute cross covariances between each pairs of columns in x and y.
### Kwargs
- `demean`: Specifies whether the respective means of x and y should be subtracted from them before
computing their cross covariance.
- `lags`: When left unspecified and `maxlags=0`, the lags used are the integers from
`-min(size(x,1)-1, 10*log10(size(x,1))) to min(size(x,1), 10*log10(size(x,1)))`
- `maxlags`: limits the lag range from `-maxlag` to `maxlag`.
"""
function xcov(x::AbstractVector{<:Real}, y::AbstractVector{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
_lags = !isempty(lags) ? lags : (maxlags == 0 ? default_crosslags(length(x)) : 0:minimum(maxlags, length(x)-1))
out = Vector{float(Base.promote_eltype(x, y))}(undef, length(_lags))
Expand All @@ -96,28 +106,6 @@ function xcov(x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}; lags::Abstra
crosscov!(out, x, y, _lags; demean=demean)
end

#---------------------------------------------------------------------------------------------------------------------
"""
xcov(x, y, [lags]; demean=true)
Compute the cross covariance function (CCF) between real-valued vectors or
matrices `x` and `y`, optionally specifying the `lags`. `demean` specifies
whether the respective means of `x` and `y` should be subtracted from them
before computing their CCF.
If both x and y are vectors, return a vector of the same length as lags. Otherwise,
compute cross covariances between each pairs of columns in x and y.
### Kwargs
- `demean`: Specifies whether the respective means of x and y should be subtracted from them before
computing their cross covariance.
- `lags`: When left unspecified and `maxlags=0`, the lags used are the integers from
`-min(size(x,1)-1, 10*log10(size(x,1))) to min(size(x,1), 10*log10(size(x,1)))`
- `maxlags`: limits the lag range from `-maxlag` to `maxlag`.
"""
xcov(x::AbstractVecOrMat{<:Real}, y::AbstractVecOrMat{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0) =
xcov(x, y, demean=demean, lags=lags, maxlags=maxlags)


"""
xcov(x::AbstractVecOrMat{<:Real}; demean::Bool=true, lags::AbstractVector{<:Integer}=Int[], maxlags=0)
Expand Down Expand Up @@ -475,7 +463,7 @@ function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::Abst
end

function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx, ns, m = size(x, 1), size(x, 2), length(lags)
lx, ns, m = size(x, 1), size(y, 2), length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)

Expand Down
5 changes: 3 additions & 2 deletions test/test_signalcorr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ c22 = GMT.crosscov(x2, x2)

@test GMT.crosscov(x, x1) [c11 c21]
@test GMT.crosscov(realx, realx1) [c11 c21]
#@test GMT.crosscov(x1, x) ≈ [c11 c12]
#@test GMT.crosscov(realx1, realx) ≈ [c11 c12]
@test GMT.crosscov(x1, x) [c11 c12]
@test GMT.crosscov(realx1, realx) [c11 c12]
@test GMT.crosscov(x, x) cat([c11 c21], [c12 c22], dims=3)
@test GMT.crosscov(realx, realx) cat([c11 c21], [c12 c22], dims=3)
@test xcov(x, x1) [c11 c21]
@test xcov(realx, realx1) [c11 c21]
@test xcov(x1, x) [c11 c12]
@test xcov(x, x) cat([c11 c21], [c12 c22], dims=3)
@test xcov(realx, realx) cat([c11 c21], [c12 c22], dims=3)

Expand Down

0 comments on commit ffab0c7

Please sign in to comment.