Esempio n. 1
0
def setup():
    # %% Load in data, model and parameters
    dataset1 = load_dataset(script_folder.joinpath(DATA_PATH1))
    dataset2 = load_dataset(script_folder.joinpath(DATA_PATH2))
    model = load_model(script_folder.joinpath(MODEL_PATH))
    parameters = load_parameters(script_folder.joinpath(PARAMETERS_FILE_PATH))
    return model, parameters, dataset1, dataset2
Esempio n. 2
0
 def setup(self):
     dataset1 = load_dataset(SCRIPT_DIR / "data/data1.ascii")
     dataset2 = load_dataset(SCRIPT_DIR / "data/data2.ascii")
     model = load_model(str(SCRIPT_DIR / "models/model.yml"))
     parameters = load_parameters(str(SCRIPT_DIR / "models/parameters.yml"))
     self.scheme = Scheme(
         model,
         parameters,
         {
             "dataset1": dataset1,
             "dataset2": dataset2
         },
         maximum_number_function_evaluations=11,
         non_negative_least_squares=True,
         optimization_method="TrustRegionReflection",
     )
Esempio n. 3
0
def load_data(result: DatasetConvertible,
              dataset_name: str | None = None) -> xr.Dataset:
    """Extract a single dataset from a :class:`DatasetConvertible` object.

    Parameters
    ----------
    result : DatasetConvertible
        Result class instance, xarray Dataset or path to a dataset file.
    dataset_name : str, optional
        Name of a specific dataset contained in ``result``, if not provided
        the first dataset will be extracted. Defaults to None.

    Returns
    -------
    xr.Dataset
        Extracted dataset.

    Raises
    ------
    TypeError
        If ``result`` isn't a :class:`DatasetConvertible` object.
    """
    if isinstance(result, xr.Dataset):
        return result
    if isinstance(result, xr.DataArray):
        return result.to_dataset(name="data")
    if isinstance(result, Result):
        if dataset_name is not None:
            return result.data[dataset_name]
        keys = list(result.data)
        return result.data[keys[0]]
    if isinstance(result, (str, Path)):
        return load_data(load_dataset(result))
    raise TypeError(
        f"Result needs to be of type {DatasetConvertible!r}, but was {result!r}."
    )
Esempio n. 4
0
from glotaran.project.scheme import Scheme

DATA_PATH1 = "data/data1.ascii"
DATA_PATH2 = "data/data2.ascii"
MODEL_PATH = "models/model.yml"
PARAMETERS_FILE_PATH = "models/parameters.yml"

# %% Setup necessary (output) paths
results_folder, script_folder = setup_case_study(Path(__file__))
output_folder = results_folder.joinpath("target_analysis")
print(f"- Using folder {output_folder.name} to read/write files for this run")

# %% Load in data, model and parameters
# dataset1 = ExplicitFile(script_folder.joinpath(DATA_PATH1)).read()
# dataset2 = ExplicitFile(script_folder.joinpath(DATA_PATH2)).read()
dataset1 = load_dataset(script_folder.joinpath(DATA_PATH1))
dataset2 = load_dataset(script_folder.joinpath(DATA_PATH2))
model = load_model(script_folder.joinpath(MODEL_PATH))
parameters = load_parameters(script_folder.joinpath(PARAMETERS_FILE_PATH))

# %% Validate model and parameters
print(model.validate(parameters=parameters))

# %% Construct the analysis scheme
scheme = Scheme(
    model,
    parameters,
    {
        "dataset1": dataset1,
        "dataset2": dataset2
    },
Esempio n. 5
0
 def loader(filename):
     return load_dataset(filename, format_name=fmt)