We want to collect datacubes nonstop. Saving is a blocking operation which leaves gaps in the data we save on the order of a few seconds. The larger the datacube, the longer this gap. We really don’t want these gaps, yet we want to save raw data. Saving raw data is extremely demanding (15 s of collect requires 15 s to save perhaps?). Can the saving be done in parallel? The following tries to address this issue.
Saves to a NetCDF file (and RGB representation) to directory dir_path in folder given by date with file name given by UTC time. Save is done in a separate multiprocess.Process.
Generate an RGB image from chosen RGB wavelengths with histogram equalisation or percentile options. The plotting backend can be specified by plot_lib and can be “bokeh” or “matplotlib”. Further customise your plot with **plot_kwargs. quick_imshow is used for saving figures quickly but cannot be used to make interactive plots.
Type
Default
Details
plot_lib
str
bokeh
Plotting backend. This can be ‘bokeh’ or ‘matplotlib’
red_nm
float
640.0
Wavelength in nm to use as the red
green_nm
float
550.0
Wavelength in nm to use as the green
blue_nm
float
470.0
Wavelength in nm to use as the blue
robust
bool
False
Choose to plot using the 2-98% percentile. Robust to outliers
hist_eq
bool
False
Choose to plot using histogram equilisation
quick_imshow
bool
False
Used to skip holoviews and use matplotlib for a static plot
These are exported by openhsi.cameras as SharedXXXCamera This should work just like standard OpenHSI.Camera. Here is an example using SharedSimulatedCamera.
from openhsi.cameras import SharedSimulatedCameraimport tempfileimport osimport timenum_saved =0num2save =3imgs=[]with tempfile.TemporaryDirectory() as temp_dir:print(temp_dir)with SharedSimulatedCamera(img_path="../assets/great_hall_slide.png", n_lines=535, processing_lvl =-1, json_path="../assets/cam_settings.json", cal_path="../assets/cam_calibration.nc", print_settings=False) as cam:for i inrange(num2save):if num_saved >0:#p.join() # waiting for the last process to finish will make this slow. pass cam.collect()print(f"collected from time: {cam.timestamps.data[0]} to {cam.timestamps.data[-1]}") imgs.append(cam.show("bokeh").opts(width=200)) p = cam.save(temp_dir) num_saved +=1 time.sleep(2) # let saving finish before check and cleanupprint(f"finished saving {num2save} datacubes")for root, dirs, files in os.walk(temp_dir):forfilein files: file_path = os.path.join(root, file) relative_path = os.path.relpath(file_path, temp_dir)print(f" {relative_path}")imgs[0]+imgs[1]+imgs[2]
/var/folders/gn/gv16fym50pv5_g7s8gt7451c0000gp/T/tmpr2loh_ou
Allocated 4676.68 MB of RAM.