Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede committed Dec 30, 2024
1 parent 39ae30f commit 7a8c438
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 16 deletions.
55 changes: 55 additions & 0 deletions src/multidomain.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export getparam, @unpack_params


"""
abstract type DomainParams
Abstract type for multidomain i.e. time, frequency domain models.
This is to extend existing models that are just definedin the image and
visibility domain and automatically extend them to time and frequency domain.
The interface is simple and to extend this with your own time and frequency models,
most users will just need to define
```julia
struct MyDomainParam <: DomainParams end
function build_params(param::MyDomainParam, p)
...
end
where `p` is the point where the model will be evaluated at. For an
example see the [`TaylorSpectralModel`](@ref).
For a model parameterized with a `<:DomainParams` the a use should access
the parameters with [`getparam`](@ref) or the `@unpack_params` macro.
```
"""
abstract type DomainParams end

abstract type FrequencyParams <: DomainParams end
abstract type TimeParams <: DomainParams end


"""
getparam(m, s::Symbol, p)
Gets the parameter value `s` from the model `m` evaluated at the domain `p`.
This is similar to getproperty, but allows for the parameter to be a function of the
domain. Essentially is `m.s <: DomainParams` then `m.s` is evaluated at the parameter `p`.
If `m.s` is not a subtype of `DomainParams` then `m.s` is returned.
!!! warn
This feature is experimental and is not considered part of the public stable API.
"""
@inline function getparam(m, s::Symbol, p)
ps = getproperty(m, s)
return build_param(ps, p)
end
@inline function getparam(m, ::Val{s}, p) where {s}
return getparam(m, s, p)
end

@inline function build_param(param::Any, p)
return param
end

6 changes: 3 additions & 3 deletions test/executors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
v = 0.1 * randn(60)
ti = collect(Float64, 1:60)
fr = fill(230e9, 60)
m = GaussTest(0.5)
m = GaussTest()

@test ThreadsEx() === ThreadsEx(:dynamic)

Expand Down Expand Up @@ -101,7 +101,7 @@ end
v = 0.1 * randn(60)
ti = collect(Float64, 1:60)
fr = fill(230e9, 60)
m = GaussTestNA(0.5)
m = GaussTestNA()

@test ThreadsEx() === ThreadsEx(:dynamic)

Expand Down Expand Up @@ -153,7 +153,7 @@ end
v = 0.1 * randn(60)
ti = collect(Float64, 1:60)
fr = fill(230e9, 60)
m = GaussTest(0.5)
m = GaussTest()

pim = (; X=range(-10.0, 10.0; length=64), Y=range(-10.0, 10.0; length=64))
gim = RectiGrid(pim)
Expand Down
21 changes: 8 additions & 13 deletions test/visibilities.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@

struct GaussTest{T} <: ComradeBase.AbstractModel
a::T
end
# GaussTest() = GaussTest{Float64}()
GaussTest() = GaussTest{Float64}()

ComradeBase.visanalytic(::Type{<:GaussTest}) = ComradeBase.IsAnalytic()
ComradeBase.imanalytic(::Type{<:GaussTest}) = ComradeBase.IsAnalytic()
ComradeBase.ispolarized(::Type{<:GaussTest}) = ComradeBase.NotPolarized()

function ComradeBase.intensity_point(m::GaussTest, p)
(; X, Y) = p
@unpack_params a = m(p)
return exp(-(X^2 + Y^2) * inv(2 * a^2)) / (2π * a)
return exp(-(X^2 + Y^2) * inv(2)) / (2π)
end

function ComradeBase.visibility_point(m::GaussTest, p)
(; U, V) = p
@unpack_params a = m(p)
return complex(exp(-2π^2 * a * (U^2 + V^2)))
return complex(exp(-2π^2 * (U^2 + V^2)))
end

ComradeBase.flux(::GaussTest{T}) where {T} = one(T)
ComradeBase.radialextent(::GaussTest{T}) where {T} = 5 * one(T)

struct GaussTestNA{T} <: ComradeBase.AbstractModel
a::T
end
GaussTestNA() = GaussTestNA{Float64}()

ComradeBase.visanalytic(::Type{<:GaussTestNA}) = ComradeBase.NotAnalytic()
ComradeBase.imanalytic(::Type{<:GaussTestNA}) = ComradeBase.NotAnalytic()
ComradeBase.ispolarized(::Type{<:GaussTestNA}) = ComradeBase.NotPolarized()

function ComradeBase.intensity_point(m::GaussTestNA, p)
(; X, Y) = p
@unpack_params a = m(p)
return exp(-(X^2 + Y^2) * inv(2 * a^2)) / (2π * a)
return exp(-(X^2 + Y^2) * inv(2)) / (2π)
end

function ComradeBase.visibility_point(m::GaussTestNA, p)
(; U, V) = p
@unpack_params a = m(p)
return complex(exp(-2π^2 * a * (U^2 + V^2)))
return complex(exp(-2π^2 * (U^2 + V^2)))
end

# Fake it to for testing
Expand Down Expand Up @@ -70,7 +65,7 @@ ComradeBase.radialextent(::GaussTestNA{T}) where {T} = 5 * one(T)
v = 0.1 * randn(60)
ti = collect(Float64, 1:60)
fr = fill(230e9, 60)
m = GaussTest(0.5)
m = GaussTest()
p = (; U=u, V=v, Ti=ti, Fr=fr)
g = UnstructuredDomain(p)
@test visibilitymap(m, g) ComradeBase.visibilitymap_analytic(m, g)
Expand All @@ -94,7 +89,7 @@ end
v = 0.1 * randn(60)
ti = collect(Float64, 1:60)
fr = fill(230e9, 60)
m = GaussTestNA(0.5)
m = GaussTestNA()
p = (; U=u, V=v, Ti=ti, Fr=fr)
g = UnstructuredDomain(p)
@test visibilitymap(m, g) ComradeBase.visibilitymap_analytic(m, g)
Expand Down

2 comments on commit 7a8c438

@ptiede
Copy link
Owner Author

@ptiede ptiede commented on 7a8c438 Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122188

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.7 -m "<description of version>" 7a8c438e1345bf800fdd5e2654783eb3d2927e23
git push origin v0.8.7

Please sign in to comment.