Skip to content

Commit b91e9b7

Browse files
authored
Merge pull request #383 from ptiede/ptiede-frequencysitearr
Multifrequency support for instrument modeling
2 parents f1971dd + 4efe705 commit b91e9b7

File tree

31 files changed

+613
-290
lines changed

31 files changed

+613
-290
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ParameterHandling = "0.4, 0.5"
8989
Pigeons = "0.3, 0.4"
9090
PolarizedTypes = "0.1"
9191
PrettyTables = "1, 2"
92-
Pyehtim = "0.1"
92+
Pyehtim = "0.2"
9393
RecipesBase = "1"
9494
Reexport = "1"
9595
SpecialFunctions = "0.10, 1, 2"

docs/CondaPkg.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/tutorials.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ withenv("JULIA_DEBUG"=>"Literate") do
2626
jl_expr = "using Literate;"*
2727
"preprocess(path, str) = replace(str, \"__DIR = @__DIR__\" => \"__DIR = \\\"\$(dirname(path))\\\"\");"*
2828
"Literate.markdown(\"$(p_)\", \"$(joinpath(OUTPUT, d))\";"*
29-
"name=\"$name\", execute=false, flavor=Literate.DocumenterFlavor(),"*
29+
"name=\"$name\", execute=true, flavor=Literate.DocumenterFlavor(),"*
3030
"preprocess=Base.Fix1(preprocess, \"$(p_)\"))"
3131
cm = `julia --project=$(@__DIR__) -e $(jl_expr)`
32-
run(cm)
32+
try
33+
run(cm)
34+
catch e
35+
@warn "there was an issues with $cm\n $e"
36+
end
3337

3438
end
3539
end

examples/advanced/HybridImaging/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CairoMakie = "0.12"
1818
Distributions = "0.25"
1919
Optimization = "4"
2020
Plots = "1"
21-
Pyehtim = "0.1"
21+
Pyehtim = "0.2"
2222
StableRNGs = "1"
2323
StatsBase = "0.34"
2424
VLBIImagePriors = "0.9"

examples/advanced/HybridImaging/main.jl

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import Pkg #hide
2+
__DIR = @__DIR__ #hide
3+
pkg_io = open(joinpath(__DIR, "pkg.log"), "w") #hide
4+
Pkg.activate(__DIR; io=pkg_io) #hide
5+
Pkg.develop(; path=joinpath(__DIR, "..", "..", ".."), io=pkg_io) #hide
6+
Pkg.instantiate(; io=pkg_io) #hide
7+
Pkg.precompile(; io=pkg_io) #hide
8+
close(pkg_io) #hide
9+
10+
11+
112
# # Hybrid Imaging of a Black Hole
213

314
# In this tutorial, we will use **hybrid imaging** to analyze the 2017 EHT data.
@@ -16,18 +27,6 @@
1627
# This is the approach we will take in this tutorial to analyze the April 6 2017 EHT data
1728
# of M87.
1829

19-
import Pkg #hide
20-
__DIR = @__DIR__ #hide
21-
pkg_io = open(joinpath(__DIR, "pkg.log"), "w") #hide
22-
Pkg.activate(__DIR; io=pkg_io) #hide
23-
Pkg.develop(; path=joinpath(__DIR, "..", "..", ".."), io=pkg_io) #hide
24-
Pkg.instantiate(; io=pkg_io) #hide
25-
Pkg.precompile(; io=pkg_io) #hide
26-
close(pkg_io) #hide
27-
28-
ENV["GKSwstype"] = "nul" #hide
29-
30-
3130
# ## Loading the Data
3231

3332
# To get started we will load Comrade
@@ -154,12 +153,10 @@ skym = SkyModel(sky, skyprior, g; metadata=skymetadata)
154153
using Enzyme
155154
post = VLBIPosterior(skym, intmodel, dvis; admode=set_runtime_activity(Enzyme.Reverse))
156155

157-
# To sample from our prior we can do
158-
xrand = prior_sample(rng, post)
159-
160-
# and then plot the results
156+
# We can sample from the prior to see what the model looks like
161157
using DisplayAs #hide
162158
import CairoMakie as CM
159+
xrand = prior_sample(rng, post)
163160
CM.activate!(type = "png", px_per_unit=1) #hide
164161
gpl = imagepixels(μas2rad(200.0), μas2rad(200.0), 128, 128)
165162
fig = imageviz(intensitymap(skymodel(post, xrand), gpl));
@@ -176,7 +173,7 @@ fig |> DisplayAs.PNG |> DisplayAs.Text #hide
176173
using Optimization
177174
using OptimizationOptimJL
178175
xopt, sol = comrade_opt(post, LBFGS();
179-
initial_params=xrand, maxiters=2000, g_tol=1e0)
176+
initial_params=xrand, maxiters=2000, g_tol=1e0);
180177

181178

182179
# First we will evaluate our fit by plotting the residuals
@@ -187,7 +184,8 @@ fig |> DisplayAs.PNG |> DisplayAs.Text #hide
187184
# These residuals suggest that we are substantially overfitting the data. This is a common
188185
# side effect of MAP imaging. As a result if we plot the image we see that there
189186
# is substantial high-frequency structure in the image that isn't supported by the data.
190-
imageviz(intensitymap(skymodel(post, xopt), gpl), figure=(;resolution=(500, 400),))
187+
fig = imageviz(intensitymap(skymodel(post, xopt), gpl), figure=(;resolution=(500, 400),));
188+
fig |> DisplayAs.PNG |> DisplayAs.Text #hide
191189

192190

193191
# To improve our results we will now move to Posterior sampling. This is the main method

