Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
palumbom committed May 14, 2024
2 parents 5d82b8a + 54cdc15 commit c15f8d5
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 25 deletions.
13 changes: 10 additions & 3 deletions example_spec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ if case == "EXPRES"
depths = [0.6] # array of line depths
templates = ["FeI_6173"] # template data to use
variability = trues(length(lines)) # whether or not the bisectors should "dance"
#no CB model
#variability = falses
#fixed_bisector = true
#extra_z = 0

blueshifts = zeros(length(lines)) # set convective blueshift value
resolution = 7e5 # spectral resolution

Expand All @@ -168,13 +173,15 @@ if case == "EXPRES"
# actually synthesize the spectra
println(">>> Synthesizing on CPU...")
tstart = time()
lambdas_cpu, outspec_cpu = GRASS.synthesize_spectra_eclipse(spec, disk, obs_long, obs_lat, alt, lines[1]/10.0, time_stamps, verbose=true, use_gpu=false)
lambdas_cpu, outspec_cpu = GRASS.synthesize_spectra_eclipse(spec, disk, obs_long, obs_lat, alt, lines ./ 10.0, time_stamps, verbose=true, use_gpu=false, fixed_bisector=true)
tstop = time()
@printf(">>> Synthesis time --> %.3f seconds \n", tstop - tstart)

#measure velocities
v_grid_cpu, ccf_cpu = GRASS.calc_ccf(lambdas_cpu, outspec_cpu, spec)
rvs_cpu, sigs_cpu = GRASS.calc_rvs_from_ccf(v_grid_cpu, ccf_cpu)

print(rvs_cpu)
end

if case == "Gottingen"
Expand Down Expand Up @@ -213,6 +220,6 @@ if case == "Gottingen"
@printf(">>> Synthesis time --> %.3f seconds \n", tstop - tstart)

