Skip to content
Merged

Dev #120

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dfeb34b
updating transport model
rafapereirabr Nov 6, 2026
4944ae7
Merge branch 'master' of https://github.com/ipea/gtfs2emis
rafapereirabr Nov 6, 2026
541d690
adapting transport model to new gtfs2gps
rafapereirabr Nov 6, 2026
e0f0f3c
new _pkgdown.yml
rafapereirabr Nov 6, 2026
08178cb
WIP: transport_model() for the new gtfs2gps (from deprecate-transport…
rafapereirabr Nov 6, 2026
e991212
Check ef_europe_emep() arguments; EC in MJ/km (G-22, G-23, G-25, G-70)
rafapereirabr Nov 6, 2026
c9f0ca3
Fix transport_model() gaps: dev gtfs2gps, speed caps, file names
rafapereirabr Nov 6, 2026
8ba1e27
Re-pin emis_grid/emis_summary test dimensions for gtfs2gps 2.1-4.9000
rafapereirabr Nov 6, 2026
eac71dd
gtfstools::interpolate_stop_times
rafapereirabr Nov 6, 2026
e65b893
Interpolate only blank stop times, before the speed limits
rafapereirabr Nov 6, 2026
4ffa3a3
Retime trips when transport_model() caps or fills segment speeds
rafapereirabr Nov 6, 2026
9961d3f
Fix emission_model(): scaled-Euro tech, process checks, output_path g…
rafapereirabr Nov 6, 2026
1cc75a8
Use has_units()/as_kmh() for unit checks; NEWS points for gtfs2gps 3.0
rafapereirabr Nov 6, 2026
9c84ace
Merge port/units-news: has_units()/as_kmh() unit checks and gtfs2gps …
rafapereirabr Nov 6, 2026
4271eca
Speed up ef_europe_emep() and emis_grid(); cut their memory use
rafapereirabr Nov 6, 2026
e5a04b8
Speed up emis_to_dt(), multiply_ef() and the MOVES/EMFAC speed lookup
rafapereirabr Nov 6, 2026
eaff30e
update ga actions
rafapereirabr Nov 7, 2026
2a69cd4
Fix wear, CETESB and emis_grid bugs; planar emis_grid(); untrack qual…
rafapereirabr Nov 7, 2026
afd4f32
Clarify the vignettes and move links to the ipea organisation
rafapereirabr Nov 7, 2026
32de108
Deprecate `parallel` in emission_model(); ncores defaults to 2
rafapereirabr Nov 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/rules/orchestrator-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ the plan and the relevant files:

| Lens | Agent | Looks for |
|---|---|---|
| Correctness and emission math | `general-purpose` | Logic errors; EF formulas vs the source (EMEP/EEA, CETESB, MOVES, EMFAC, scaled Euro); speed validity ranges; units (km/h, km vs m, g/km, g); EF lookups that silently return `NA`/wrong rows; fleet composition not summing to 1; vector recycling between fleet and EF; joins/aggregations in `emis_summary()`/`emis_grid()`; CRS in `emis_grid()`; same result with `parallel = TRUE` and `FALSE` |
| Correctness and emission math | `general-purpose` | Logic errors; EF formulas vs the source (EMEP/EEA, CETESB, MOVES, EMFAC, scaled Euro); speed validity ranges; units (km/h, km vs m, g/km, g); EF lookups that silently return `NA`/wrong rows; fleet composition not summing to 1; vector recycling between fleet and EF; joins/aggregations in `emis_summary()`/`emis_grid()`; CRS in `emis_grid()`; same result with `ncores = 1` and `ncores = 2` |
| Performance and parallelism | `general-purpose` | Avoidable copies, row loops, repeated joins, slow `sf` operations, objects shipped to `future` workers, side effects (`<<-`, messages) lost in workers, temp files left behind; asks for `bench::mark` if a speed claim is made |
| Package and CRAN | `r-package-reviewer` (local; if absent, `general-purpose` with `r-package-conventions.md`) | Conventions, roxygen, NAMESPACE, `data/` vs `data-raw/`, tests (including known values and "doesn't change input data"), CRAN policy (cores, writing outside `tempdir()`), back-compat |

Expand Down
2 changes: 1 addition & 1 deletion .claude/rules/plan-first-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ paths. They never see each other's output in the first round.
| Reviewer | Mandate |
|---|---|
| **Minimalist** | Make it smaller. Which steps, files, abstractions, arguments or dependencies are unnecessary? Can an existing helper do this? What is the smallest diff that fully solves the problem? Is anything gold-plating? |
| **Skeptic** | Make it right. What breaks? Edge cases (speeds outside EF validity ranges, unknown pollutant/vehicle/Euro/model-year combinations, fleet shares not summing to 1, `NA` speeds, empty tables, geographic vs projected CRS), caller mutation, `parallel = TRUE` vs `FALSE` divergence, units of outputs, performance regressions, back-compat for exported functions, CRAN issues, missing tests. |
| **Skeptic** | Make it right. What breaks? Edge cases (speeds outside EF validity ranges, unknown pollutant/vehicle/Euro/model-year combinations, fleet shares not summing to 1, `NA` speeds, empty tables, geographic vs projected CRS), caller mutation, `ncores = 1` vs `ncores = 2` divergence, units of outputs, performance regressions, back-compat for exported functions, CRAN issues, missing tests. |

Each returns findings as `{severity: CRITICAL|MAJOR|MINOR, finding, proposed_change}`
and a verdict: `APPROVE` or `REVISE`.
Expand Down
2 changes: 1 addition & 1 deletion .claude/rules/quality-gates.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ All must hold for the files touched:
| Docs regenerated | `Rscript -e "devtools::document()"` then `git diff --stat man/ NAMESPACE DESCRIPTION` | No unexpected content drift (use `git diff`, not `git status`: `core.autocrlf=true` can rewrite line endings only); intended changes staged with the source |
| Targeted tests | `Rscript -e "devtools::test(filter = '<fn>')"` for every touched function (files are `test_<fn>.R`) | 0 failures, 0 new warnings |
| Units / known values | for EF or emission math changes: a hand-checked value against the source table/equation | Matches within tolerance |
| Parallel parity | if `transport_model()`/`emission_model()` worker code changed: run with `parallel = FALSE` and `parallel = TRUE, ncores = 2` (install the package first) | Identical results |
| Parallel parity | if `transport_model()`/`emission_model()` worker code changed: run with `ncores = 1` and `ncores = 2` (install the package first) | Identical results |
| Data | if `data/*.rda` changed | Rebuilt by the `data-raw/` script; `R/data.R` matches the columns |
| Style | read the diff against the surrounding code | Matches the file (conventions A5) |
| NEWS | user-facing change | Bullet under the development-version heading (conventions A9) |
Expand Down
17 changes: 9 additions & 8 deletions .claude/rules/r-package-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ emi_list ──emis_summary() / emis_to_dt() / emis_grid()──► tables / sf
do).
- Use keyed / `on =` joins and `by =` grouping. No new row-wise loops.
- **Parallelism:** `transport_model()` and `emission_model()` take
`parallel` / `ncores`, set `future::plan("multisession", workers = ncores)`,
restore the previous plan with `on.exit()`, and use `furrr::future_map()`.
Default `ncores` is `parallelly::availableCores(omit = 1)`.
`ncores` (default 2; `parallel` is deprecated). `transport_model()` passes
it to {gtfs2gps} as threads; `emission_model()`, for a folder `tp_model`,
sets `future::plan("multisession", workers = ncores)`, restores the
previous plan with `on.exit()`, and uses `furrr::future_map()`.
- Worker code runs in separate R processes: no `<<-`; return values.
- Under `load_all()`, workers load the **installed** gtfs2emis, so install
before testing a changed worker path.
- A worker-path change must give **identical results** with
`parallel = FALSE` and `parallel = TRUE, ncores = 2` (Gate 1).
`ncores = 1` and `ncores = 2` (Gate 1).
- Never use more than 2 workers in tests, examples or vignettes.
- `transport_model(output_path = )` writes files: only to the user's path or
`tempdir()`.
Expand Down Expand Up @@ -144,7 +145,7 @@ emi_list ──emis_summary() / emis_to_dt() / emis_grid()──► tables / sf
`@return` (class, columns, units), `@family`/`@seealso` where useful, and
`@examples`.
- **Examples** use the bundled fixtures and stay small: one shape of
`irl_dub_gtfs.zip`, `parallel = FALSE`. Slow examples go in `\donttest{}`,
`irl_dub_gtfs.zip`, `ncores = 1`. Slow examples go in `\donttest{}`,
never `\dontrun{}`.
- Internal helpers (`multiply_ef()`, `fuel_correction()`): `@noRd` or
`@keywords internal`, matching the file.
Expand Down Expand Up @@ -172,7 +173,7 @@ emi_list ──emis_summary() / emis_to_dt() / emis_grid()──► tables / sf
- a **known-value test** for EF functions (a value checked by hand against
the source table/equation, with the source cited in a comment)
- "doesn't change input data" when the function takes a data.table/sf
- `parallel = FALSE` vs `TRUE, ncores = 2` parity if the worker path changed
- `ncores = 1` vs `ncores = 2` parity if the worker path changed
- When an algorithm change legitimately moves pinned values, re-derive them
and explain the change in the plan; never paste new output blindly.

