Skip to content

Commit

Permalink
Simulator fully supports scattering by filter mesh and mirrors — but …
Browse files Browse the repository at this point in the history
…more work is required
  • Loading branch information
danseaton committed May 10, 2024
1 parent 155a1da commit cbbc6e2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
11 changes: 6 additions & 5 deletions suncet_instrument_simulator/config_files/config_default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Take MHD emission measure maps and compute new radiance maps from them (True); else loads existing ones from disk
compute_new_radiance_maps = False
# Convolve the image with modeled diffraction due to filter mesh, expressed as another point spread function
apply_mesh_diffraction = False
apply_mesh_diffraction = True
# Convolve the image with scattered light modeled inside the telescope, expressed as another point spread function
apply_mirror_scattered_light_psf = True
# Include spikes due to particle hits on the detector (see spike_rate below to control frequency)
Expand All @@ -12,11 +12,11 @@ subtract_dark_onboard = True
# Compress images or not (uses JPEG-LS)
compress_image = False
# Select timesteps to work on [first, last, step]
timesteps_to_process = [300, 500, 1]
timesteps_to_process = [300, 301, 1]
# Set window size over which to calculate SNR (pixels) - should be an odd number
SNR_window = 3
# Directory name for simulator run # TODO: Move these to the "structure" section
model_directory_name = /mhd/dimmest/
model_directory_name = /mhd/bright_fast/
# Directory for EM Maps
em_directory_name = /em_maps/
# Directory name for saved maps
Expand All @@ -41,7 +41,8 @@ fov = [2.67, 2.0]
mirror_coating_reflectivity_filename = b4c_rigaku_surrogate_measurement.csv
filter_entrance_transmission_filename = filter_entrance_transmission.csv
filter_focal_plane_transmission_filename = filter_focal_plane_transmission.csv
mirror_scatter_filename = SunCet_PSF_0SolarRad_s13.5A_185A_Normalized.fits
mirror_scatter_filename = suncet_mirror_scatter_psf.fits
filter_diffraction_filename = suncet_diffraction_patterns_2k.fits

[detector]
# [cm2]
Expand Down Expand Up @@ -95,4 +96,4 @@ jitter = 0.6372
# the 'vanilla' metadata file for the mission, relevant parameters will be overwritten for output files
base_metadata_filename = suncet_metadata_definition_v1.0.1.csv
# the folder that contains the model data to ingest, which must be a subfolder within the os.getenv('suncet_data') folder
model_data_folder = /mhd/dimmest/
model_data_folder = /mhd/bright_fast/
1 change: 1 addition & 0 deletions suncet_instrument_simulator/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, filename):
self.filter_entrance_transmission_filename = config['telescope']['filter_entrance_transmission_filename']
self.filter_focal_plane_transmission_filename = config['telescope']['filter_focal_plane_transmission_filename']
self.mirror_scatter_filename = config['telescope']['mirror_scatter_filename']
self.filter_diffraction_filename = config['telescope']['filter_diffraction_filename']

# detector
self.detector_physical_area = config['detector'].getfloat('detector_physical_area') * u.cm**2
Expand Down
34 changes: 21 additions & 13 deletions suncet_instrument_simulator/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@ def __init__(self, config):


def __get_coating_name(self):
return os.path.basename(self.config.mirror_coating_reflectivity_filename).split('_1')[0]

return os.path.basename(self.config.mirror_coating_reflectivity_filename).split('_1')[0]

def __load_mirror_scatter_psf(self):
filename = self.config.mirror_scatter_filename
psf = fits.open(os.getenv('suncet_data') + '/psf_data/' + filename)[0].data
psf_crop = psf[2:-1, 2:-1] # because convolve_fft requires us to have an odd number of rows
psf_norm = psf_crop/np.sum(psf_crop)

return psf_norm
full_path = os.getenv('suncet_data') + '/mirror_scatter/' + filename
psf = fits.open(full_path)[0].data
psf_crop = psf[0:-1, 0:-1] # because convolve_fft requires us to have an odd number of rows
return psf_crop


def __load_mesh_diffraction_psf(self):
# TODO: implement load_mesh_diffraction
pass

filename = self.config.filter_diffraction_filename
full_path = os.getenv('suncet_data') + '/filter_mesh_diffraction/' + filename
diffraction_psf = fits.open(full_path)
return diffraction_psf

def store_target_wavelengths(self, radiance_maps): # Will interpolate/calculate any subsequent wavelength-dependent quantities to this "target" wavelength array
if self.__is_nested_time_and_wavelength(radiance_maps):
Expand Down Expand Up @@ -149,15 +148,24 @@ def convert_steradians_to_pixels(self, radiance_maps):
pixel_area_steradians = (plate_scale_rad**2).to(u.steradian / (u.pix**2))
return self.__apply_function_to_leaves(radiance_maps, lambda x: x * pixel_area_steradians)

def apply_diffraction_psf(self, radiance_maps):
return self.__apply_function_to_leaves(radiance_maps, self.__convolve_diffraction_psf)

def __convolve_diffraction_psf(self, map):
# todo: fix the bad hack to find the correct diffraction pattern
target_psf = self.mesh_diffraction_psf[int(map.meta['wavelnth']) - 170].data
target_psf_crop = target_psf[0:-1, 0:-1]
convolved_data = convolve_fft(map.data, target_psf_crop)
return sunpy.map.Map(convolved_data, map.meta)

def apply_mirror_scattered_light_psf(self, radiance_maps):
return self.__apply_function_to_leaves(radiance_maps, self.__convolve_mirror_scatter)


def __convolve_mirror_scatter(self, map):
convolved_data = convolve_fft(map.data, self.mirror_scatter_psf)
background = convolve_fft(map.data, self.mirror_scatter_psf)
eta = np.sum(self.mirror_scatter_psf)
convolved_data = map.data * (1 - eta) + background
return sunpy.map.Map(convolved_data, map.meta)


def apply_effective_area(self, radiance_maps):
'''
Expand Down
8 changes: 4 additions & 4 deletions suncet_instrument_simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def __sun_to_detector(self):
self.radiance_maps = self.hardware.extract_fov(self.radiance_maps)
self.radiance_maps = self.hardware.interpolate_spatial_resolution(self.radiance_maps)
self.radiance_maps = self.hardware.convert_steradians_to_pixels(self.radiance_maps)
if self.config.apply_psf:
self.radiance_maps = self.hardware.apply_psf(self.radiance_maps)
if self.config.apply_scattered_light_psf:
self.radiance_maps = self.hardware.apply_scattered_light_psf(self.radiance_maps)
if self.config.apply_mesh_diffraction:
self.radiance_maps = self.hardware.apply_diffraction_psf(self.radiance_maps)
if self.config.apply_mirror_scattered_light_psf:
self.radiance_maps = self.hardware.apply_mirror_scattered_light_psf(self.radiance_maps)
self.radiance_maps = self.hardware.apply_effective_area(self.radiance_maps)
self.radiance_maps = self.hardware.apply_exposure_times(self.radiance_maps)

Expand Down

0 comments on commit cbbc6e2

Please sign in to comment.