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

Feature/coverage #637

Merged
merged 12 commits into from
Feb 16, 2023
Merged

Feature/coverage #637

merged 12 commits into from
Feb 16, 2023

Conversation

NicolasColombi
Copy link
Collaborator

@NicolasColombi NicolasColombi commented Feb 1, 2023

Changes proposed in this PR:

Add coverage tests for module nightlight.py

Function tested:
1 ) read_bm_file
2) download_nl_files
3) unzip_tif_to_py

situated in: climada/entity/exposures/litpop/nightlight.py

Changes:

  1. Add tests
  2. Change how exception are raised in read_bm_file so that the error
    message is more explicit.

PR Author Checklist

PR Reviewer Checklist

1) Add coverage test for function read_bm_file at line 422 of:
climada/entity/exposures/litpop/nighlight.py

2) Invert the arguments of the path fucntion at line 441 of the file:
climada/entity/exposures/litpop/nighlight.py. The wrong order of the
arguments lead to the creation of a wrong path, which lead to an error
when opening the GeoTiff file as a Gdal DataSet.
A whitespace caused a linter issue to raise
1) delate a whitespace in read_bm_file in nightlight.py

2) add test for function path() which is used in read_bm_file
3) change the way the path is created
Function tested: read_bm_file situated in:
climada/entity/exposures/litpop/nightlight.py

Changes:

1) Move test to integration test
2) Reduce the function arguments of read_bm_file from 2 to 1.
3) Change how exeption are raised in read_bm_file so that the error
message is more explicit.
@NicolasColombi NicolasColombi changed the base branch from main to develop February 1, 2023 14:08
@NicolasColombi NicolasColombi marked this pull request as ready for review February 1, 2023 14:19
def read_bm_file(bm_path, filename):
def read_bm_file(file_path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although I agree, a single argument would be preferable here, this change affects the signature of a public function and hence we must keep backwards compatibility. Please revert this.

As a compromise one could make it flexible, i.e., allow bm_path, filename and file_path as named arguments - and possibly even *args as unnamed ones. But I think that would be out of scope of this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @emanuel-schmid , I changed the arguments of the function back to where it was before. Since I had already written another test meanwhile on that branch, it is also part of the commit. If it is a problem i can revert the commit, stash the additional test and commit only the changes to read_bm_files. Thanks for the review!

NicolasColombi and others added 3 commits February 8, 2023 17:03
1 ) Ripristine 2 orginal arguments of read_bm_file function

2) Add test for unzip_tif_to_py function of nightlight.py
Comment on lines 24 to 29
from climada.entity.exposures.litpop import nightlight
from climada.util.constants import SYSTEM_DIR
from climada.util.constants import (SYSTEM_DIR, CONFIG)

BM_FILENAMES = nightlight.BM_FILENAMES
DATA_DIR = CONFIG.exposures.test_data.dir()

Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@emanuel-schmid for the DATA_DIR ? Sorry, it was a remaining of the old test that i tried, it can be delated. Regarding the CONFIG: since CONFIG is imported from the same file as SYSTEM_DIR I thought it was more clean to import it with brackets.

Comment on lines -446 to -447
arr1 = band1.ReadAsArray()
del band1
Copy link
Collaborator

Choose a reason for hiding this comment

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

@NicolasColombi : do you know why band1 was deleted in the previous version? Why is the deletion skipped now?
(del something summons the garbage collector)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @emanuel-schmid, Yes, it is because in the old version extracting the first band of the image (band1) and then reading it as an array was done in 3 steps: 1) get the raster band , convert raster to array, delate the raster band1 in non array format. By getting the first band and directly reading it as an array (line 446) nothing is stored, so no need to delate anything. Line 446 of the new version does the same as Lines 445 to 447 of the old.

Copy link
Collaborator

Choose a reason for hiding this comment

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

🙈 Thanks!

@emanuel-schmid emanuel-schmid merged commit 1ba2743 into develop Feb 16, 2023
@emanuel-schmid
Copy link
Collaborator

🙌

@emanuel-schmid emanuel-schmid deleted the feature/coverage branch February 16, 2023 07:48
@emanuel-schmid emanuel-schmid mentioned this pull request Feb 17, 2023
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants