import types
import inspect


def get_pytorch_model(module, model_settings):
    """
    Define a DeepSphere-Weather model based on model_settings configs.
    
    The architecture structure must be define in the 'module' custom python file  

    Parameters
    ----------
    module : module
        Imported python module containing the architecture definition.
    model_settings : dict
        Dictionary containing all architecture options.
    """
    if not isinstance(module, types.ModuleType):
        raise TypeError("'module' must be a preimported module with the architecture definition.")
    # - Retrieve the required model arguments
    DeepSphereModelClass = getattr(module, model_settings['architecture_name'])
    fun_args = inspect.getfullargspec(DeepSphereModelClass.__init__).args
    model_args = {k: model_settings[k] for k in model_settings.keys() if k in fun_args}
    # - Define DeepSphere model 
    model = DeepSphereModelClass(**model_args)           
    return model