Effect - Snailz Docs

Skip to content

# Effect

Apply effects to raw data.

## `do_all_effects(params, data)`

Apply effects in order.

Source code in `src/snailz/effect.py`

     6
     7
     8
     9
    10
    11
    12
    def do_all_effects(params, data):
        """Apply effects in order."""

        changes = {"parameters": params.model_dump(mode="json")}
        for effect in (_do_pollution, _do_delay, _do_person, _do_precision):
            changes.update(effect(params, data["grids"], data["persons"], data["samples"]))
        return changes

## `_do_delay(params, grids, persons, samples)`

Modify sample mass based on sampling date.

Source code in `src/snailz/effect.py`

    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    def _do_delay(params, grids, persons, samples):
        """Modify sample mass based on sampling date."""

        duration = (params.sample_date[1] - params.sample_date[0]).days
        daily = (params.sample_mass[1] - params.sample_mass[0]) / duration
        for s in samples:
            elapsed = (s.timestamp - params.sample_date[0]).days
            growth = elapsed * daily
            s.mass += growth
        return {"daily": daily}

## `_do_person(params, grids, persons, samples)`

Modify sample mass based on the person doing the survey.

Source code in `src/snailz/effect.py`

    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    def _do_person(params, grids, persons, samples):
        """Modify sample mass based on the person doing the survey."""

        if params.clumsy_factor is None:
            return {}
        clumsy = random.choice(persons)
        for s in samples:
            if s.person_id == clumsy.person_id:
                s.mass -= params.sample_mass[0] * params.clumsy_factor
        return {"clumsy": clumsy.person_id}

## `_do_pollution(params, grids, persons, samples)`

Modify sample mass based on presence of pollution.

Source code in `src/snailz/effect.py`

    39
    40
    41
    42
    43
    44
    45
    46
    def _do_pollution(params, grids, persons, samples):
        """Modify sample mass based on presence of pollution."""

        grids = {g.grid_id: g for g in grids}
        for s in samples:
            pollution = grids[s.grid_id][s.x, s.y]
            s.mass += params.pollution_factor * pollution * s.mass
        return {}

## `_do_precision(params, grids, persons, samples)`

Adjust precision of mass measurements.

Source code in `src/snailz/effect.py`

    49
    50
    51
    52
    53
    54
    def _do_precision(params, grids, persons, samples):
        """Adjust precision of mass measurements."""

        for s in samples:
            s.mass = round(s.mass, params.precision)
        return {}