#measure velocities
v_grid_cpu, ccf_cpu = GRASS.calc_ccf(lambdas_cpu, outspec_cpu, spec)
rvs_cpu, sigs_cpu = GRASS.calc_rvs_from_ccf(v_grid_cpu, ccf_cpu)
GRASS.calc_ccf(lambdas_cpu, outspec_cpu, spec)
# rvs_cpu, sigs_cpu = GRASS.calc_rvs_from_ccf(v_grid_cpu, ccf_cpu)
end
Binary file added express_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added express_line_fixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 13 additions & 7 deletions src/convenience_eclipse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Synthesize spectra given parameters in `spec` and `disk` instances.
"""
function synthesize_spectra_eclipse(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, obs_long, obs_lat, alt, wavelength, time_stamps;
seed_rng::Bool=false, verbose::Bool=true,
use_gpu::Bool=false, precision::DataType=Float64,
use_gpu::Bool=false, precision::DataType=Float64, fixed_bisector::Bool=false,
skip_times::BitVector=falses(disk.Nt)) where T<:AF
# call appropriate simulation function on cpu or gpu
if use_gpu
return synth_Eclipse_gpu(spec, disk, seed_rng, verbose, precision, skip_times, obs_long, obs_lat, alt, time_stamps, wavelength)
return synth_Eclipse_gpu(spec, disk, seed_rng, verbose, precision, skip_times, obs_long, obs_lat, alt, time_stamps, wavelength, fixed_bisector)
else
return synth_Eclipse_cpu(spec, disk, seed_rng, verbose, skip_times, obs_long, obs_lat, alt, time_stamps, wavelength)
return synth_Eclipse_cpu(spec, disk, seed_rng, verbose, skip_times, obs_long, obs_lat, alt, time_stamps, wavelength, fixed_bisector)
end
end

function synth_Eclipse_cpu(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, seed_rng::Bool,
verbose::Bool, skip_times::BitVector, obs_long, obs_lat, alt, time_stamps, wavelength) where T<:AF
verbose::Bool, skip_times::BitVector, obs_long, obs_lat, alt, time_stamps, wavelength, fixed_bisector::Bool) where T<:AF

# parse out dimensions for memory allocation
N = disk.N
Expand Down Expand Up @@ -51,7 +51,7 @@ function synth_Eclipse_cpu(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, seed
if verbose
println("\t>>> Template: " * splitdir(file)[end])
end
soldata = SolarData(fname=file)
soldata = SolarData(fname=file, fixed_bisector=fixed_bisector)

# re-seed the rng
if seed_rng
Expand All @@ -66,7 +66,7 @@ function synth_Eclipse_cpu(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, seed
end

function synth_Eclipse_gpu(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, seed_rng::Bool,
verbose::Bool, precision::DataType, skip_times::BitVector, obs_long, obs_lat, alt, time_stamps, wavelength) where T<:AF
verbose::Bool, precision::DataType, skip_times::BitVector, obs_long, obs_lat, alt, time_stamps, wavelength, fixed_bisector::Bool) where T<:AF
# make sure there is actually a GPU to use
@assert CUDA.functional()

Expand Down Expand Up @@ -98,9 +98,15 @@ function synth_Eclipse_gpu(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, seed
if verbose
println("\t>>> Template: " * splitdir(file)[end])
end
soldata_cpu = SolarData(fname=file)
soldata_cpu = SolarData(fname=file, fixed_bisector=fixed_bisector)
soldata = GPUSolarData(soldata_cpu, precision=precision)

<<<<<<< HEAD
=======
# # get conv. blueshift and keys from input data
# get_keys_and_cbs_gpu!(gpu_allocs, soldata)

>>>>>>> 54cdc15f7b3705708bc2a47744517551b5599e2d
# run the simulation and multiply flux by this spectrum
disk_sim_eclipse_gpu(spec_temp, disk, soldata, gpu_allocs,
flux, templates, idx,
Expand Down
1 change: 1 addition & 0 deletions src/disk_sim_eclipse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function disk_sim_eclipse(spec::SpecParams{T}, disk::DiskParamsEclipse{T}, solda

# get amount of convective blueshift needed
extra_z = spec.conv_blueshifts[l] - z_cbs_avg
#extra_z = 0.0 # spec.conv_blueshifts[l] - z_cbs_avg

# get shifted line center
λΔD = spec.lines[l]
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/gpu_precomps_eclipse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function calc_eclipse_quantities_gpu!(wavelength, μs, z_rot, ax_codes,

#calculate distance
n2 = CUDA.sqrt(OM_bary[1]^2.0 + OM_bary[2]^2.0 + OM_bary[3]^2.0)
d2 = (OM_bary[1] * OP_bary_x + OM_bary[2] * OP_bary_y + OM_bary[3] * OP_bary_z) / (n2 * n1)
d2 = acos((OM_bary[1] * OP_bary_x + OM_bary[2] * OP_bary_y + OM_bary[3] * OP_bary_z) / (n2 * n1))
if (d2 < atan(moon_radius/n2))
continue
end
Expand Down
9 changes: 2 additions & 7 deletions src/gpu/gpu_sim_eclipse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ function disk_sim_eclipse_gpu(spec::SpecParams{T1}, disk::DiskParamsEclipse{T1},
@cusync @cuda threads=threads1 blocks=blocks1 generate_tloop_gpu!(tloop, dat_idx, lenall_gpu)
end

# plt.imshow(Array(gpu_allocs.ax_codes))
# plt.colorbar()
# plt.show()
# break

# don't synthesize spectrum if skip_times is true, but iterate t index
if skip_times[t]
@cusync @captured @cuda threads=threads1 blocks=blocks1 iterate_tloop_gpu!(tloop, dat_idx, lenall_gpu)
Expand Down Expand Up @@ -113,9 +108,9 @@ function disk_sim_eclipse_gpu(spec::SpecParams{T1}, disk::DiskParamsEclipse{T1},
widall_gpu_loop, allwavs, allints)

# do the line synthesis, interp back onto wavelength grid
# @cusync @cuda threads=threads4 blocks=blocks4 line_profile_gpu!(prof, μs, ld[:,:,l], dA, λs, allwavs, allints)
@cusync @cuda threads=threads4 blocks=blocks4 line_profile_gpu!(prof, μs, ld[:,:,l], dA, λs, allwavs, allints)

@cusync @cuda threads=threads4 blocks=blocks4 line_profile_gpu!(prof, μs, ld, dA, λs, allwavs, allints)
#@cusync @cuda threads=threads4 blocks=blocks4 line_profile_gpu!(prof, μs, ld, dA, λs, allwavs, allints)

# copy data from GPU to CPU
@cusync @cuda threads=threads5 blocks=blocks5 apply_line!(t, prof, flux, sum_wts)
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/gpu_synthesis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ function line_profile_gpu!(prof, μs, ld, dA, λs, allwavs, allints)
# loop over wavelengths
for j in idy:sdy:CUDA.length(λs)
if ((λs[j] < CUDA.first(allwavs_i)) || (λs[j] > CUDA.last(allwavs_i)))
@inbounds CUDA.@atomic prof[j] += dA[m,n] * ld[m,n,1]
@inbounds CUDA.@atomic prof[j] += dA[m,n] * ld[m,n]
else
@inbounds CUDA.@atomic prof[j] += itp(λs[j]) * dA[m,n] * ld[m,n,1]
@inbounds CUDA.@atomic prof[j] += itp(λs[j]) * dA[m,n] * ld[m,n]
end
end
end
Expand Down
11 changes: 6 additions & 5 deletions src/velocities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ function calc_ccf(λs::AA{T1,1}, flux::AA{T1,2},
ccf[i,j] = ccf_plan.allow_nans ? nansum(proj_flux) : sum(proj_flux)
end
end
# print(ccf)

# normalize if normalize==true
if normalize
ccf ./= maximum(ccf)
end
return v_grid, ccf
# # normalize if normalize==true
# if normalize
# ccf ./= maximum(ccf)
# end
# return v_grid, ccf
end

function calc_ccf!(v_grid::AA{T1,1}, projection::AA{T1,2}, proj_flux::AA{T1,1},
Expand Down

0 comments on commit c15f8d5

Please sign in to comment.