Skip to content

Commit

Permalink
add sth
Browse files Browse the repository at this point in the history
  • Loading branch information
wssuzb committed Dec 24, 2023
1 parent 70fab69 commit d456ce7
Show file tree
Hide file tree
Showing 14 changed files with 7,310 additions and 622 deletions.
4,262 changes: 4,262 additions & 0 deletions docs/src/assets/fig/lc_check_i_z.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
426 changes: 426 additions & 0 deletions docs/src/assets/fig/plot_cv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
642 changes: 642 additions & 0 deletions docs/src/assets/fig/plot_sf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 129 additions & 1 deletion docs/src/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,132 @@ To use **Jirachi**, we need to import...



## Loading light curves
## Loading light curves

```julia
# load light curves.
i_lc = load_data("./data/montano_n1_i_4395.txt", [1, 2, 3]; band="i")
z_lc = load_data("./data/montano_n1_z_4395.txt", [1, 2, 3]; band="z")

# convert time to second, and start it from 0 second.
i_lc.time = round.(i_lc.time * 24 * 3600, digits=2)
i_lc.time = i_lc.time .- i_lc.time[1]
z_lc.time = round.(z_lc.time * 24 * 3600, digits=2)
z_lc.time = z_lc.time .- z_lc.time[1]
```

## Get the light curves binned

```julia
t_binsize = 103.68
lc_edges = bin_lc_edges(t_binsize, 0, 25000)

i_lc_bin = bin_light_curve(i_lc; lc_edges = lc_edges)
z_lc_bin = bin_light_curve(z_lc; lc_edges = lc_edges)

lc1_bin, lc2_bin = get_common_lc(i_lc_bin, z_lc_bin)
```

## check and plot it !

```julia
plotlc(i_lc, i_lc_bin, z_lc, z_lc_bin;
label=[i_lc.band, i_lc.band * "_bin", z_lc.band, z_lc.band * "_bin"],
lc_edges=lc_edges,
save_fig_path="./fig/lc_check_i_z.svg",
save_fig=true,
hwratio=0.3)
```

![lc](../assets/fig/lc_check_i_z.svg)

### Begin calculating structure function!

### input parameters

```julia
# structure function
sf_bin = 0.05
sf_bin_edges = 0:sf_bin:5 # in log space
mode = "both" # lc bootstrapped for structure function error
nsim = 1000 # lc bootstrapped for structure function error
lower_bounds = [0, 0, 0, 0.001]
upper_bounds = [10, 2e4, 2, 0.1]
p0 = [1, 1e3, 1, 0.005]

t_fit = 10 .^ range(log10(1), log10(6e4), step=0.1)

# color variation
cv_bin = 0.1
cv_bin_edges = 0:cv_bin:5 # in log space
nsigma = 3
erron=true

# save all run results.
fi_np::String="./data/run_i_z.h5"

```



### Structure function

```julia
fit_sf1 = fitsf_mcmc(lc1_bin; nsim=nsim, lb = lower_bounds , ub = upper_bounds, sf_bin_edges=sf_bin_edges, p0=p0, mode = mode)
fit_sf2 = fitsf_mcmc(lc2_bin; nsim=nsim, lb = lower_bounds, ub = upper_bounds, sf_bin_edges=sf_bin_edges, p0=p0, mode = mode)

binsf1, binsf2 = fit_sf1.binsf, fit_sf2.binsf

par_1, par_1_err = fit_sf1.param, fit_sf1.param_err
par_2, par_2_err = fit_sf2.param, fit_sf2.param_err


t_break_1 = find_t_break(binsf1)
t_break_2 = find_t_break(binsf2)

itp1 = find_t_min(binsf1, par_1; t_fit=t_fit)
itp2 = find_t_min(binsf2, par_2; t_fit=t_fit)

t_min_1, sf_min_1 = itp1.t_min, itp1.sf_min
t_min_2, sf_min_2 = itp2.t_min, itp2.sf_min

t_fit_1, sf_fit_1 = itp1.t_fit, itp1.sf_fit
t_fit_2, sf_fit_2 = itp2.t_fit, itp2.sf_fit


proper_time = [maximum([t_min_1, t_min_2]), minimum([t_break_1, t_break_2])]
```



## and show it

```julia
plotsf(binsf1, binsf2; fitsf1=[t_fit_1, sf_fit_1], fitsf2=[t_fit_2, sf_fit_2], proper_time = proper_time)
```

![sf](../assets/fig/plot_sf.svg)

### calculating color variation

```julia
nsigma = nsigma
erron = erron

# cv in flux-Flux
cv_flux_res = color_variation(lc1_bin, lc2_bin, nsigma, erron, "flux")
cv_flux = cv_flux_res

bincv_flux = binned_color_variation(cv_flux, cv_bin_edges)

# cv in mag-mag
cv_mag_res = color_variation(lc1_bin, lc2_bin, nsigma, erron, "mag")
cv_mag = cv_mag_res

bincv_mag = binned_color_variation(cv_mag, cv_bin_edges)
```

and plot it

![cv](../assets/fig/plot_cv.svg)

2 changes: 1 addition & 1 deletion src/Jirachi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export jmodel, model, fitsf, fitsf_mcmc, find_t_min, find_t_break

export runall

export IntegerTicks, theme_lc, theme_sf, plotlc, plotsf
export IntegerTicks, theme_lc, theme_sf, plotlc, plotsf, plotcv


end
76 changes: 62 additions & 14 deletions src/plotting.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
export theme_sf, theme_hist, theme_lc, IntegerTicks, plotlc, plotsf
export theme_sf, theme_hist, theme_lc, IntegerTicks, plotlc, plotsf, plotcv


