MetOffice / CATNIP

Climate Analysis Tool: Now In Python
Other
5 stars 2 forks source link

test visualisation.py #118

Open zmaalick opened 4 years ago

nhsavage commented 3 years ago

The approach iris uses for comparing graphics is here https://github.com/SciTools/iris/blob/077df3ec15530255df80c2fc330eb21998e24769/lib/iris/tests/__init__.py#L823

nhsavage commented 3 years ago

in ants: https://code.metoffice.gov.uk/trac/ancil/browser/ants/trunk/lib/ants/tests/__init__.py#L554

nhsavage commented 3 years ago

There are two functions in this module: vector_plot and plot_regress. The aim is to compare the figure created by these routines (without saving to disk) to a KGO image using the imagehash library.

Steps:

  1. generate good image and store in repo
  2. add imagehash to dependencies (already in software stack at MO)
  3. call the routines with the same data and options as used to generate the KGO
  4. compare the figure generated with the KGO image based on the ANTS use of imagehash

Each of these will have several images to be tested, as there are multiple options to be tested, In the case of visualiastion,py significant more thought is needed to make this code safe (checking u and v in correct order, failing if it can't find a single X axis not printing an error, etc. This (and the tests for the new checks) should be on a different ticket

zmaalick commented 3 years ago

Some important references:

https://towardsdatascience.com/unit-testing-python-data-visualizations-18e0250430 https://stackoverflow.com/questions/42996199/turn-off-graphs-while-running-unittests/43000569 https://matplotlib.org/3.1.0/api/testing_api.html

nhsavage commented 3 years ago

157 has been opened to cover the additional tests to vector_plot.

nhsavage commented 3 years ago

suggestion from https://pysource.com/2018/07/19/check-if-two-images-are-equal-with-opencv-and-python/