Expand Down Expand Up @@ -211,7 +212,7 @@ it at release. Credit external contributors and reference issues (`#123`).
| Writing outside `tempdir()` | `tempdir()` or user-supplied `output_path` |
| `<<-` | Return values |
| `options()`/`future::plan()` changed, not restored | `on.exit(..., add = TRUE)` |
| More than 2 cores in tests/examples/vignettes | `parallel = FALSE` or `ncores = 2` |
| More than 2 cores in tests/examples/vignettes | `ncores = 1` or `ncores = 2` |
| `T`/`F` | `TRUE`/`FALSE` |
| Unvalidated enumerated arg | `checkmate::assert_choice()` |
| `==` on doubles or `units` vs numeric | tolerance / `units::set_units()` |
Expand All @@ -228,7 +229,7 @@ it at release. Credit external contributors and reference issues (`#123`).
[ ] new/changed args validated with checkmate
[ ] units correct and preserved (km/h, km/m, g/km, g)
[ ] EF lookups error on unknown combinations; known-value test cites the source
[ ] worker path: identical results parallel = FALSE vs TRUE
[ ] worker path: identical results ncores = 1 vs 2
[ ] ≤ 2 cores and tempdir() only in tests/examples/vignettes
[ ] conditions via cli / internal assert_* wrappers (A4); errors classed gtfs2emis_error
[ ] style matches the file (leading commas, explicit return())
Expand Down
49 changes: 27 additions & 22 deletions .github/workflows/R-CMD-check-CRAN.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# (check-standard.yaml), reduced to one job that runs the check the way CRAN
# does: NOT_CRAN=false, so tests/examples guarded by skip_on_cran() also run
# as on CRAN.
on:
push:
branches:
- master
branches: [main, master]
pull_request:
branches:
- master

