Skip to content

Remove OTBObject

Vincent Delbar requested to merge interface into release-1.6

This was quite simple starting from your branch and I'm happy with the result. Now it finally make sense to use abstract base class...with abstract methods write and key_image_output.
Initially -20 lines for code, just by moving all image and numpy related code to RasterInterface. I kept App.__init__ as it was in my previous MR, since your changes with the "name" attr provoked undesired side effects on the pipeline tests.

Also made small improvements in type hints and exceptions not raised properly, and :

  • Make App internal attributes all_param_types and out_param_types private
  • Slicer functions name (renamed create_one_input_fake_exp and create_fake_exp to something more explicit)
  • Now raise attribute error if trying to access app["unknown key"] (see commit )
  • Print warning if writing to an already existing file path

Edit : with latest small commits the diff is now +356 -421 =)
If you approve I think we should merge and squash your MR first (because of duplicated commit messages) then merge this one without squash (there are several commits that we should keep apart).
P.S. : I won't go to the office tomorrow

classDiagram
  class ABC{
    AbstactBaseClass
  }
  class App {
    _all_param_types
    _out_param_types
    _time_end : int
    _time_start : int
    app
    data
    elapsed_time
    exports_dic : dict
    frozen : bool
    image_dic : NoneType
    key_input
    key_input_image
    key_output_image
    name : str
    parameters : dict
    parameters_keys : tuple
    quiet : bool
    used_outputs
    execute()
    find_outputs() tuple[str]
    flush()
    get_first_key(param_types: list[int]) str
    propagate_dtype(target_key: str, dtype: int)
    save_objects()
    set_parameters()
    summarize() dict[str, str | dict[str, Any]]
    write()
  }
  class Input {
    name
    path : str
  }
  class LogicalOperation {
    logical_exp : str
    logical_exp_bands : list
    build_fake_expressions(operator: str, inputs: list[App | str | int | float], nb_bands: int)
  }
  class OTBTFApp {
    set_nb_sources()
  }
  class Operation {
    exp : str
    exp_bands : list
    fake_exp_bands : list
    im_count : int
    im_dic : dict
    inputs : list
    logical_fake_exp_bands : list
    name
    nb_channels : dict
    operator : str
    unique_inputs
    build_fake_expressions(operator: str, inputs: list[App | str | int | float], nb_bands: int)
    get_real_exp(fake_exp_bands: str) tuple[list[str], str]
    make_fake_exp(x: App | str, band: int, keep_logical: bool) tuple[str, list[App], int]
  }
  class Output {
    app
    filepath : NoneType, Path
    key_output_image
    name
    param_key : Optional[str]
    parent_pyotb_app
    exists() bool
    make_parent_dirs()
    write(filepath: None | str | Path)
  }
  class RasterInterface {
    app
    dtype
    exports_dic : dict
    key_output_image
    metadata
    shape
    transform
    channels_list_from_slice(bands: int) list[int]
    export(key: str, preserve_dtype: bool) dict[str, dict[str, np.ndarray]]
    get_infos() dict[str, (str, float, list[float])]
    get_statistics() dict[str, (str, float, list[float])]
    read_values_at_coords(row: int, col: int, bands: int) list[int | float] | int | float
    to_numpy(key: str, preserve_dtype: bool, copy: bool) np.ndarray
    to_rasterio() tuple[np.ndarray, dict[str, Any]]
    write()
    xy_to_rowcol(x: float, y: float) tuple[int, int]
  }
  class Slicer {
    cols
    input
    name : str
    one_band_sliced
    rows
  }
  RasterInterface --|> ABC
  OTBTFApp --|> App
  App --|> RasterInterface
  Input --|> App
  LogicalOperation --|> Operation
  Operation --|> App
  Output --|> RasterInterface
  Slicer --|> App
  App --* Output : parent_app
``
Edited by Vincent Delbar

Merge request reports

Loading