From 7be1e195649b567ab8c5578e199ee59b09692e17 Mon Sep 17 00:00:00 2001 From: Gerard Casey Date: Wed, 11 Sep 2024 16:21:56 +0100 Subject: [PATCH] Back in time, add logging to cropping, add to docs --- .cruft.json | 2 +- .github/workflows/docs.yml | 9 ++++++++- .github/workflows/pr-ci.yml | 2 ++ .pre-commit-config.yaml | 8 ++++---- CHANGELOG.md | 1 + docs/activity_plans.md | 3 ++- pyproject.toml.rej | 10 ++++++++++ requirements/dev.txt | 4 ++-- src/pam/operations/cropping.py | 13 +++++++++++++ 9 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 pyproject.toml.rej diff --git a/.cruft.json b/.cruft.json index f0ee6048..c77be0c6 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/arup-group/cookiecutter-pypackage.git", - "commit": "b7724521f898ab28f541d492aff8e2be2ed76a01", + "commit": "b4e39b80b4d9b4d6682ab18635a98a097b292a46", "checkout": null, "context": { "cookiecutter": { diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 40422ee5..91ee369f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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: diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index 82498968..8d578c40 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -11,6 +11,8 @@ on: - CONTRIBUTING.md - docs/** - mkdocs.yml + - ".github/**/*" + - "!.github/workflows/pr-ci.yml" jobs: test: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8c6159e..aef68a43 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index a7b4e56b..30ad3993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/activity_plans.md b/docs/activity_plans.md index fb7514ac..570aec1a 100644 --- a/docs/activity_plans.md +++ b/docs/activity_plans.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/pyproject.toml.rej b/pyproject.toml.rej new file mode 100644 index 00000000..90b4ebc1 --- /dev/null +++ b/pyproject.toml.rej @@ -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]` diff --git a/requirements/dev.txt b/requirements/dev.txt index 57383799..0d463b0f 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -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 diff --git a/src/pam/operations/cropping.py b/src/pam/operations/cropping.py index b0e82c70..9221f250 100644 --- a/src/pam/operations/cropping.py +++ b/src/pam/operations/cropping.py @@ -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,