name: R-CMD-check
name: R-CMD-check-CRAN

permissions: read-all

jobs:
check:
R-CMD-check-CRAN:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
name: CRAN-like ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-22.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/jammy/latest"}
- {os: ubuntu-latest, r: 'release'}

env:
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
env:
_R_CHECK_CRAN_INCOMING_: false
NOT_CRAN: false
- uses: r-lib/actions/check-r-package@v2
with:
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
env:
_R_CHECK_CRAN_INCOMING_: false
NOT_CRAN: false
49 changes: 28 additions & 21 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- master
branches: [main, master]
pull_request:
branches:
- master

# Kept as "R-CMD-check" (not upstream's "R-CMD-check.yaml"): the README badge
# links to the workflow by this name.
name: R-CMD-check

permissions: read-all

jobs:
check:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
Expand All @@ -18,28 +21,32 @@ jobs:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-22.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/jammy/latest"}
- {os: ubuntu-22.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/jammy/latest"}
- {os: ubuntu-22.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/jammy/latest"}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
45 changes: 30 additions & 15 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- master
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:

name: pkgdown
name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
RSPM: https://packagemanager.rstudio.com/cran/__linux__/jammy/latest
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: write
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
id: install-r
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build and deploy pkgdown site
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@d92aa235d04922e8f08b40ce78cc5442fcfbfa2f # v4.8.0
with:
clean: false
branch: gh-pages
folder: docs
30 changes: 15 additions & 15 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master

name: test-coverage
name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
env:
RSPM: https://packagemanager.rstudio.com/cran/__linux__/jammy/latest
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-r@v2

# Installs Suggests too (gtfstools is needed by tests/testthat/setup.R).
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
Expand All @@ -34,15 +33,16 @@ jobs:
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
files: ./cobertura.xml
plugins: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -55,7 +55,7 @@ jobs:

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
path: ${{ runner.temp }}/package
11 changes: 5 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ Brazil CETESB, USA MOVES and USA EMFAC, plus scaled-Euro local factors.
`emission_model()` combines segments, fleet data and emission factors. The
`emis_*()` helpers summarise the result by time, vehicle and pollutant, or on
a spatial grid. It is built on `data.table`, `sf`, `units`, `checkmate`,
`terra` and `future`/`furrr`. Published on CRAN; developed by Ipea (ipeaGIT).
`terra` and `future`/`furrr`. Published on CRAN; developed by Ipea (GitHub: `ipea`).
Maintainer (cre): Joao Bazzo; authors include Rafael H. M. Pereira and
Pedro R. Andrade. License MIT. Docs: <https://ipea.github.io/gtfs2emis/> (DESCRIPTION still points to the
dead `ipeagit` host; audit item #30).
Pedro R. Andrade. License MIT. Docs: <https://ipea.github.io/gtfs2emis/>.
Method paper: Vieira, Pereira & Andrade (2022), doi:10.31219/osf.io/8m2cy.
Default branch: `master`.

Expand All @@ -27,7 +26,7 @@ Default branch: `master`.
- **Never surprise the caller.** Functions don't modify the user's GTFS,
`tp_model`, fleet data or `emi_list` (`data.table::copy()`).
- **Parallel = sequential.** `transport_model()` and `emission_model()` must
give the same result with `parallel = TRUE` and `parallel = FALSE`.
give the same result with `ncores = 1` and `ncores = 2`.
- **CRAN-ready at all times.** `R CMD check --as-cran`: 0 errors, 0 warnings.
Examples and vignettes use ≤ 2 cores and write only to `tempdir()`.
- **Plan first.** Enter plan mode before non-trivial tasks. Every plan is
Expand All @@ -53,8 +52,8 @@ gates are in [`.claude/rules/quality-gates.md`](.claude/rules/quality-gates.md).
gtfs2emis/
├── DESCRIPTION, NAMESPACE # NAMESPACE is roxygen-generated; never hand-edit
├── R/
│ ├── transport_model.R # GTFS → sf segments (gtfs2gps), parallel/output_path
│ ├── emission_model.R # tp_model + fleet + EF → emi_list, parallel
│ ├── transport_model.R # GTFS → sf segments (gtfs2gps), ncores/output_path
│ ├── emission_model.R # tp_model + fleet + EF → emi_list, ncores
│ ├── ef_europe_emep.R, ef_brazil_cetesb.R, ef_usa_moves.R, ef_usa_emfac.R, ef_scaled_euro.R
│ ├── emi_europe_emep_wear.R # non-exhaust (tyre, brake, road wear)
│ ├── slope_class_europe_emep.R # road slope from a DEM (terra)
Expand Down
Loading
Loading