-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
9 changed files
with
135 additions
and
22 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,57 @@ | ||
<common> | ||
|
||
<dust_component> "input/dust_nk/silicate_d03.nk" "plaw" 1.0 3800.0 1e-06 1e-06 -3.5 | ||
<phase_function> PH_MIE | ||
|
||
<mass_fraction> 0.01 | ||
|
||
<nr_threads> -1 | ||
|
||
</common> | ||
|
||
<task> 1 | ||
|
||
<cmd> CMD_DUST_EMISSION | ||
|
||
<detector_dust nr_pixel = "255*255"> 1e-6 1e-3 4 1 0.0 0.0 4.32e+18 | ||
|
||
<max_subpixel_lvl> 2 | ||
|
||
<path_grid> "projects/test/raytracing_scattering/grid_3D_sphere_const_T_m1e-5.dat" | ||
<path_out> "projects/test/raytracing_scattering/dust/" | ||
|
||
</task> | ||
|
||
<task> 1 | ||
|
||
<cmd> CMD_DUST_EMISSION | ||
|
||
<detector_dust nr_pixel = "255*255"> 1e-6 1e-3 4 1 0.0 0.0 4.32e+18 | ||
|
||
<source_star nr_photons = "1e6"> 0 0 0 2 4500 | ||
|
||
<max_subpixel_lvl> 2 | ||
|
||
<rt_scattering> 1 | ||
|
||
<path_grid> "projects/test/raytracing_scattering/grid_3D_sphere_const_T_m1e-5.dat" | ||
<path_out> "projects/test/raytracing_scattering/dust_rt/" | ||
|
||
</task> | ||
|
||
<task> 1 | ||
|
||
<cmd> CMD_DUST_SCATTERING | ||
|
||
<detector_dust_mc nr_pixel = "255*255"> 1e-6 1e-3 4 0.00 0.00 4.32e+18 | ||
|
||
<source_star nr_photons = "1e6"> 0 0 0 2 4500 | ||
<source_dust nr_photons = "2.1e6"> | ||
|
||
<path_grid> "projects/test/raytracing_scattering/grid_3D_sphere_const_T_m1e-5.dat" | ||
<path_out> "projects/test/raytracing_scattering/dust_mc/" | ||
|
||
<peel_off> 1 | ||
<enfsca> 1 | ||
|
||
</task> |
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,65 @@ | ||
from astropy.io import fits | ||
from astropy import units as u | ||
import numpy as np | ||
|
||
|
||
""" | ||
---------------------------------------------- | ||
Raytracing and scattering | ||
---------------------------------------------- | ||
Test whether scattering in a dust simulation | ||
(from radiation field) looks the same as | ||
scattering in a dust_mc simulation. | ||
In order to pass this test, all detectors | ||
(with different orientations) have to yield | ||
the same stellar + scattered + emitted flux | ||
for each wavelength. | ||
(Should get better with more photons) | ||
""" | ||
|
||
|
||
def read_data(sed_fits_file): | ||
fits_header = fits.getheader(sed_fits_file) | ||
fits_data = fits.getdata(sed_fits_file) | ||
|
||
nr_wave = np.shape(fits_data)[2] | ||
sed_wavelengths = np.zeros(nr_wave) * u.m | ||
for i_wave in range(nr_wave): | ||
sed_wavelengths[i_wave] = float(fits_header[f'HIERARCH WAVELENGTH{i_wave+1}']) * u.m | ||
|
||
_stokes = ['I', 'Q', 'U', 'V'] | ||
sed_data = {} | ||
for i_s, i_stokes in enumerate(_stokes): | ||
sed_data[i_stokes] = fits_data[i_s,0,:] * u.Jy | ||
|
||
return sed_data | ||
|
||
|
||
def compare(): | ||
dust_sed_data = read_data('projects/test/raytracing_scattering/dust/data/polaris_detector_nr0001_sed.fits.gz') | ||
dust_rt_sed_data = read_data('projects/test/raytracing_scattering/dust_rt/data/polaris_detector_nr0001_sed.fits.gz') | ||
dust_mc_sed_data = read_data('projects/test/raytracing_scattering/dust_mc/data/polaris_detector_nr0001_sed.fits.gz') | ||
|
||
max_rel_diff = np.max(np.abs( (dust_sed_data['I'] + dust_mc_sed_data['I']) / dust_rt_sed_data['I'] - 1.0 )) | ||
if max_rel_diff > 1e-1: | ||
raise Exception(f'Test failed: Stokes I does not match (max. relative difference = {max_rel_diff})') | ||
|
||
mc_polarization = np.sqrt(dust_mc_sed_data['Q']**2 + dust_mc_sed_data['U']**2 + dust_mc_sed_data['V']**2) / (dust_mc_sed_data['I'] + dust_sed_data['I']) | ||
rt_polarization = np.sqrt(dust_rt_sed_data['Q']**2 + dust_rt_sed_data['U']**2 + dust_rt_sed_data['V']**2) / dust_rt_sed_data['I'] | ||
max_abs_diff = np.max(np.abs( mc_polarization - rt_polarization )) | ||
if max_abs_diff > 1e-2: | ||
raise Exception(f'Test failed: Polarization does not match (max. absolute difference = {max_abs_diff})') | ||
|
||
max_polarization = np.max(mc_polarization) | ||
if max_polarization > 1e-2: | ||
raise Exception(f'Test failed: Polarization is too large (max. value = {max_polarization})') | ||
|
||
return True | ||
|
||
|
||
if __name__ == '__main__': | ||
res = compare() | ||
if res: | ||
print('Test passed') |
Binary file not shown.
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 |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
|
||
<mass_fraction> 0.01 | ||
|
||
<write_dust_files> 1 | ||
|
||
<nr_threads> -1 | ||
|
||
</common> | ||
|
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
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 |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
|
||
<mass_fraction> 0.01 | ||
|
||
<write_dust_files> 1 | ||
|
||
<nr_threads> -1 | ||
|
||
</common> | ||
|
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
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 |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
|
||
<mass_fraction> 0.01 | ||
|
||
<write_dust_files> 1 | ||
|
||
<nr_threads> -1 | ||
|
||
</common> | ||
|
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