from autolens.pipeline import tagging

class TestPhaseTag:

    def test__mixture_of_values(self):

        phase_tag = tagging.phase_tag_from_phase_settings(sub_grid_size=2,
                                                          bin_up_factor=None,
                                                          image_psf_shape=None,
                                                          inversion_psf_shape=None,
                                                          inner_mask_radii=0.3,
                                                          positions_threshold=2.0,
                                                          interp_pixel_scale=None)


        assert phase_tag == '_sub_2_pos_2.00_inner_mask_0.30'

        phase_tag = tagging.phase_tag_from_phase_settings(sub_grid_size=1,
                                                          bin_up_factor=3,
                                                          image_psf_shape=(2, 2),
                                                          inversion_psf_shape=(3,3),
                                                          inner_mask_radii=None,
                                                          positions_threshold=None,
                                                          interp_pixel_scale=0.2)

        assert phase_tag == '_sub_1_bin_up_3_image_psf_2x2_inversion_psf_3x3_interp_0.200'

class TestTaggers:

    def test__positions_threshold_tagger(self):

        tag = tagging.positions_threshold_tag_from_positions_threshold(positions_threshold=None)
        assert tag == ''
        tag = tagging.positions_threshold_tag_from_positions_threshold(positions_threshold=1.0)
        assert tag == '_pos_1.00'
        tag = tagging.positions_threshold_tag_from_positions_threshold(positions_threshold=2.56)
        assert tag == '_pos_2.56'

    def test__inner_circular_mask_radii_tagger(self):

        tag = tagging.inner_mask_radii_tag_from_inner_circular_mask_radii(inner_mask_radii=None)
        assert tag == ''
        tag = tagging.inner_mask_radii_tag_from_inner_circular_mask_radii(inner_mask_radii=0.2)
        print(tag)
        assert tag == '_inner_mask_0.20'
        tag = tagging.inner_mask_radii_tag_from_inner_circular_mask_radii(inner_mask_radii=3)
        assert tag == '_inner_mask_3.00'

    def test__sub_grid_size_tagger(self):

        tag = tagging.sub_grid_size_tag_from_sub_grid_size(sub_grid_size=1)
        assert tag == '_sub_1'
        tag = tagging.sub_grid_size_tag_from_sub_grid_size(sub_grid_size=2)
        assert tag == '_sub_2'
        tag = tagging.sub_grid_size_tag_from_sub_grid_size(sub_grid_size=4)
        assert tag == '_sub_4'

    def test__bin_up_factor_tagger(self):

        tag = tagging.bin_up_factor_tag_from_bin_up_factor(bin_up_factor=None)
        assert tag == ''
        tag = tagging.bin_up_factor_tag_from_bin_up_factor(bin_up_factor=1)
        assert tag == ''
        tag = tagging.bin_up_factor_tag_from_bin_up_factor(bin_up_factor=2)
        assert tag == '_bin_up_2'
        tag = tagging.bin_up_factor_tag_from_bin_up_factor(bin_up_factor=3)
        assert tag == '_bin_up_3'

    def test__image_psf_shape_tagger(self):

        tag = tagging.image_psf_shape_tag_from_image_psf_shape(image_psf_shape=None)
        assert tag == ''
        tag = tagging.image_psf_shape_tag_from_image_psf_shape(image_psf_shape=(2,2))
        print(tag.strip())
        assert tag == '_image_psf_2x2'
        tag = tagging.image_psf_shape_tag_from_image_psf_shape(image_psf_shape=(3,4))
        assert tag == '_image_psf_3x4'

    def test__inversion_psf_shape_tagger(self):

        tag = tagging.inversion_psf_shape_tag_from_inversion_psf_shape(inversion_psf_shape=None)
        assert tag == ''
        tag = tagging.inversion_psf_shape_tag_from_inversion_psf_shape(inversion_psf_shape=(2,2))
        print(tag.strip())
        assert tag == '_inversion_psf_2x2'
        tag = tagging.inversion_psf_shape_tag_from_inversion_psf_shape(inversion_psf_shape=(3,4))
        assert tag == '_inversion_psf_3x4'

    def test__interp_pixel_scale_tagger(self):

        tag = tagging.interp_pixel_scale_tag_from_interp_pixel_scale(interp_pixel_scale=None)
        assert tag == ''
        tag = tagging.interp_pixel_scale_tag_from_interp_pixel_scale(interp_pixel_scale=0.5)
        assert tag == '_interp_0.500'
        tag = tagging.interp_pixel_scale_tag_from_interp_pixel_scale(interp_pixel_scale=0.25)
        assert tag == '_interp_0.250'
        tag = tagging.interp_pixel_scale_tag_from_interp_pixel_scale(interp_pixel_scale=0.234)
        assert tag == '_interp_0.234'