Skip to content

Commit

Permalink
Implemented image compression via JPEG-LS
Browse files Browse the repository at this point in the history
  • Loading branch information
jmason86 committed Nov 21, 2023
1 parent 8f0b8ae commit 809c718
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ dependencies:
- netCDF4=1.6.0
- h5netcdf=1.1.0
- bottleneck=1.3.7
- pillow-jpls=1.2.0

prefix: ~/anaconda3
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ seaborn==0.11
xarray==2022.6.0
netCDF4==1.6.0
h5netcdf==1.1.0
bottleneck==1.3.7
bottleneck==1.3.7
pillow-jpls==1.2.0
6 changes: 4 additions & 2 deletions suncet_instrument_simulator/config_files/config_default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ apply_psf = True
apply_scattered_light_psf = False
# Subtract a dark frame with onboard software
subtract_dark_onboard = True
# Compress images or not (uses JPEG-LS)
compress_image = True
# Select timesteps to work on [first, last, step]
timesteps_to_process = [1, 500, 1]
# Directory name for simulator run
model_directory_name = /mhd/bright_fast/
# Director for EM Maps
model_directory_name = /mhd/bright_fast/ # TODO: Move these to the "structure" section
# Directory for EM Maps
em_directory_name = /em_maps/
# Directory name for saved maps
map_directory_name = /rendered_euv_maps/
Expand Down
1 change: 1 addition & 0 deletions suncet_instrument_simulator/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, filename):
self.apply_psf = config['behavior'].getboolean('apply_psf')
self.apply_scattered_light_psf = config['behavior'].getboolean('apply_scattered_light_psf')
self.subtract_dark = config['behavior'].getboolean('subtract_dark_onboard')
self.compress_image = config['behavior'].getboolean('compress_image')
self.timesteps_to_process = json.loads(config.get('behavior', 'timesteps_to_process'))
self.model_directory_name = config['behavior']['model_directory_name']
self.em_directory_name = config['behavior']['em_directory_name']
Expand Down
21 changes: 21 additions & 0 deletions suncet_instrument_simulator/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from astropy.coordinates import SkyCoord
from astropy import constants as const
import sunpy.map
from pillow_jpls import Image
from sunpy.coordinates import frames
from suncet_instrument_simulator import config_parser # This is just for running as a script -- should delete when done testing

Expand Down Expand Up @@ -451,6 +452,26 @@ def bin_image(self, onboard_processed_images, xbin=None, ybin=None):
onboard_processed_images.meta['cdelt2'] = self.config.plate_scale.value * ybin # Note 2: there is also risk here because a) the user must be responsible in the config file to ensure the image_dimensions and plate_scale are compatible, and b) the units they input for plate_scale must be the same as those already in the map

return onboard_processed_images

def compress_image(self, onboard_processed_images):
normalized_data = (onboard_processed_images.data - np.min(onboard_processed_images.data)) / (np.max(onboard_processed_images.data) - np.min(onboard_processed_images.data))
max_value = 2**self.config.readout_bits.value - 1

if self.config.readout_bits <= (8 * u.bit):
dtype = np.uint8
mode = 'L'
elif self.config.readout_bits <= (16 * u.bit): # if readout_bits is, e.g., 12 or 14, we've scaling accordingly and just won't use the excess bits in these standard numpy containers (8, 16, 32)
dtype = np.uint16
mode = 'I;16'
elif self.config.readout_bits <= (32 * u.bit):
dtype = np.uint32
mode = 'I'
else:
raise ValueError("Unsupported bit depth")

scaled_data = (normalized_data * max_value).astype(dtype)
image = Image.fromarray(scaled_data, mode=mode)
return sunpy.map.Map(np.array(image), onboard_processed_images.meta)



Expand Down
2 changes: 2 additions & 0 deletions suncet_instrument_simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def __apply_camera_software(self):
self.onboard_processed_images = self.onboard_software.filter_out_particle_hits(self.onboard_processed_images)
self.onboard_processed_images = self.onboard_software.create_composite(self.onboard_processed_images)
self.onboard_processed_images = self.onboard_software.bin_image(self.onboard_processed_images)
if self.config.compress_image:
self.onboard_processed_images = self.onboard_software.compress_image(self.onboard_processed_images)


def __calculate_snr(self):
Expand Down

0 comments on commit 809c718

Please sign in to comment.