struct IntegerTicks end

Makie.get_tickvalues(::IntegerTicks, vmin, vmax) = ceil(Int, vmin) : floor(Int, vmax)


theme_lc = merge(theme_web(width=1000,
colors=MakiePublication.tableau_10(),
linestyles=[nothing, :dash, :dash],
ishollowmarkers=[true, true, false],
markers=[:circle, :diamond, :rtriangle],
linecycle=Cycle([:color, :linestyle], covary=true),
scattercycle=Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true),
markerstrokewidth=0.8,
heightwidthratio=0.3,
), theme_latexfonts())
# theme_lc = merge(theme_web(width=1000,
# colors=MakiePublication.tableau_10(),
# linestyles=[nothing, :dash, :dash],
# ishollowmarkers=[true, true, false],
# markers=[:circle, :diamond, :rtriangle],
# linecycle=Cycle([:color, :linestyle], covary=true),
# scattercycle=Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true),
# markerstrokewidth=0.8,
# heightwidthratio=0.3,
# ), theme_latexfonts())


theme_hist = merge(theme_web(width=350, colors=MakiePublication.tableau_10(),linestyles=[nothing, :dash, :dash], ishollowmarkers=[true, true, false], markers=[:circle, :diamond, :rtriangle], linecycle=Cycle([:color, :linestyle], covary=true), scattercycle=Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true), markerstrokewidth=0.8, heightwidthratio=0.9,), theme_latexfonts())
# theme_hist = merge(theme_web(width=350, colors=MakiePublication.tableau_10(),linestyles=[nothing, :dash, :dash], ishollowmarkers=[true, true, false], markers=[:circle, :diamond, :rtriangle], linecycle=Cycle([:color, :linestyle], covary=true), scattercycle=Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true), markerstrokewidth=0.8, heightwidthratio=0.9,), theme_latexfonts())

# theme_llc = merge(theme_web(width=1000,
# colors=MakiePublication.COLORS[5],
Expand Down Expand Up @@ -88,7 +88,7 @@ end



function plotsf(binsf1::binned_result, binsf2::binned_result; fitsf1=[], fitsf2=[], proper_time=[])
function plotsf(binsf1::binned_result, binsf2::binned_result; fitsf1=[], fitsf2=[], proper_time=[], save_fig_path::String="./fig/plot_sf.svg", save_fig::Bool=true)
theme_sf = merge(theme_web(width=350, colors=MakiePublication.tableau_10(),linestyles=[nothing, :dash, :dash], ishollowmarkers=[true, true, false], markers=[:circle, :diamond, :rtriangle], linecycle=Cycle([:color, :linestyle], covary=true), scattercycle=Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true), markerstrokewidth=0.8, heightwidthratio=0.9,), theme_latexfonts())

fig_sf = with_theme(theme_sf) do
Expand All @@ -101,6 +101,8 @@ function plotsf(binsf1::binned_result, binsf2::binned_result; fitsf1=[], fitsf2=
yscale=log10,
xticks = LogTicks(IntegerTicks()),
yticks = LogTicks(IntegerTicks()),
yminorticks=IntervalsBetween(9),
xminorticks=IntervalsBetween(9),
xticksize=8,
yticksize=8,
xticksmirrored = true, yticksmirrored = true,
Expand All @@ -125,7 +127,53 @@ function plotsf(binsf1::binned_result, binsf2::binned_result; fitsf1=[], fitsf2=
fig
# resize_to_layout!(fig)
end
save_fig ? savefig(save_fig_path, fig_sf) : println(" ")

return fig_sf
end


function plotcv(bincv::binned_result; mode="flux", proper_time=[],save_fig_path::String="./fig/plot_cv.svg", save_fig::Bool=true)

theme_cv = merge(theme_web(width=350, colors=MakiePublication.tableau_10(),linestyles=[nothing, :dash, :dash], ishollowmarkers=[true, true, false], markers=[:circle, :diamond, :rtriangle], linecycle=Cycle([:color, :linestyle], covary=true), scattercycle=Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true), markerstrokewidth=0.8, heightwidthratio=0.9,), theme_latexfonts())

mode == "mag" && (ylabel = L"$C_m(\Delta t)$")
mode == "flux" && (ylabel = L"$C_f(\Delta t)$")

fig_cv = with_theme(theme_cv) do
fig = Figure()

ax = Axis(fig[1, 1],
xlabel=L"$\Delta t$ [sec]",
ylabel=ylabel,
xscale=log10,
xticks = LogTicks(IntegerTicks()),
# yticks = 0.5:0.1:1.1,
yminorticks=IntervalsBetween(9),
xminorticks=IntervalsBetween(9),
xticksize=8,
yticksize=8,
xticksmirrored = true, yticksmirrored = true,
)

s = scatter!(ax, 10 .^ bincv.x, bincv.y)


e = errorbars!(ax, 10 .^ bincv.x, bincv.y, bincv.yerr, bincv.yerr, linewidth=0.5, whiskerwidth = 0.2)

isempty(proper_time) ? print(" ") : band!(ax, 10 ^ proper_time[1]:10 ^ proper_time[2], 0.5, 1.1, color= (:red, 0.1))
# hspan!(-1.1, -0.9, color = (:blue, 0.5))

savefig("./fig/plot_sf.pdf", fig_sf)
ylims!(0.5, 1.1)
# ylims!(4e-3, 2e-1)
xlims!(80, 3e4)

fig
# resize_to_layout!(fig)
end

save_fig ? savefig(save_fig_path, fig_cv) : println(" ")

return fig_cv

end
Loading

0 comments on commit d456ce7

Please sign in to comment.