コード例 #1
0
def test_userregions():
    """ Run the parameter setup script
    """
    regions = [":10", "30:60", "80:", ":10,35:65,80:", "10:20;", "10:20,"]
    result = [[np.array([], dtype=int),
               np.array([99], dtype=int)],
              [np.array([299], dtype=int),
               np.array([598], dtype=int)],
              [np.array([798], dtype=int),
               np.array([], dtype=int)],
              [
                  np.array([349, 798], dtype=int),
                  np.array([99, 648], dtype=int)
              ], [], [np.array([99], dtype=int),
                      np.array([199], dtype=int)]]
    resstat = [0, 0, 0, 0, 1, 2]
    nslits = 2
    maxsl = 100
    for rr, reg in enumerate(regions):
        status, regs = skysub.read_userregions(reg,
                                               nslits,
                                               maxslitlength=maxsl)
        if status != 1:
            assert (len(regs) == nslits)
            assert (np.array_equal(
                np.where(regs[0][1:] & ~regs[0][:-1])[0], result[rr][0]))
            assert (np.array_equal(
                np.where(~regs[0][1:] & regs[0][:-1])[0], result[rr][1]))
        assert (status == resstat[rr])
コード例 #2
0
ファイル: test_skysub.py プロジェクト: broulston/PypeIt
def test_userregions():
    """ Run the parameter setup script
    """
    regions = [":10", "30:60", "80:", ":10,35:65,80:", "10:20;", "10:20,"]
    result = [[[0, 100]], [[300, 599]], [[799, 1000]],
              [[0, 100], [350, 649], [799, 1000]], [], [[100, 200]]]
    resstat = [0, 0, 0, 0, 1, 2]
    for rr, reg in enumerate(regions):
        status, regs = skysub.read_userregions(reg, resolution=1000)
        assert (regs == result[rr])
        assert (status == resstat[rr])
コード例 #3
0
def test_generatemask():
    maxsl = 1000
    nslits = 2
    reg = "80:"
    tstmsk = np.zeros((1000, 1000))
    tstmsk[:, 744:901] = 1
    status, regs = skysub.read_userregions(reg, nslits, maxslitlength=maxsl)
    slits = SlitTraceSet(left_init=np.full((1000, 1), 120, dtype=float),
                         right_init=np.full((1000, 1), 900, dtype=float),
                         binspec=1,
                         binspat=1,
                         pypeline='IFU',
                         nspat=1000,
                         PYP_SPEC='dummy')
    skymask = skysub.generate_mask("IFU", regs, slits, slits.left_init,
                                   slits.right_init)
    assert (np.array_equal(skymask, tstmsk))
コード例 #4
0
ファイル: skysub_regions.py プロジェクト: tbowers7/PypeIt
    def button_regb(self, event):
        """Allow for text to be entered in the terminal. If the
        text is valid, and then apply to all slits. The text should
        be a comma separated list of percentages to apply to all slits
        Example: The following string   :10, 35:65, 80:
        would select the first 10%, the inner 30%, and the final 20% of all slits

        Args:
            event : Event
                A matplotlib event instance
        """
        self.update_infobox(
            message='Enter regions in the terminal (see terminal for help)',
            yesno=False)
        print("")
        self.region_help()
        print("To exit this tool, enter no text, and press enter.")
        while True:
            print("")
            text = input("Enter the regions: ")
            status, reg = skysub.read_userregions(text, self._nslits,
                                                  self._maxslitlength)
            if status == 0:
                print("Regions parsed successfully")
                for rr in range(len(reg)):
                    # Apply to all slits
                    for sl in range(self._nslits):
                        self._skyreg[sl] = reg[rr].copy()
                self.replot()
                break
            elif status == 1:
                print(
                    'Region definition should be a comma-separated list of percentages (see help)'
                )
            elif status == 2:
                print(
                    'Region definition should contain a semi-colon (see help)')
            # Break out of the loop if no text is entered
            if len(text.strip()) == 0: break
        return