IO (Read/Write)#
synpivimage lets you store your metadata and generated data. Either all is stored in a single HDF5 file or images in a TIG file and metadata in a JSON-LD files. Both provide sufficient and transparent information about the generation process as the parameters are linked to persistent identifiers.
import synpivimage
Write Metadata#
Create sample camera and laser
cam = synpivimage.Camera(
nx=128,
ny=128,
bit_depth=16,
qe=1,
sensitivity=1,
baseline_noise=0,
dark_noise=0,
shot_noise=False,
fill_ratio_x=1.0,
fill_ratio_y=1.0,
particle_image_diameter=1.0
)
gauss_laser = synpivimage.Laser(
width=1.4,
shape_factor=2
)
Save to JSON-LD#
Call save_jsonld:
cam_filename = cam.save_jsonld('cam.json')
gauss_laser_filename = gauss_laser.save_jsonld('laser.json')
Load from JSON-LD#
To load the components, we from_jsonld of the Ontology class LaserModel. This will generate an object as defined in the ontology. Base on this ontology, we know how to find the parameters (laser shape factor etc.):
from pivmetalib.pivmeta import LaserModel
from ontolutils.namespacelib import PIVMETA
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[4], line 1
----> 1 from pivmetalib.pivmeta import LaserModel
2 from ontolutils.namespacelib import PIVMETA
ImportError: cannot import name 'LaserModel' from 'pivmetalib.pivmeta' (/home/docs/checkouts/readthedocs.org/user_builds/synpivimage/envs/latest/lib/python3.8/site-packages/pivmetalib/pivmeta/__init__.py)
loaded_laser = LaserModel.from_jsonld(gauss_laser_filename)[0]
for param in loaded_laser.hasParameter:
if str(param.hasStandardName) == str(PIVMETA.model_laser_sheet_shape_factor):
lst = param.hasNumericalValue
if str(param.hasStandardName) == str(PIVMETA.model_laser_sheet_shape_factor):
lsf = param.hasNumericalValue
lst, lsf
(2, 2)
Now we can instantiate a new laser class with the synpivimage package:
loaded_gauss_laser = synpivimage.Laser(
width=lst,
shape_factor=lsf
)
loaded_gauss_laser
Laser(shape_factor=2, width=2.0)
Write Data#
Writing data means writing images and metadata together. This has been shown in the single image section and the double image section, too.