save

giant.camera_models.camera_model.save(file, name, model, group=None, misalignment=False)[source]

This function is used to save a camera model to a GIANT xml file.

The models are stored as plain text xml trees, where each property is a node of the tree. The root element for the camera models is called CameraModels. You can also optionally specify a group in order to be able to collect similar camera models together.

The xml file stores all information necessary for recreating the camera model when it is loaded from a file. This includes the module that defines the camera model, as well as the name of the class that the camera model was an instance of. When saving the camera model to file, this function first looks to see if a camera model of the same name and group already exists in the file. If it does then that camera model is overwritten with the new values. If it does not, then the current camera model is added to the file.

Camera models are converted into xml using the to_elem() method of the class. This method is defined in the CameraModel class and thus all models that subclass CameraModel (as they should) are usable with this function.

There is an optional keyword argument group which can be used to store the camera model in a sub node of the xml tree. This is mostly just used to organize the save file and allow faster lookup when the file becomes large, but it can also be used to distinguish between multiple camera models with the same name, though this is not recommended.

Finally, there is a misalignment flag which specifies whether you want to save the misalignment values in the file. This should generally be left as false, which resets the misalignment in the model to be a single misalignment of [0, 0, 0] and adjusts the estimation_parameters attribute accordingly. If set to true, then the misalignment is stored exactly as it is in the camera model.

Warning

There is a security risk when loading XML files (exacerbated here by using a eval on some of the field of the xml tree). Do not pass untrusted/unverified files to this function. The files themselves are simple text files that can easily be verified for malicious code by inspecting them in a text editor beforehand.

Parameters:
  • file (Path | str) – The path of the file to store the camera model in

  • name (str) – The name to use to store the camera model (i.e. ‘Navigation Camera’)

  • model (CameraModel) – The instance of the camera model to store. Should be a subclass of CameraModel

  • group (str | None) – An optional group to store the camera model into.

  • misalignment (bool) – A flag specifying whether to include the misalignment values in the save file or not.