Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots of steady-state experiments #23

Open
DeepaMahm opened this issue Jun 23, 2022 · 3 comments
Open

Plots of steady-state experiments #23

DeepaMahm opened this issue Jun 23, 2022 · 3 comments

Comments

@DeepaMahm
Copy link

Hello @fbergmann ,

I tried to make a few changes in the function def plot_per_dependent_variable to create plots for the steady-state data and
I would like to share the modified function (please see below) with you.

Thanks so much for the new release, this helps me a lot in obtaining the steady-state data in the required format.

def plot_per_dependent_variable_ss(**kwargs):
    """
    This function creates a figure for each dependent variable, with traces for all experiments.

    :param kwargs:

    - | `model`: to specify the data model to be used (if not specified
      | the one from :func:`.get_current_model` will be taken)

    :return: array of tuples (fig, ax) for each figure created
    """
    dm = model_io.get_model_from_dict_or_default(kwargs)

    task = dm.getTask(TASK_PARAMETER_ESTIMATION)
    assert (isinstance(task, COPASI.CFitTask))

    problem = task.getProblem()
    assert (isinstance(problem, COPASI.CFitProblem))

    experiments = problem.getExperimentSet()
    assert (isinstance(experiments, COPASI.CExperimentSet))

    result = []
    num_experiments = experiments.getExperimentCount()
    if num_experiments == 0:
        return result

    data = get_simulation_results(**kwargs)
    exp_data = data[0]  # experimental data
    sim_data = data[1]  # simulation data

    dependent_variables = {}

    for i in range(num_experiments):
        experiment = experiments.getExperiment(i)
        mapping = get_experiment_mapping(experiment)

        # set independent values for that experiment
        independent = mapping[mapping.type == 'independent']
        xname = independent.iloc[0].mapping

        # set dependent values for that experiment
        dependent = mapping[mapping.type == 'dependent']
        num_dependent = dependent.shape[0]
        for j in range(num_dependent):
            name = dependent.iloc[j].mapping
            if name not in dependent_variables:
                dependent_variables[name] = []
            dependent_variables[name].append(i)

    for dependent in dependent_variables:
        fig, ax = plt.subplots()
        cycler = plt.cycler("color", plt.cm.tab20c.colors)()
        ax.set_title(dependent)
        experiment_indices = dependent_variables[dependent]

        for i in experiment_indices:
            experiment = experiments.getExperiment(i)
            exp_name = experiment.getObjectName()
            nextval = next(cycler)['color']
            name = dependent
            if name not in sim_data[i].columns:
                name = name[1:-1]

            sim_data[i][xname] = exp_data[i][xname]
            # print(sim_data[i])

            sim_data[i].reset_index().plot(x=xname, y=name,
                                           label="{0} Fit".format(exp_name), ax=ax, color=nextval)
            exp_data[i].plot.scatter(x=xname, y=dependent, ax=ax, color=nextval,
                                     label='{0} Measured'.format(exp_name))
        # plt.savefig('ss.png')
        result.append((fig, ax))

    return result

@fbergmann
Copy link
Member

thank you so very much for this submission!

@fbergmann
Copy link
Member

I'll leave this open for now, as i need to find a way to make this work:

  • with time courses
  • with steady state data that has no independent data

i'll make commits onto this issue as i make progress.

@fbergmann fbergmann reopened this Jun 24, 2022
@DeepaMahm
Copy link
Author

Hi @fbergmann ,

I would like to suggest one more use case
i.e steady state data with multiple independent data.

I look forward to use these implementations.

Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants