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

Bugfix: make consistency.Approx repr consistent with class behavior #427

Merged
merged 1 commit into from Jun 9, 2023

Conversation

pressler-vsc
Copy link
Collaborator

Description

As mentioned in SarPy#425, the existing sarpy.consistency.Approx __repr__ is both incorrect (missing an abs) and inconsistent with its usage (given how odd np.isclose actually is)

This PR aims to remedy this by adjusting the check (note the swapped order of operands in the new np.isclose usage) and the repr to align.

In master

>>> import sarpy.consistency.consistency as con
>>> con.Approx(-5)
-5 +/- 1e-10
>>> con.Approx(+5)
5 +/- 4.9999999999999996e-06

In this branch

>>> import sarpy.consistency.consistency as con
>>> con.Approx(-5)
-5 ± 5.0001e-06
>>> con.Approx(+5)
5 ± 5.0001e-06

Test Plan

Changes tested against SarPy environments in python 3.6, 3.8, and 3.10

3.6
========================================================================================================================================================== test session starts ===========================================================================================================================================================
platform linux -- Python 3.6.13, pytest-6.2.4, py-1.11.0, pluggy-0.13.1
rootdir: /home/vscuser/git/glweb/software/third-party/sarpy
collected 279 items                                                                                                                                                                                                                                                                                                                      

