Skip to content

Conversation

@zeliest
Copy link
Collaborator

@zeliest zeliest commented Mar 10, 2025

Changes proposed in this PR:

  • Added a target_grid option for creating LitPop exposures. If the argument is not provided, the grid is automatically defined based on the population dataset (GPW) or nightlight dataset (NASA Black Marble), depending on the resolution.

    • If res_arcsec == 15, the Black Marble Nightlight grid is used with a predefined global transform.
    • Otherwise, the grid aligns with GPW, adjusting to the nearest resolution step based on its transform.
  • Removed outdated test case (test_reproject_input_data_odd_downsample), as it was no longer relevant with the new grid alignment method.

  • Added a new test (test_target_grid_alignment) to verify that the reprojection correctly aligns with the target grid.

Why this is needed:

  • Allows to flexibly define grid for litpop to align with hazards
  • This becomes faster when defining LitPop for many countries, as the grid is defined only once.

PR Author Checklist

PR Reviewer Checklist

reference_year=DEF_REF_YEAR,
gpw_version=GPW_VERSION,
data_dir=SYSTEM_DIR,
target_grid=None
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add the docstring for this new variable?

res_arcsec=15,
reference_year=DEF_REF_YEAR,
data_dir=SYSTEM_DIR,
target_grid=None
Copy link
Member

Choose a reason for hiding this comment

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

idem, can you please add the docstring?

reference_year=DEF_REF_YEAR,
gpw_version=GPW_VERSION,
data_dir=SYSTEM_DIR,
target_grid=None
Copy link
Member

Choose a reason for hiding this comment

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

idem, can you please add the docstring?

reference_year=DEF_REF_YEAR,
gpw_version=GPW_VERSION,
data_dir=SYSTEM_DIR,
target_grid=None
Copy link
Member

Choose a reason for hiding this comment

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

idem, can you please add the docstring?

Copy link
Member

@chahank chahank left a comment

Choose a reason for hiding this comment

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

Great addition! I have noted quickly some small elements to improve the code itself. I will do a review of the desired result of the new feature soon. I am currently wondering how the resampling of the original data (black marble and gpw) is done, how this affects the output results, and whether this is clear to the user at the moment.

@zeliest zeliest changed the title Feature/costum grid litpop Feature/custom grid litpop Mar 12, 2025
@chahank
Copy link
Member

chahank commented Mar 12, 2025

So, the data is regridded using the method util.coords.align_raster_data (make a link in the docstring with See Also section) and using the resampling rasterio.warp.Resampling.bilinear. I think this information should be added to the docstring, together with the information on how to use either the lit or the pop grid. Also, it should be clear that if the target grid is defined, then the resolution does nothing.

Comment on lines 535 to 539
# TESTS = unittest.TestLoader().loadTestsFromTestCase(TestLitPopExposure)
# TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestAdmin1))
# unittest.TextTestRunner(verbosity=2).run(TESTS)

TESTS = unittest.TestLoader().loadTestsFromTestCase(TestLitPopGridAlignment)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# TESTS = unittest.TestLoader().loadTestsFromTestCase(TestLitPopExposure)
# TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestAdmin1))
# unittest.TextTestRunner(verbosity=2).run(TESTS)
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestLitPopGridAlignment)
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestLitPopExposure)
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestAdmin1))
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestLitPopGridAlignment))

@chahank
Copy link
Member

chahank commented Mar 26, 2025

The tests are currently failing due to a too-low test coverage. It means that many of the added lines of code are never tested for. This suggests that additional unit tests are required.

Also, there are small linter errors that are easy to correct (trailing white spaces for instance).

@chahank chahank marked this pull request as ready for review September 23, 2025 14:24
@chahank
Copy link
Member

chahank commented Sep 23, 2025

I think the test coverage is failing because the main methods to setup litpop are only tested in the integration test.

@emanuel-schmid if you confirm, I would merge.

@emanuel-schmid
Copy link
Collaborator

I think the test coverage is failing because the main methods to setup litpop are only tested in the integration test.

That may be the reason. It fails if the reference job, which is a particular commit from develop, has a better (lines of code)/(tested lines of code) ratio. That's all.

If only this fails, we don't mind. 🤷

@chahank chahank merged commit 0e57f8f into develop Sep 25, 2025
17 of 19 checks passed
@emanuel-schmid emanuel-schmid deleted the feature/costum_grid_litpop branch December 11, 2025 08:43
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.

4 participants