Skip to content

Commit

Permalink
Back in time, add logging to cropping, add to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gac55 committed Sep 11, 2024
1 parent d91ffcb commit 7be1e19
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/arup-group/cookiecutter-pypackage.git",
"commit": "b7724521f898ab28f541d492aff8e2be2ed76a01",
"commit": "b4e39b80b4d9b4d6682ab18635a98a097b292a46",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ name: Build docs
on:
push:
branches:
- "**"
- main

pull_request:
branches:
- main
paths-ignore:
- tests/**
- ".github/**/*"
- "!.github/workflows/docs.yml"


jobs:
docs-test:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
- CONTRIBUTING.md
- docs/**
- mkdocs.yml
- ".github/**/*"
- "!.github/workflows/pr-ci.yml"

jobs:
test:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ["--maxkb=1000"]

- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.2.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit # https://beta.ruff.rs/docs/usage/#github-action
rev: v0.6.3
rev: v0.3.0
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.7
rev: 1.8.3
hooks:
- id: nbqa-black
- id: nbqa-ruff
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
* Facility link snapping (#276).
* Logging of the agents and households removed during (spatial) cropping (#285).

### Changed

Expand Down
3 changes: 2 additions & 1 deletion docs/activity_plans.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ This is resulting some difficult to follow logic (e.g., [][pam.activity.Plan.fil
## Plan cropping
The [`pam.operations.cropping`](reference/pam/operations/cropping.md) module allows to spatially subset populations, by simplifying plan components that take place outside the "core" area.
Any activities or legs that do not affect that core area are removed from the agents' plans, and agents with fully-external plans are removed from the population.
Examples of using the module can be found in the [][plan-cropping] notebook.
Examples of using the module can be found in the [][plan-cropping] notebook.
Plan cropping now features basic logging on the input and then output population, quantifying the changes in agent and households as a result of the cropping.
10 changes: 10 additions & 0 deletions pyproject.toml.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff a/pyproject.toml b/pyproject.toml (rejected hunks)
@@ -9,7 +9,7 @@ minversion = "6.0"
# `--cov --cov-report=xml --cov-config=pyproject.toml` - generate coverage report for tests (uses pytest-cov; call `--no-cov` in CLI to switch off; `--cov-config` include to avoid bug)
# `-m 'not high_mem'` - Do not run tests marked as consuming large amounts of memory (call `-m "high_mem"` in CLI to invert this; only `high_mem` marked tests will be run)
# `-p no:memray` - Do not use the memray memory profiling plugin (call `-p memray` in CLI to switch on memory profiling)
-addopts = "-rav --strict-markers -n2 --nbmake --nbmake-kernel=pam --cov --cov-report=xml --cov-config=pyproject.toml -m 'not high_mem' -p no:memray"
+addopts = "-rav --strict-markers -nauto --nbmake --nbmake-kernel=pam --cov --cov-report=xml --cov-config=pyproject.toml -m 'not high_mem' -p no:memray"
testpaths = ["tests", "examples"]

# to mark a test, decorate it with `@pytest.mark.[marker-name]`
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cruft >= 2, < 3
jupyter < 2
mike >= 2, < 3
mkdocs < 1.6
mkdocs >= 1.6, < 2
mkdocs-material >= 9.4, < 10
mkdocs-click < 0.7
mkdocs-jupyter < 0.24.7
mkdocs-jupyter >= 0.24.8, < 0.25
mkdocstrings-python < 2
nbmake >= 1.5.1, < 2
pre-commit < 4
Expand Down
13 changes: 13 additions & 0 deletions src/pam/operations/cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,36 @@ def simplify_population(
) -> None:
"""Simplify external plans across a population."""
# simplify plans

for hid, pid, person in population.people():
simplify_external_plans(person.plan, boundary, snap_to_boundary, rename_external_activities)

# remove empty person-plans and households
remove_persons = []
track_those_removed = []

print("Before simplification", population.stats)

for hid, pid, person in population.people():
if len(person.plan) == 1 and person.plan.day[0].act == "external":
remove_persons.append((hid, pid))
track_those_removed.append({"hid": hid, "pid": pid})
for hid, pid in remove_persons:
del population[hid].people[pid]

print(len(remove_persons), "persons to be removed")

remove_hhs = [
hid for hid in population.households if len(population.households[hid].people) == 0
]

print(len(remove_hhs), "households to be removed")

for hid in remove_hhs:
del population.households[hid]

print("After simplification", population.stats)


def simplify_external_plans(
plan: Plan,
Expand Down

0 comments on commit 7be1e19

Please sign in to comment.