tests/test_class_string.py .                                                                                                                                                                                                                                                                                                       [  0%]
tests/consistency/test_consistency.py ........                                                                                                                                                                                                                                                                                     [  3%]
tests/consistency/test_cphd_consistency.py ..............................................................                                                                                                                                                                                                                          [ 25%]
tests/geometry/test_geocoords.py ..........                                                                                                                                                                                                                                                                                        [ 29%]
tests/geometry/test_geometry_elements.py ..........                                                                                                                                                                                                                                                                                [ 32%]
tests/geometry/test_latlon.py ...                                                                                                                                                                                                                                                                                                  [ 33%]
tests/geometry/test_point_projection.py ............                                                                                                                                                                                                                                                                               [ 37%]
tests/io/DEM/test_geoid.py s                                                                                                                                                                                                                                                                                                       [ 38%]
tests/io/DEM/test_geotiff1deg_list.py ....                                                                                                                                                                                                                                                                                         [ 39%]
tests/io/DEM/test_geotiff1deg_reader.py .ss..ss.                                                                                                                                                                                                                                                                                   [ 42%]
tests/io/complex/test_reader.py sssssssssss                                                                                                                                                                                                                                                                                        [ 46%]
tests/io/complex/test_remote.py .                                                                                                                                                                                                                                                                                                  [ 46%]
tests/io/complex/test_sicd.py s                                                                                                                                                                                                                                                                                                    [ 47%]
tests/io/complex/test_utils.py .                                                                                                                                                                                                                                                                                                   [ 47%]
tests/io/complex/sicd_elements/test_sicd_elements_errorstatistics.py .                                                                                                                                                                                                                                                             [ 48%]
tests/io/complex/sicd_elements/test_sicd_elements_grid.py ..                                                                                                                                                                                                                                                                       [ 48%]
tests/io/complex/sicd_elements/test_sicd_elements_imagedata.py .                                                                                                                                                                                                                                                                   [ 49%]
tests/io/complex/sicd_elements/test_sicd_elements_imageformation.py ......                                                                                                                                                                                                                                                         [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_matchinfo.py .                                                                                                                                                                                                                                                                   [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_pfa.py .                                                                                                                                                                                                                                                                         [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_radarcollection.py ..............                                                                                                                                                                                                                                                [ 56%]
tests/io/complex/sicd_elements/test_sicd_elements_radiometric.py .                                                                                                                                                                                                                                                                 [ 57%]
tests/io/complex/sicd_elements/test_sicd_elements_rgazcomp.py .                                                                                                                                                                                                                                                                    [ 57%]
tests/io/complex/sicd_elements/test_sicd_elements_scpcoa.py ...................                                                                                                                                                                                                                                                    [ 64%]
tests/io/complex/sicd_elements/test_sicd_elements_sicd.py ..................................                                                                                                                                                                                                                                       [ 76%]
tests/io/complex/sicd_elements/test_sicd_elements_timeline.py .....                                                                                                                                                                                                                                                                [ 78%]
tests/io/complex/sicd_elements/test_sicd_elements_utils.py ...                                                                                                                                                                                                                                                                     [ 79%]
tests/io/general/test_base.py ...                                                                                                                                                                                                                                                                                                  [ 80%]
tests/io/general/test_data_segment.py ..........                                                                                                                                                                                                                                                                                   [ 84%]
tests/io/general/test_format_function.py .......                                                                                                                                                                                                                                                                                   [ 86%]
tests/io/general/test_nitf_headers.py s                                                                                                                                                                                                                                                                                            [ 87%]
tests/io/general/test_tre.py .                                                                                                                                                                                                                                                                                                     [ 87%]
tests/io/phase_history/test_cphd.py .                                                                                                                                                                                                                                                                                              [ 87%]
tests/io/phase_history/cphd1_elements/test_utils.py .                                                                                                                                                                                                                                                                              [ 88%]
tests/io/product/test_reader.py ..s                                                                                                                                                                                                                                                                                                [ 89%]
tests/io/product/test_sidd_schema.py ........                                                                                                                                                                                                                                                                                      [ 92%]
tests/io/product/test_sidd_writing.py s                                                                                                                                                                                                                                                                                            [ 92%]
tests/io/received/test_crsd.py s                                                                                                                                                                                                                                                                                                   [ 92%]
tests/visualization/test_remap.py ....................                                                                                                                                                                                                                                                                             [100%]

============================================================================================================================================================ warnings summary ============================================================================================================================================================
tests/geometry/test_point_projection.py::test_image_to_ground_errors
tests/geometry/test_point_projection.py::test_image_to_ground_dem
  /home/vscuser/miniconda3/envs/sarpy36/lib/python3.6/site-packages/sarpy-1.3.42-py3.6.egg/sarpy/geometry/point_projection.py:1903: RuntimeWarning: divide by zero encountered in double_scalars
    lon_grid_size = min(10, lat_grid_size/abs(numpy.sin(numpy.deg2rad(ref_llh[0]))))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================================================================================================================== 258 passed, 21 skipped, 2 warnings in 19.64s ==============================================================================================================================================

3.8
========================================================================================================================================================== test session starts ===========================================================================================================================================================
platform linux -- Python 3.8.16, pytest-7.3.1, pluggy-1.0.0
rootdir: /home/vscuser/git/glweb/software/third-party/sarpy
collected 279 items                                                                                                                                                                                                                                                                                                                      

tests/test_class_string.py .                                                                                                                                                                                                                                                                                                       [  0%]
tests/consistency/test_consistency.py ........                                                                                                                                                                                                                                                                                     [  3%]
tests/consistency/test_cphd_consistency.py ..............................................................                                                                                                                                                                                                                          [ 25%]
tests/geometry/test_geocoords.py ..........                                                                                                                                                                                                                                                                                        [ 29%]
tests/geometry/test_geometry_elements.py ..........                                                                                                                                                                                                                                                                                [ 32%]
tests/geometry/test_latlon.py ...                                                                                                                                                                                                                                                                                                  [ 33%]
tests/geometry/test_point_projection.py ............                                                                                                                                                                                                                                                                               [ 37%]
tests/io/DEM/test_geoid.py s                                                                                                                                                                                                                                                                                                       [ 38%]
tests/io/DEM/test_geotiff1deg_list.py ....                                                                                                                                                                                                                                                                                         [ 39%]
tests/io/DEM/test_geotiff1deg_reader.py .ss..ss.                                                                                                                                                                                                                                                                                   [ 42%]
tests/io/complex/test_reader.py sssssssssss                                                                                                                                                                                                                                                                                        [ 46%]
tests/io/complex/test_remote.py .                                                                                                                                                                                                                                                                                                  [ 46%]
tests/io/complex/test_sicd.py s                                                                                                                                                                                                                                                                                                    [ 47%]
tests/io/complex/test_utils.py .                                                                                                                                                                                                                                                                                                   [ 47%]
tests/io/complex/sicd_elements/test_sicd_elements_errorstatistics.py .                                                                                                                                                                                                                                                             [ 48%]
tests/io/complex/sicd_elements/test_sicd_elements_grid.py ..                                                                                                                                                                                                                                                                       [ 48%]
tests/io/complex/sicd_elements/test_sicd_elements_imagedata.py .                                                                                                                                                                                                                                                                   [ 49%]
tests/io/complex/sicd_elements/test_sicd_elements_imageformation.py ......                                                                                                                                                                                                                                                         [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_matchinfo.py .                                                                                                                                                                                                                                                                   [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_pfa.py .                                                                                                                                                                                                                                                                         [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_radarcollection.py ..............                                                                                                                                                                                                                                                [ 56%]
tests/io/complex/sicd_elements/test_sicd_elements_radiometric.py .                                                                                                                                                                                                                                                                 [ 57%]
tests/io/complex/sicd_elements/test_sicd_elements_rgazcomp.py .                                                                                                                                                                                                                                                                    [ 57%]
tests/io/complex/sicd_elements/test_sicd_elements_scpcoa.py ...................                                                                                                                                                                                                                                                    [ 64%]
tests/io/complex/sicd_elements/test_sicd_elements_sicd.py ..................................                                                                                                                                                                                                                                       [ 76%]
tests/io/complex/sicd_elements/test_sicd_elements_timeline.py .....                                                                                                                                                                                                                                                                [ 78%]
tests/io/complex/sicd_elements/test_sicd_elements_utils.py ...                                                                                                                                                                                                                                                                     [ 79%]
tests/io/general/test_base.py ...                                                                                                                                                                                                                                                                                                  [ 80%]
tests/io/general/test_data_segment.py ..........                                                                                                                                                                                                                                                                                   [ 84%]
tests/io/general/test_format_function.py .......                                                                                                                                                                                                                                                                                   [ 86%]
tests/io/general/test_nitf_headers.py s                                                                                                                                                                                                                                                                                            [ 87%]
tests/io/general/test_tre.py .                                                                                                                                                                                                                                                                                                     [ 87%]
tests/io/phase_history/test_cphd.py .                                                                                                                                                                                                                                                                                              [ 87%]
tests/io/phase_history/cphd1_elements/test_utils.py .                                                                                                                                                                                                                                                                              [ 88%]
tests/io/product/test_reader.py ..s                                                                                                                                                                                                                                                                                                [ 89%]
tests/io/product/test_sidd_schema.py ........                                                                                                                                                                                                                                                                                      [ 92%]
tests/io/product/test_sidd_writing.py s                                                                                                                                                                                                                                                                                            [ 92%]
tests/io/received/test_crsd.py s                                                                                                                                                                                                                                                                                                   [ 92%]
tests/visualization/test_remap.py ....................                                                                                                                                                                                                                                                                             [100%]

============================================================================================================================================================ warnings summary ============================================================================================================================================================
tests/test_class_string.py::TestClassString::test_class_str
  /home/vscuser/miniconda3/envs/sarpy38/lib/python3.8/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

tests/test_class_string.py::TestClassString::test_class_str
  /home/vscuser/miniconda3/envs/sarpy38/lib/python3.8/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

tests/geometry/test_point_projection.py::test_image_to_ground_errors
tests/geometry/test_point_projection.py::test_image_to_ground_dem
  /home/vscuser/miniconda3/envs/sarpy38/lib/python3.8/site-packages/sarpy-1.3.42-py3.8.egg/sarpy/geometry/point_projection.py:1903: RuntimeWarning: divide by zero encountered in scalar divide
    lon_grid_size = min(10, lat_grid_size/abs(numpy.sin(numpy.deg2rad(ref_llh[0]))))

tests/visualization/test_remap.py::TestRemap::test_LUTRemap_matplotlib
tests/visualization/test_remap.py::TestRemap::test_remap_names
tests/visualization/test_remap.py::TestRemap::test_remap_names
tests/visualization/test_remap.py::TestRemap::test_remap_names
tests/visualization/test_remap.py::TestRemap::test_remap_names
  /home/vscuser/miniconda3/envs/sarpy38/lib/python3.8/site-packages/sarpy-1.3.42-py3.8.egg/sarpy/visualization/remap.py:1562: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap(obj
)`` instead.                                                                                                                                                                                                                                                                                                                                  cmap = cm.get_cmap(value, max_out_size+1)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================================================================== 258 passed, 21 skipped, 9 warnings in 18.75s ==============================================================================================================================================

3.10
========================================================================================================================================================== test session starts ===========================================================================================================================================================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0
rootdir: /home/vscuser/git/glweb/software/third-party/sarpy
collected 279 items                                                                                                                                                                                                                                                                                                                      

tests/test_class_string.py .                                                                                                                                                                                                                                                                                                       [  0%]
tests/consistency/test_consistency.py ........                                                                                                                                                                                                                                                                                     [  3%]
tests/consistency/test_cphd_consistency.py ..............................................................                                                                                                                                                                                                                          [ 25%]
tests/geometry/test_geocoords.py ..........                                                                                                                                                                                                                                                                                        [ 29%]
tests/geometry/test_geometry_elements.py ..........                                                                                                                                                                                                                                                                                [ 32%]
tests/geometry/test_latlon.py ...                                                                                                                                                                                                                                                                                                  [ 33%]
tests/geometry/test_point_projection.py ............                                                                                                                                                                                                                                                                               [ 37%]
tests/io/DEM/test_geoid.py s                                                                                                                                                                                                                                                                                                       [ 38%]
tests/io/DEM/test_geotiff1deg_list.py ....                                                                                                                                                                                                                                                                                         [ 39%]
tests/io/DEM/test_geotiff1deg_reader.py .ss..ss.                                                                                                                                                                                                                                                                                   [ 42%]
tests/io/complex/test_reader.py sssssssssss                                                                                                                                                                                                                                                                                        [ 46%]
tests/io/complex/test_remote.py .                                                                                                                                                                                                                                                                                                  [ 46%]
tests/io/complex/test_sicd.py s                                                                                                                                                                                                                                                                                                    [ 47%]
tests/io/complex/test_utils.py .                                                                                                                                                                                                                                                                                                   [ 47%]
tests/io/complex/sicd_elements/test_sicd_elements_errorstatistics.py .                                                                                                                                                                                                                                                             [ 48%]
tests/io/complex/sicd_elements/test_sicd_elements_grid.py ..                                                                                                                                                                                                                                                                       [ 48%]
tests/io/complex/sicd_elements/test_sicd_elements_imagedata.py .                                                                                                                                                                                                                                                                   [ 49%]
tests/io/complex/sicd_elements/test_sicd_elements_imageformation.py ......                                                                                                                                                                                                                                                         [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_matchinfo.py .                                                                                                                                                                                                                                                                   [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_pfa.py .                                                                                                                                                                                                                                                                         [ 51%]
tests/io/complex/sicd_elements/test_sicd_elements_radarcollection.py ..............                                                                                                                                                                                                                                                [ 56%]
tests/io/complex/sicd_elements/test_sicd_elements_radiometric.py .                                                                                                                                                                                                                                                                 [ 57%]
tests/io/complex/sicd_elements/test_sicd_elements_rgazcomp.py .                                                                                                                                                                                                                                                                    [ 57%]
tests/io/complex/sicd_elements/test_sicd_elements_scpcoa.py ...................                                                                                                                                                                                                                                                    [ 64%]
tests/io/complex/sicd_elements/test_sicd_elements_sicd.py ..................................                                                                                                                                                                                                                                       [ 76%]
tests/io/complex/sicd_elements/test_sicd_elements_timeline.py .....                                                                                                                                                                                                                                                                [ 78%]
tests/io/complex/sicd_elements/test_sicd_elements_utils.py ...                                                                                                                                                                                                                                                                     [ 79%]
tests/io/general/test_base.py ...                                                                                                                                                                                                                                                                                                  [ 80%]
tests/io/general/test_data_segment.py ..........                                                                                                                                                                                                                                                                                   [ 84%]
tests/io/general/test_format_function.py .......                                                                                                                                                                                                                                                                                   [ 86%]
tests/io/general/test_nitf_headers.py s                                                                                                                                                                                                                                                                                            [ 87%]
tests/io/general/test_tre.py .                                                                                                                                                                                                                                                                                                     [ 87%]
tests/io/phase_history/test_cphd.py .                                                                                                                                                                                                                                                                                              [ 87%]
tests/io/phase_history/cphd1_elements/test_utils.py .                                                                                                                                                                                                                                                                              [ 88%]
tests/io/product/test_reader.py ..s                                                                                                                                                                                                                                                                                                [ 89%]
tests/io/product/test_sidd_schema.py ........                                                                                                                                                                                                                                                                                      [ 92%]
tests/io/product/test_sidd_writing.py s                                                                                                                                                                                                                                                                                            [ 92%]
tests/io/received/test_crsd.py s                                                                                                                                                                                                                                                                                                   [ 92%]
tests/visualization/test_remap.py ....................                                                                                                                                                                                                                                                                             [100%]

============================================================================================================================================================ warnings summary ============================================================================================================================================================
tests/test_class_string.py::TestClassString::test_class_str
  /home/vscuser/miniconda3/envs/sarpy/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

tests/test_class_string.py::TestClassString::test_class_str
  /home/vscuser/miniconda3/envs/sarpy/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

tests/geometry/test_point_projection.py::test_image_to_ground_errors
tests/geometry/test_point_projection.py::test_image_to_ground_dem
  /home/vscuser/miniconda3/envs/sarpy/lib/python3.10/site-packages/sarpy-1.3.42-py3.10.egg/sarpy/geometry/point_projection.py:1903: RuntimeWarning: divide by zero encountered in scalar divide
    lon_grid_size = min(10, lat_grid_size/abs(numpy.sin(numpy.deg2rad(ref_llh[0]))))

tests/visualization/test_remap.py::TestRemap::test_LUTRemap_matplotlib
tests/visualization/test_remap.py::TestRemap::test_remap_names
tests/visualization/test_remap.py::TestRemap::test_remap_names
tests/visualization/test_remap.py::TestRemap::test_remap_names
tests/visualization/test_remap.py::TestRemap::test_remap_names
  /home/vscuser/miniconda3/envs/sarpy/lib/python3.10/site-packages/sarpy-1.3.42-py3.10.egg/sarpy/visualization/remap.py:1562: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap(obj
)`` instead.                                                                                                                                                                                                                                                                                                                                  cmap = cm.get_cmap(value, max_out_size+1)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================================================================== 258 passed, 21 skipped, 9 warnings in 18.62s ==============================================================================================================================================

@Darder Darder merged commit 2cfc6ed into ngageoint:master Jun 9, 2023
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.

None yet

2 participants