Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

29 clip osm #34

Merged
merged 123 commits into from
Aug 22, 2023
Merged

29 clip osm #34

merged 123 commits into from
Aug 22, 2023

Conversation

r-leyshon
Copy link
Contributor

@r-leyshon r-leyshon commented Jul 26, 2023

Description

Fixes #29

  • This branch is a hotfix off gtfs validation pipeline #15 (I needed the defence modules). Please wait on outcome of PR 15 gtfs validation pipeline #20 before reviewing this.
  • Introduces a filter_osm() function.
  • Some breaking changes in utils.defence.py to make units more generalisable.
  • Integration tests included in dedicated workflow step in single workflow.
  • Tests for filter_osm()
  • Refactored test module names. Pytest doesn't like test modules with identical names.

Motivation and Context

Filter Open Street Map pbf files to a bounding box.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Test configuration details:

  • OS: macos
  • Python version: 3.9.13
  • Java version: openjdk 11.0.19 2023-04-18 LTS
  • Python management system: pip

Advice for reviewer

Pytest modules renamed. transport_performance.gtfs.utils and transport_performance.osm.utils would cause problems. Therefore gone with: transport_performance.gtfs.gtfs_utils, so on.

Checklist:

  • My code follows the intended structure of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings - pkg_resources deprecation warnings have started again. Please see pkg_resources deprecation warning #19 . Note that this is a local issue on my machine and is not evident in the CI runners.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules Please do not review until 15 gtfs validation pipeline #20 has been merged to main.

Additional comments

r-leyshon added 30 commits June 21, 2023 13:45
@r-leyshon r-leyshon added the enhancement New feature or request label Jul 26, 2023
@r-leyshon r-leyshon added this to the sprint 2 end milestone Jul 26, 2023
@r-leyshon r-leyshon linked an issue Jul 26, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2023

Codecov Report

Patch coverage: 80.95% and project coverage change: -0.49% ⚠️

Comparison is base (96f48a9) 83.91% compared to head (872b045) 83.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #34      +/-   ##
==========================================
- Coverage   83.91%   83.42%   -0.49%     
==========================================
  Files           8        9       +1     
  Lines         491      525      +34     
==========================================
+ Hits          412      438      +26     
- Misses         79       87       +8     
Flag Coverage Δ
unittests 83.42% <80.95%> (-0.49%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/transport_performance/osm/osm_utils.py 75.75% <75.75%> (ø)
src/transport_performance/gtfs/gtfs_utils.py 100.00% <100.00%> (ø)
src/transport_performance/gtfs/routes.py 93.33% <100.00%> (ø)
src/transport_performance/gtfs/validation.py 100.00% <100.00%> (ø)
src/transport_performance/utils/defence.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SergioRec SergioRec self-assigned this Aug 15, 2023
Copy link
Contributor

@SergioRec SergioRec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script works as intended. Created technical debt issues for comments below.


def filter_osm(
pbf_pth=here("tests/data/newport-2023-06-13.osm.pbf"),
out_pth="filtered.osm.pbf",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default of out_pth is only the filename, so the output will be saved in root. Could this be changed to outputs/osm?
#80


def filter_osm(
pbf_pth=here("tests/data/newport-2023-06-13.osm.pbf"),
out_pth="filtered.osm.pbf",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using a path in the out_pth argument, using backslashes in the string is not recognised as a path and instead creates a file with that character or whatever escape character happens in the filename. Using double slash to prevent escape character just creates a file with the slash in the name.

Will add to #61 as it's related to helper function _check_parent_dir_exists.

@@ -71,9 +75,9 @@ def _is_gtfs_pth(pth, param_nm, check_existing=True):
_, ext = os.path.splitext(pth)
if check_existing and not os.path.exists(pth):
raise FileExistsError(f"{pth} not found on file.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is unclear.

>>> filter_osm(pbf_pth = 'folder/subfolder/blah.pbf')
FileExistsError: folder/subfolder/blah.pbf not found on file.

Something like <file> not found would read better.

#83

cmd = [
"osmosis",
"--read-pbf",
pbf_pth.as_posix(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PosixPath() will likely not work in Windows machines. According to the pathlib documentation, the method .as_posix returns a string representation of the path with forward slashes. Perhaps worth exploring a more OS agnostic method for this.
#81

except FileNotFoundError as e2:
if install_osmosis:
print(f"osmosis command was not recognised: {e2}. Trying install.")
subprocess.run(["brew", "install", "osmosis"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subprocess.run(["brew", "install", "osmosis"]) will only run in macOS systems. We could add a more system agnostic way of doing this? E.g. check OS and use an if statement to run different commands depending on OS.
#82

@@ -40,13 +40,21 @@ jobs:
- name: Check Java Install
run: |
java --version
- name: Install Osmosis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructions to install osmosis need to be added to CONTRIBUTING.md.
#79

filter_osm(bbox=[0.0, 0.1, 0.1, 0.0])
with pytest.raises(
TypeError,
match="ox` must contain <class 'float'> only. Found <class 'int'>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work, but truncating the error message to match to fit the line does not look good.

_is_expected_filetype(pth=in_pth, param_nm="in_pth")
_is_expected_filetype(
pth=out_pth, param_nm="out_pth", check_existing=False
)
_check_list(ls=bbox_list, param_nm="bbox_list", exp_type=float)
for param in [units, crs]:
if not isinstance(param, str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function is going to be used to crop GTFS based on a provided box, we should rename the local variable newport_feed to something generic.

#78

Copy link
Contributor

@SergioRec SergioRec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging with dev, pending technical debt issues.

@SergioRec SergioRec merged commit 3915cf6 into dev Aug 22, 2023
4 checks passed
@SergioRec SergioRec deleted the 29-clip-osm branch August 22, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clip osm
4 participants