Example #1
0
def create_params(input_info_solver):
    """Create a Parameters instance from an InfoSolverBase instance."""
    if isinstance(input_info_solver, InfoSolverBase):
        info_solver = input_info_solver
    elif hasattr(input_info_solver, "Simul"):
        info_solver = input_info_solver.Simul.create_default_params()
    else:
        raise ValueError("Can not create params from input input_info_solver.")

    params = Parameters(tag="params")
    dict_classes = info_solver.import_classes()

    dict_classes["Solver"] = import_class(info_solver.module_name,
                                          info_solver.class_name)

    for Class in list(dict_classes.values()):
        if hasattr(Class, "_complete_params_with_default"):
            try:
                Class._complete_params_with_default(params)
            except TypeError:
                try:
                    Class._complete_params_with_default(params, info_solver)
                except TypeError as e:
                    e.args += ("for class: " + repr(Class), )
                    raise

    return params
Example #2
0
def main():

    reset_logger()
    config_logging("info")

    args = parse_args()

    path_instructions_xml = args.path
    logger.info(
        "\nFrom Python, start with instructions in xml file:\n%s",
        path_instructions_xml,
    )

    params = ParamContainer(path_file=path_instructions_xml)

    program = None

    try:
        params.Action.ActionName
    except AttributeError:
        pass
    else:
        program = "uvmat"

    try:
        program = params._value_text["program"]
    except (AttributeError, KeyError):
        pass

    if program not in programs:
        raise ValueError("Can not detect the program to launch.")

    print(args)

    print(f"using input file from {program}")

    if program == "uvmat":
        tidy_uvmat_instructions(params)
        action_name = params.action.action_name
        logger.info(
            'Check if the action "%s" is implemented by FluidImage', action_name
        )
        if action_name not in actions_classes.keys():
            raise NotImplementedError(
                'action "' + action_name + '" is not yet implemented.'
            )

        cls = actions_classes[action_name]
        action = cls(params, args)

    elif program == "fluidimage":
        cls = import_class(
            params._value_text["module"], params._value_text["class"]
        )
        modif_fluidimage_params(params, args)
        action = cls(params)

    return action.compute()
Example #3
0
def init_im2im_function(im2im=None, args_init=()):
    """Initialize the filter function."""

    if isinstance(im2im, str):
        str_package, str_obj = im2im.rsplit(".", 1)
        im2im = import_class(str_package, str_obj)

    if isinstance(im2im, types.FunctionType):
        obj = im2im
        im2im_func = im2im
    elif isinstance(im2im, type):
        print("in init_im2im", args_init)
        obj = im2im(*args_init)
        im2im_func = obj.calcul

    return obj, im2im_func
Example #4
0
    def import_classes(self):
        """Import the classes and return a dictionary."""
        dict_classes = {}
        tags = self.classes._tag_children
        if len(tags) == 0:
            return dict_classes

        for tag in tags:
            cls = self.classes.__dict__[tag]
            try:
                module_name = cls.module_name
                class_name = cls.class_name
            except AttributeError:
                pass
            else:
                Class = import_class(module_name, class_name)
                dict_classes[cls._tag] = Class

        return dict_classes