-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
218c98e
commit 7088011
Showing
19 changed files
with
2,841 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
include("radialProfiles.jl") | ||
|
||
#= | ||
Functions for Cost and Gradient used in the Optimize step with LBFGS | ||
NB: Reparameterization for [s, g1, g2] via [σ, e1, e2] to constraint update steps inside R+ x B_2(r) | ||
=# | ||
|
||
function cost(params; r = r, c= c, starL=starCatalog[iteration], radial=fGaussian, AnalyticStampSize=AnalyticStampSize, get_middle_nxn=get_middle_nxn) | ||
Totalcost = 0 | ||
σ = params[1] | ||
s_guess = σ^2 | ||
e1_guess = params[2] | ||
e2_guess = params[3] | ||
ellipticity = sqrt((e1_guess)^2 + (e2_guess)^2) | ||
normG = sqrt(1 + 0.5*( (1/ellipticity^2) - sqrt( (4/ellipticity^2)+ (1/ellipticity^4) ) )) | ||
ratio = ellipticity/normG | ||
g1_guess = e1_guess/ratio | ||
g2_guess = e2_guess/ratio | ||
|
||
starL = get_middle_nxn(starL, AnalyticStampSize) | ||
r = AnalyticStampSize | ||
c = AnalyticStampSize | ||
|
||
sum = 0 | ||
for u in 1:r | ||
for v in 1:c | ||
try | ||
sum += radial(u,v, g1_guess, g2_guess, s_guess, r/2,c/2) | ||
catch | ||
sum += 0 | ||
end | ||
end | ||
end | ||
A_guess = 1/sum | ||
|
||
for u in 1:r | ||
for v in 1:c | ||
if isnan(starL[u,v]) | ||
Totalcost += 0 | ||
else | ||
Totalcost += 0.5*(A_guess*radial(u, v, g1_guess, g2_guess, s_guess, r/2, c/2) - starL[u, v])^2 | ||
end | ||
end | ||
end | ||
return Totalcost | ||
end | ||
|
||
|
||
function costD(params; r=r, c=c, starL=pixelGridFits[iteration], radial=fGaussian, AnalyticStampSize=AnalyticStampSize, get_middle_nxn=get_middle_nxn) | ||
Totalcost = 0 | ||
σ = params[1] | ||
s_guess = σ^2 | ||
e1_guess = params[2] | ||
e2_guess = params[3] | ||
ellipticity = sqrt((e1_guess)^2 + (e2_guess)^2) | ||
normG = sqrt(1 + 0.5*( (1/ellipticity^2) - sqrt( (4/ellipticity^2)+ (1/ellipticity^4) ) )) | ||
ratio = ellipticity/normG | ||
g1_guess = e1_guess/ratio | ||
g2_guess = e2_guess/ratio | ||
|
||
starL = get_middle_nxn(starL, AnalyticStampSize) | ||
r = AnalyticStampSize | ||
c = AnalyticStampSize | ||
|
||
sum = 0 | ||
for u in 1:r | ||
for v in 1:c | ||
try | ||
sum += radial(u,v, g1_guess, g2_guess, s_guess, r/2,c/2) | ||
catch | ||
sum += 0 | ||
end | ||
end | ||
end | ||
A_guess = 1/sum | ||
|
||
for u in 1:r | ||
for v in 1:c | ||
if isnan(starL[u,v]) | ||
Totalcost += 0 | ||
else | ||
Totalcost += 0.5*(A_guess*radial(u, v, g1_guess, g2_guess, s_guess, r/2, c/2) - starL[u, v])^2 | ||
end | ||
end | ||
end | ||
return Totalcost | ||
end | ||
|
||
function g!(storage, p) | ||
grad_cost = ForwardDiff.gradient(cost, p) | ||
storage[1] = grad_cost[1] | ||
storage[2] = grad_cost[2] | ||
storage[3] = grad_cost[3] | ||
end | ||
|
||
function gD!(storage, p) | ||
grad_cost = ForwardDiff.gradient(costD, p) | ||
storage[1] = grad_cost[1] | ||
storage[2] = grad_cost[2] | ||
storage[3] = grad_cost[3] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#= | ||
Function to parse arguments from the command line | ||
=# | ||
|
||
function process_arguments(args) | ||
fancyPrint("Parsing Arguments") | ||
configdir = args[1] | ||
println("━ Config Directory: ", configdir) | ||
outdir = args[2] | ||
println("━ Output Directory: ", outdir) | ||
catalog = args[3] | ||
println("━ Catalog: ", catalog) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function chisq_cost(params; starL=starCatalog[iteration], weight_map=errVignets[iteration]) | ||
pixel_values = params | ||
chisq = sum(x -> isfinite(x) ? x : 0, (pixel_values .- vec(starL)) .^ 2 ./ vec(weight_map)) | ||
return chisq | ||
end | ||
|
||
|
||
function chisq_g!(storage, p) | ||
chisq_grad_cost = ForwardDiff.gradient(chisq_cost, p) | ||
storage[1:length(chisq_grad_cost)] = chisq_grad_cost | ||
end | ||
|
Oops, something went wrong.