Ugly code and parameters roles/types
The following code is ugly:
@property
def data(self) -> dict[str, float, list[float]]:
"""Expose app's output data values in a dictionary."""
known_bad_keys = ("ram", "elev.default", "mapproj.utm.zone", "mapproj.utm.northhem")
skip_keys = known_bad_keys + tuple(self._out_param_types) + tuple(self.parameters)
data_dict = {}
for key in filter(lambda k: k not in skip_keys, self.parameters_keys):
value = self.__dict__.get(key)
if not isinstance(value, otb.ApplicationProxy) and value not in (None, "", [], ()):
data_dict[str(key)] = value
return data_dict
Could be use GetParameterRole()
to determine if the parameter is intended for output?
pyotb.Smoothing(...).app.GetParameterRole("ram") # 0
pyotb.Smoothing(...).app.GetParameterRole("in") # 0
pyotb.OrthoRectification(...).app.GetParameterRole("elev.default") # 0
pyotb.ReadImageInfo(...).app.GetParameterRole("spacingx") # 1
pyotb.ExtractROI(...).app.GetParameterRole("out") # 1
Additionally, we should use GetParameterTypes()
to avoid processing wrong params.
# Types returned from GetParameterTypes()
types = {
otbApplication.ParameterType_Int : "otbApplication.ParameterType_Int",
otbApplication.ParameterType_Float : "otbApplication.ParameterType_Float",
otbApplication.ParameterType_Double : "otbApplication.ParameterType_Double",
otbApplication.ParameterType_String : "otbApplication.ParameterType_String",
otbApplication.ParameterType_StringList : "otbApplication.ParameterType_StringList",
otbApplication.ParameterType_InputFilename : "otbApplication.ParameterType_InputFilename",
otbApplication.ParameterType_InputFilenameList : "otbApplication.ParameterType_InputFilenameList",
otbApplication.ParameterType_OutputFilename : "otbApplication.ParameterType_OutputFilename",
otbApplication.ParameterType_Directory : "otbApplication.ParameterType_Directory",
otbApplication.ParameterType_Choice : "otbApplication.ParameterType_Choice",
otbApplication.ParameterType_InputImage : "otbApplication.ParameterType_InputImage",
otbApplication.ParameterType_InputImageList : "otbApplication.ParameterType_InputImageList",
otbApplication.ParameterType_InputVectorData : "otbApplication.ParameterType_InputVectorData",
otbApplication.ParameterType_InputVectorDataList : "otbApplication.ParameterType_InputVectorDataList",
otbApplication.ParameterType_OutputImage : "otbApplication.ParameterType_OutputImage",
otbApplication.ParameterType_OutputVectorData : "otbApplication.ParameterType_OutputVectorData",
otbApplication.ParameterType_Radius : "otbApplication.ParameterType_Radius",
otbApplication.ParameterType_Group : "otbApplication.ParameterType_Group",
otbApplication.ParameterType_ListView : "otbApplication.ParameterType_ListView",
otbApplication.ParameterType_RAM : "otbApplication.ParameterType_RAM",
otbApplication.ParameterType_Bool : "otbApplication.ParameterType_Bool",
otbApplication.ParameterType_Field : "otbApplication.ParameterType_Field",
otbApplication.ParameterType_Band : "otbApplication.ParameterType_Band",
}