Esempio n. 1
0
    def _read_dither(self, dither_file):
        """
        Read the relative dither position

        Parameters
        ----------
        dither_file : string
            file containing the dither relative position. If None a single
            dither added
        """
        with open(dither_file, 'r') as f:
            f = ft.skip_comments(f)
            for l in f:
                try:
                    _bn, _d, _x, _y, _seeing, _norm, _airmass = l.split()
                except ValueError:  # skip empty or incomplete lines
                    pass
                try:
                    _d = list(set(re.findall(r'D\d', _d)))[0]
                except IndexError:
                    msg = "While extracting the dither number from the"
                    msg += " basename in the dither file, {} matches to"
                    msg += " 'D\\d' expression where found. I expected"
                    msg += " one. What should I do?"
                    raise DitherParseError(msg.format(len(_d)))
                self.basename[_d] = _bn
                self.dx[_d] = float(_x)
                self.dy[_d] = float(_y)
                self.seeing[_d] = float(_seeing)
                self.norm[_d] = float(_norm)
                self.airmass[_d] = float(_airmass)
Esempio n. 2
0
def test_skip_comments_files(datadir, fname, next_line):
    '''make sure that line endings are handled properly'''
    with datadir.join(fname).open('r') as f:
        f = ft.skip_comments(f)
        line = f.readline()
    assert next_line in line
    assert line.endswith('\n')
Esempio n. 3
0
def test_skip_comments(text, next_line):
    '''Skipping comments'''
    f = six.StringIO(text)

    f = ft.skip_comments(f)

    line = f.readline()
    assert line == next_line
Esempio n. 4
0
def test_skip_all_comments_files(tmpdir):
    '''make sure that a file with all commented lines is properly handled'''
    cfile = tmpdir.join('all_comments.txt')
    cfile.write('# a comment\n# an other one')

    with cfile.open('r') as f:
        f = ft.skip_comments(f)
        line = f.read(10)

    assert not line
Esempio n. 5
0
    def _read_header(self, f):
        """
        Parameters
        ----------
        f : file object
            file object to parse

        Returns
        -------
        f : file object
            file object after consuming the header
        """
        # Try to determine the IFU ID from the header
        while True:
            line = f.readline().strip()
            if not line.startswith('#'):
                raise IFUCenterError('Failed to find IFU bundle ID in '
                                     'file header')

            line = line[1:].strip()

            if not line.startswith('IFU ') and not line.startswith('VIFU'):
                continue

            self.ifuid = int(line[4:])
            # Read remaining comment lines
            f = ft.skip_comments(f)
            break

        # get the fiber diameter and fiber separation
        line = f.readline()
        self.fiber_d, self.fiber_sep = [float(i) for i in line.split()]
        # get the number of fibers in the x and y direction
        f = ft.skip_comments(f)
        line = f.readline()
        self.nfibx, self.nfiby = [int(i) for i in line.split()]
        f = ft.skip_comments(f)
        return f