{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astroplan/issues/81","labels_url":"https://api.github.com/repos/astropy/astroplan/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astroplan/issues/81/comments","events_url":"https://api.github.com/repos/astropy/astroplan/issues/81/events","html_url":"https://github.com/astropy/astroplan/issues/81","id":103784544,"number":81,"title":"Failing test_image_example","user":{"login":"bsipocz","id":6788290,"avatar_url":"https://avatars.githubusercontent.com/u/6788290?v=3","gravatar_id":"","url":"https://api.github.com/users/bsipocz","html_url":"https://github.com/bsipocz","followers_url":"https://api.github.com/users/bsipocz/followers","following_url":"https://api.github.com/users/bsipocz/following{/other_user}","gists_url":"https://api.github.com/users/bsipocz/gists{/gist_id}","starred_url":"https://api.github.com/users/bsipocz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsipocz/subscriptions","organizations_url":"https://api.github.com/users/bsipocz/orgs","repos_url":"https://api.github.com/users/bsipocz/repos","events_url":"https://api.github.com/users/bsipocz/events{/privacy}","received_events_url":"https://api.github.com/users/bsipocz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/astropy/astroplan/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/astropy/astroplan/milestones/2","html_url":"https://github.com/astropy/astroplan/milestones/0.2%20release","labels_url":"https://api.github.com/repos/astropy/astroplan/milestones/2/labels","id":1087266,"number":2,"title":"0.2 release","description":"After GSoC and Astropy 1.1 release -> astroplan 0.2 release","creator":{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false},"open_issues":23,"closed_issues":11,"state":"open","created_at":"2015-04-28T11:35:54Z","updated_at":"2015-10-15T18:36:28Z","due_on":"2015-10-24T07:00:00Z","closed_at":null},"comments":7,"created_at":"2015-08-28T19:51:15Z","updated_at":"2015-10-15T19:13:27Z","closed_at":null,"body":"There is another test failing.\r\n\r\n```\r\n=========================================================== test session starts ============================================================\r\nplatform darwin -- Python 2.7.10 -- pytest-2.5.1\r\n\r\nRunning tests with Astropy version 1.1.dev13304.\r\nRunning tests in astroplan /Users/bsipocz/munka/devel/astroplan/docs.\r\n\r\nPlatform: Darwin-14.5.0-x86_64-i386-64bit\r\n\r\nExecutable: /Users/bsipocz/.virtualenvs/astropy-dev/bin/python\r\n\r\nFull Python Version: \r\n2.7.10 (default, May 26 2015, 20:29:34) \r\n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]\r\n\r\nencodings: sys: ascii, locale: UTF-8, filesystem: utf-8, unicode bits: 15\r\nbyteorder: little\r\nfloat info: dig: 15, mant_dig: 15\r\n\r\nNumpy: 1.9.2\r\nScipy: 0.16.0\r\nMatplotlib: 1.4.3\r\npyephem: not available\r\n____________________________________________________________ test_image_example ____________________________________________________________\r\n\r\nargs = (), kwargs = {}\r\nbaseline_dir = '/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroplan-test-qX407r/lib.macosx-10.10-x86_64-2.7/astroplan/plots/tests/baseline_images'\r\ninspect = <module 'inspect' from '/sw/lib/python2.7/inspect.pyc'>, fig = <matplotlib.figure.Figure object at 0x109d9f8d0>\r\nfilename = 'test_image_example.png', result_dir = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT'\r\ntest_image = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/test_image_example.png'\r\nbaseline_image_ref = '/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroplan-test-qX407r/lib.macosx-10.10-x86_64-2.7/astroplan/plots/tests/baseline_images/test_image_example.png'\r\nbaseline_image = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/baseline-test_image_example.png'\r\n\r\n    @wraps(item.function)\r\n    def item_function_wrapper(*args, **kwargs):\r\n    \r\n        baseline_dir = compare.kwargs.get('baseline_dir', None)\r\n        if baseline_dir is None:\r\n            if self.baseline_dir is None:\r\n                baseline_dir = os.path.join(os.path.dirname(item.fspath.strpath), 'baseline')\r\n            else:\r\n                baseline_dir = self.baseline_dir\r\n        else:\r\n            baseline_dir = os.path.join(os.path.dirname(item.fspath.strpath), baseline_dir)\r\n    \r\n        # Run test and get figure object\r\n        import inspect\r\n        if inspect.ismethod(original):  # method\r\n            fig = original(*args[1:], **kwargs)\r\n        else:  # function\r\n            fig = original(*args, **kwargs)\r\n    \r\n        # Find test name to use as plot name\r\n        filename = compare.kwargs.get('filename', None)\r\n        if filename is None:\r\n            filename = original.__name__ + '.png'\r\n    \r\n        # What we do now depends on whether we are generating the reference\r\n        # images or simply running the test.\r\n        if self.generate_dir is None:\r\n    \r\n            # Save the figure\r\n            result_dir = tempfile.mkdtemp()\r\n            test_image = os.path.abspath(os.path.join(result_dir, filename))\r\n    \r\n            fig.savefig(test_image, **savefig_kwargs)\r\n    \r\n            # Find path to baseline image\r\n            baseline_image_ref = os.path.abspath(os.path.join(os.path.dirname(item.fspath.strpath), baseline_dir, filename))\r\n    \r\n            if not os.path.exists(baseline_image_ref):\r\n                raise Exception(\"\"\"Image file not found for comparison test\r\n                                        Generated Image:\r\n                                        \\t{test}\r\n                                        This is expected for new tests.\"\"\".format(\r\n                    test=test_image))\r\n    \r\n            # distutils may put the baseline images in non-accessible places,\r\n            # copy to our tmpdir to be sure to keep them in case of failure\r\n            baseline_image = os.path.abspath(os.path.join(result_dir, 'baseline-' + filename))\r\n            shutil.copyfile(baseline_image_ref, baseline_image)\r\n    \r\n>           msg = compare_images(baseline_image, test_image, tol=tolerance)\r\n\r\n/sw/lib/python2.7/site-packages/pytest_mpl/plugin.py:141: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\n\r\nexpected = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/baseline-test_image_example.png'\r\nactual = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/test_image_example.png', tol = 2, in_decorator = False\r\n\r\n    def compare_images(expected, actual, tol, in_decorator=False):\r\n        \"\"\"\r\n        Compare two \"image\" files checking differences within a tolerance.\r\n    \r\n        The two given filenames may point to files which are convertible to\r\n        PNG via the `.converter` dictionary. The underlying RMS is calculated\r\n        with the `.calculate_rms` function.\r\n    \r\n        Parameters\r\n        ----------\r\n        expected : str\r\n            The filename of the expected image.\r\n        actual :str\r\n            The filename of the actual image.\r\n        tol : float\r\n            The tolerance (a color value difference, where 255 is the\r\n            maximal difference).  The test fails if the average pixel\r\n            difference is greater than this value.\r\n        in_decorator : bool\r\n            If called from image_comparison decorator, this should be\r\n            True. (default=False)\r\n    \r\n        Example\r\n        -------\r\n        img1 = \"./baseline/plot.png\"\r\n        img2 = \"./output/plot.png\"\r\n        compare_images( img1, img2, 0.001 ):\r\n    \r\n        \"\"\"\r\n        if not os.path.exists(actual):\r\n            msg = \"Output image %s does not exist.\" % actual\r\n            raise Exception(msg)\r\n    \r\n        if os.stat(actual).st_size == 0:\r\n            msg = \"Output image file %s is empty.\" % actual\r\n            raise Exception(msg)\r\n    \r\n        verify(actual)\r\n    \r\n        # Convert the image to png\r\n        extension = expected.split('.')[-1]\r\n    \r\n        if not os.path.exists(expected):\r\n            raise IOError('Baseline image %r does not exist.' % expected)\r\n    \r\n        if extension != 'png':\r\n            actual = convert(actual, False)\r\n            expected = convert(expected, True)\r\n    \r\n        # open the image files and remove the alpha channel (if it exists)\r\n        expectedImage = _png.read_png_int(expected)\r\n        actualImage = _png.read_png_int(actual)\r\n        expectedImage = expectedImage[:, :, :3]\r\n        actualImage = actualImage[:, :, :3]\r\n    \r\n        actualImage, expectedImage = crop_to_same(\r\n            actual, actualImage, expected, expectedImage)\r\n    \r\n        # convert to signed integers, so that the images can be subtracted without\r\n        # overflow\r\n        expectedImage = expectedImage.astype(np.int16)\r\n        actualImage = actualImage.astype(np.int16)\r\n    \r\n>       rms = calculate_rms(expectedImage, actualImage)\r\n\r\n/sw/lib/python2.7/site-packages/matplotlib/testing/compare.py:326: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\n\r\nexpectedImage = array([[[255, 255, 255],\r\n        [255, 255, 255],\r\n        [255, 255, 255],\r\n   ...55, 255, 255],\r\n        [255, 255, 255],\r\n        [255, 255, 255]]], dtype=int16)\r\nactualImage = array([[[255, 255, 255],\r\n        [255, 255, 255],\r\n        [255, 255, 255],\r\n   ...55, 255, 255],\r\n        [255, 255, 255],\r\n        [255, 255, 255]]], dtype=int16)\r\n\r\n    def calculate_rms(expectedImage, actualImage):\r\n        \"Calculate the per-pixel errors, then compute the root mean square error.\"\r\n        num_values = np.prod(expectedImage.shape)\r\n>       abs_diff_image = abs(expectedImage - actualImage)\r\nE       ValueError: operands could not be broadcast together with shapes (600,800,3) (660,880,3)\r\n\r\n/sw/lib/python2.7/site-packages/matplotlib/testing/compare.py:246: ValueError\r\n```"},"comment":{"url":"https://api.github.com/repos/astropy/astroplan/issues/comments/148492037","html_url":"https://github.com/astropy/astroplan/issues/81#issuecomment-148492037","issue_url":"https://api.github.com/repos/astropy/astroplan/issues/81","id":148492037,"user":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T19:13:27Z","updated_at":"2015-10-15T19:13:27Z","body":"@bmorris3 - I have a solution, in my head, I just haven't had a chance to implement it yet ;)\r\n\r\nThough actually for now, you can emulate this solution by resetting the rc parameters to the default at the start of the test:\r\n\r\n```\r\nplt.rcParams.clear()\r\nplt.rcParams.update(plt.rcParamsDefault)\r\n```"}}