pycnic / pysimkernel

A Python package to control parameter scans and iterations for computational experiments
ISC License
1 stars 2 forks source link

pytemper user story #33

Open andsor opened 8 years ago

andsor commented 8 years ago
import simkernel as simk
import pytemper

def single_run_statistics(rho, seed, ts, return_period_generator, generator_options):
    """
    The following is generic code that can go into the pytemper package
    """
    t_max = max(ts)

    # get the return periods from the given stochastic system at hand
    return_periods_gen = return_period_generator(
        rho=rho, seed=seed, t_max=t_max,
        **generator_options
    )
    return_periods = list(return_periods_gen)

    # compute and return the temporal percolation cluster statistics
    return pytemper.singlerun.statistics(ts=ts, return_periods=return_periods)

# this is also generic and fits into the pytemper package
xp = simk.Experiment(
    single_run_statistics
).aggregate(
    # this aggregates before even specifying seed input -- delayed to upper layer / calls
    'seed', pytemper.single_rho_statistics
)

res = xp(
    rho=np.linspace(0, 1),
    seed=range(100),
    ts=simk.noit(np.logspace(0, 6).astype(int)),  # noit: to take the argument as one literal list, do not iterate!
    return_period_generator=simk.noit(...),  # actual simulation!
    generator_options=dict(...),  # further simulation options
)

I am still not so sure about the output. Is it clear that we can use an ndarray here. Or should it be in table format. Or dictionary access? pandas dataframe? res[rho]?