示例#1
0
    def test_classify_image_mean_var_file():
        """Classify an image from files using mean and variance."""
        local = os.path.dirname(os.path.abspath(__file__))

        example.get_sample(local)

        h, j, v, z = [os.path.join(local, f"{b}.fits") for b in "hjvz"]

        Classifier.classify(h=h,
                            j=j,
                            v=v,
                            z=z,
                            out_dir=local,
                            out_type="mean_var")

        outs = dh.get_expected_morpheus_output(out_type="mean_var")

        for k in outs:

            np.testing.assert_allclose(
                outs[k],
                fits.getdata(os.path.join(local, f"{k}.fits")),
                atol=1e-5,
                err_msg=f"{k} failed comparison",
            )

            os.remove(os.path.join(local, f"{k}.fits"))

        for b in "hjvz":
            os.remove(os.path.join(local, f"{b}.fits"))
示例#2
0
    def test_classify_mean_var_parallel_cpu():
        """Classify an image in parallel with two cpus."""
        local = os.path.dirname(os.path.abspath(__file__))
        os.mkdir(os.path.join(local, "output"))
        out_dir = os.path.join(local, "output")

        example.get_sample(local)
        h, j, v, z = [os.path.join(local, f"{b}.fits") for b in "hjvz"]

        outs = dh.get_expected_morpheus_output(out_type="mean_var")

        classified = Classifier.classify(
            h=h,
            j=j,
            v=v,
            z=z,
            out_dir=out_dir,
            out_type="mean_var",
            cpus=2,
            parallel_check_interval=0.25,  # check every 15 seconds
        )

        for k in outs:
            np.testing.assert_allclose(outs[k],
                                       classified[k],
                                       atol=1e-5,
                                       err_msg=f"{k} failed comparison")

        shutil.rmtree(out_dir)

        for b in [h, j, v, z]:
            os.remove(b)
示例#3
0
    def test_sample_data_return():
        """Tests sample_data function returning arrays."""
        arrs = example.get_sample()

        expected_shape = (144, 144)
        for i in range(4):
            assert expected_shape == arrs[i].shape
示例#4
0
    def test_sample_data_save():
        """Tests sample_data function saving to file."""
        local = os.path.dirname(os.path.abspath(__file__))

        example.get_sample(local)

        names = [f"{b}.fits" for b in ["h", "j", "v", "z"]]

        arrs = []
        for name in names:
            f_loc = os.path.join(local, name)
            arrs.append(fits.getdata(f_loc))
            os.remove(f_loc)

        expected_shape = (144, 144)
        for i in range(4):
            assert expected_shape == arrs[i].shape
示例#5
0
    def test_segmap_from_classified_fails():
        """Test the segmap_from_classified method."""

        data = dh.get_expected_morpheus_output()
        h, _, _, _ = example.get_sample()
        mask = np.zeros_like(h, dtype=np.int)
        mask[5:-5, 5:-5] = 1

        with pytest.raises(ValueError):
            Classifier.segmap_from_classified(data, h, mask=mask, bkg_src_threshold=1.0)
示例#6
0
    def test_catalog_from_classified():
        """Test the catalog_from_classified method."""

        classified = dh.get_expected_morpheus_output()
        h, _, _, _ = example.get_sample()
        segmap = dh.get_expected_segmap()["segmap"]

        expected_catalog = dh.get_expected_catalog()["catalog"]

        actual_catalog = Classifier.catalog_from_classified(classified, h, segmap)

        assert expected_catalog == actual_catalog
示例#7
0
    def test_classify_image_rank_vote_in_mem():
        """Classify an image in memory using rank vote."""
        h, j, v, z = example.get_sample()

        expected_outs = dh.get_expected_morpheus_output()

        outs = Classifier.classify(h=h, j=j, v=v, z=z, out_dir=None)

        for k in outs:
            np.testing.assert_allclose(outs[k],
                                       expected_outs[k],
                                       err_msg=f"{k} failed comparison")
示例#8
0
    def test_segmap_from_classified():
        """Test the segmap_from_classified method."""

        data = dh.get_expected_morpheus_output()
        h, _, _, _ = example.get_sample()
        mask = np.zeros_like(h, dtype=np.int)
        mask[5:-5, 5:-5] = 1

        expected_segmap = dh.get_expected_segmap()["segmap"]

        actual_segmap = Classifier.segmap_from_classified(data, h, mask=mask)

        np.testing.assert_array_equal(expected_segmap, actual_segmap)
示例#9
0
    def test_classify_image_mean_var():
        """Classify an image from files using mean and variance."""
        h, j, v, z = example.get_sample()

        outs = Classifier.classify(h=h, j=j, v=v, z=z, out_type="mean_var")

        expected_outs = dh.get_expected_morpheus_output(out_type="mean_var")

        for k in outs:
            np.testing.assert_allclose(outs[k],
                                       expected_outs[k],
                                       atol=1e-5,
                                       err_msg=f"{k} failed comparison")
示例#10
0
# Copyright 2018 Ryan Hausen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ==============================================================================
"""Simple classification example reading from disk."""

from morpheus.classifier import Classifier
from morpheus.data import example

# this saves the sample numpy arrays as FITS files in 'out_dir'
example.get_sample(out_dir=".")
h, j, v, z = [f"{band}.fits" for band in "hjvz"]

morphs = Classifier.classify(h=h, j=j, v=v, z=z)
示例#11
0
# MIT License
# Copyright 2018 Ryan Hausen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ==============================================================================
"""Simple classification example in memory."""

from morpheus.classifier import Classifier
from morpheus.data import example

h, j, v, z = example.get_sample()
morphs = Classifier.classify(h=h, j=j, v=v, z=z)