examples/beginner/GeometricModeling/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Distributions = "0.25"
1818
Optimization = "4"
1919
Pigeons = "0.4"
2020
Plots = "1"
21-
Pyehtim = "0.1"
21+
Pyehtim = "0.2"
2222
StableRNGs = "1"
2323
VLBIImagePriors = "0.9"

examples/beginner/GeometricModeling/main.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import Pkg; #hide
2+
__DIR = @__DIR__ #hide
3+
pkg_io = open(joinpath(__DIR, "pkg.log"), "w") #hide
4+
Pkg.activate(__DIR; io=pkg_io) #hide
5+
Pkg.develop(; path=joinpath(__DIR, "..", "..", ".."), io=pkg_io) #hide
6+
Pkg.instantiate(; io=pkg_io) #hide
7+
Pkg.precompile(; io=pkg_io) #hide
8+
close(pkg_io) #hide
9+
10+
111
# # Geometric Modeling of EHT Data
212

313
# `Comrade` has been designed to work with the EHT and ngEHT.
@@ -9,22 +19,15 @@
919
# In this tutorial, we will construct a similar model and fit it to the data in under
1020
# 50 lines of code (sans comments). To start, we load Comrade and some other packages we need.
1121

12-
import Pkg #hide
13-
__DIR = @__DIR__ #hide
14-
pkg_io = open(joinpath(__DIR, "pkg.log"), "w") #hide
15-
Pkg.activate(__DIR; io=pkg_io) #hide
16-
Pkg.develop(; path=joinpath(__DIR, "..", "..", ".."), io=pkg_io) #hide
17-
Pkg.instantiate(; io=pkg_io) #hide
18-
Pkg.precompile(; io=pkg_io) #hide
19-
close(pkg_io) #hide
20-
ENV["GKSwstype"] = "nul" #hide
21-
22+
# To get started we load Comrade.
23+
#-
2224

2325
using Comrade
2426

2527

28+
# Currently we use eht-imaging for data management, however this will soon be replaced
29+
# by a pure Julia solution.
2630
using Pyehtim
27-
2831
# For reproducibility we use a stable random number genreator
2932
using StableRNGs
3033
rng = StableRNG(42)
@@ -81,7 +84,7 @@ prior = (
8184
ξτ= Uniform(0.0, π),
8285
f = Uniform(0.0, 1.0),
8386
σG = Uniform(μas2rad(1.0), μas2rad(100.0)),
84-
τG = Uniform(0.0, 1.0),
87+
τG = Exponential(1.0),
8588
ξG = Uniform(0.0, 1π),
8689
xG = Uniform(-μas2rad(80.0), μas2rad(80.0)),
8790
yG = Uniform(-μas2rad(80.0), μas2rad(80.0))
@@ -146,8 +149,8 @@ fpost = asflat(post)
146149
p = prior_sample(rng, post)
147150

148151
# and then transform it to transformed space using T
149-
logdensityof(cpost, Comrade.TV.inverse(cpost, p))
150-
logdensityof(fpost, Comrade.TV.inverse(fpost, p))
152+
logdensityof(cpost, Comrade.inverse(cpost, p))
153+
logdensityof(fpost, Comrade.inverse(fpost, p))
151154

152155
# note that the log densit is not the same since the transformation has causes a jacobian to ensure volume is preserved.
153156

@@ -238,3 +241,4 @@ DisplayAs.Text(DisplayAs.PNG(p))
238241
# and the model, divided by the data's error:
239242
p = residual(post, chain[end]);
240243
DisplayAs.Text(DisplayAs.PNG(p))
244+

examples/beginner/LoadingData/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Pyehtim = "3d61700d-6e5b-419a-8e22-9c066cf00468"
66

77
[compat]
88
Plots = "1"
9-
Pyehtim = "0.1"
9+
Pyehtim = "0.2"

examples/beginner/LoadingData/main.jl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
# # Loading Data into Comrade
2-
3-
# The VLBI field does not have a standardized data format, and the EHT uses a
4-
# particular uvfits format similar to the optical interferometry oifits format.
5-
# As a result, we reuse the excellent `eht-imaging` package to load data into `Comrade`.
6-
7-
# Once the data is loaded, we then convert the data into the tabular format `Comrade`
8-
# expects. Note that this may change to a Julia package as the Julia radio
9-
# astronomy group grows.
10-
11-
# To get started, we will load `Comrade` and `Plots` to enable visualizations of the data
121
import Pkg #hide
132
__DIR = @__DIR__ #hide
143
pkg_io = open(joinpath(__DIR, "pkg.log"), "w") #hide
@@ -18,11 +7,18 @@ Pkg.instantiate(; io=pkg_io) #hide
187
Pkg.precompile(; io=pkg_io) #hide
198
close(pkg_io) #hide
209

21-
ENV["GKSwstype"] = "nul" #hide
10+
# # Loading Data into Comrade
2211

12+
# The VLBI field does not have a standardized data format, and the EHT uses a
13+
# particular uvfits format similar to the optical interferometry oifits format.
14+
# As a result, we reuse the excellent `eht-imaging` package to load data into `Comrade`.
2315

24-
using Comrade
16+
# Once the data is loaded, we then convert the data into the tabular format `Comrade`
17+
# expects. Note that this may change to a Julia package as the Julia radio
18+
# astronomy group grows.
2519

20+
# To get started, we will load `Comrade` and `Plots` to enable visualizations of the data
21+
using Comrade
2622
using Plots
2723

2824
# We also load Pyehtim since it loads eht-imaging into Julia using PythonCall and exports

examples/intermediate/ClosureImaging/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Distributions = "0.25"
2424
Optimization = "4"
2525
Pkg = "1"
2626
Plots = "1"
27-
Pyehtim = "0.1"
27+
Pyehtim = "0.2"
2828
StableRNGs = "1"
2929
VLBIImagePriors = "0.9"

0 commit comments

Comments
 (0)