Honor quadrature kwargs in calculate_total_face_area - #1568
Conversation
calculate_total_face_area accepted quadrature_rule, order and latitude_adjusted_area but ignored them, always returning the cached default-parameter face_areas. As a result the gaussian/corrected path produced the same total as the triangular one. Keep the cached fast path for the default parameters (which also preserves the equal-area values used for HEALPix grids) and route any non-default quadrature settings through _compute_face_areas so the requested rule, order and latitude adjustment actually take effect.
Sevans711
left a comment
There was a problem hiding this comment.
@vakudo thank you for your contribution! I also confirmed it runs, correctly gives results which actually depend on relevant kwargs, and that the new test fails on main while succeeding after your fix.
Let's merge to main!
I may open a separate issue soon related to the other parts of the face areas API. Looking into the existing methods and your fix helped me notice this. For example, uxarray now properly supports kwargs like quadrature_rule publicly in calculate_total_face_area(), while the only non-deprecated public interface for getting individual face areas (i.e., Grid.face_areas) does not support those kwargs. It seems strange to support them publicly only for the total, and not for individual faces.
Closes #1567.
Grid.calculate_total_face_area()documentsquadrature_rule,orderandlatitude_adjusted_areaparameters, but the body ignored them and always returnednp.sum(self.face_areas.values)— the cached face areas computed with the default parameters. So calling it with, for example,quadrature_rule="gaussian", order=5, latitude_adjusted_area=Truegave exactly the same total as the default triangular call.Fix
triangular,order=4, no latitude adjustment) it still returns the cachedface_areas, which also preserves the theoretical equal-area values used for HEALPix grids._compute_face_areas(quadrature_rule, order, latitude_adjusted_area)so the requested quadrature rule, order and latitude adjustment actually take effect.The default behavior (and the HEALPix path) is unchanged.
Tests
Added
test_calculate_total_face_area_respects_quadrature_kwargs, which asserts the corrected result differs from the uncorrected one and matches the expectedTRI_AREA/CORRECTED_TRI_AREAconstants to 6 decimals. The existingtest_face_areas_calculate_total_face_area_triangleused adecimal=3tolerance too loose to catch this (the correction for that triangle is ~2.8e-4). The new test fails on the previous code and passes with the fix; the fulltest/grid/grid/test_areas.pysuite passes.Note: the "Face Area Calculations" docs page (section 2) also states the second calculation gives a slightly different area than the first — with this fix that statement becomes true when non-default quadrature settings are used.