Ejemplo n.º 1
0
    def read_orbits(file_object, num_of_orbits):
        """Return list of orbits read from the file.

        Parameters
        ----------
        file_object : iterable
            file-like object

        num_of_orbits : int

        Returns
        -------
        orbits : list

        Raises
        ------
        RinexNavFileError
            on unexpected end of the file.
        """
        orbits = [None] * num_of_orbits
        for i in range(num_of_orbits):
            try:
                line = next(file_object)
            except StopIteration:
                msg = 'Unexpected end of the file.'
                raise RinexNavFileError(msg)
            orbits[i] = line.rstrip()
        return orbits
Ejemplo n.º 2
0
def rnx_nav(filename):
    """Возвращает объект RinexNavFile в зависимости от версии в файле.

    """
    version, file_type = RinexNavFileV2.retrieve_ver_type(filename)

    if version in {2.0, 2.01, 2.1, 2.11}:
        return RinexNavFileV2(filename)
    elif version in {3.0, 3.01, 3.02, 3.03, 3.04}:
        return RinexNavFileV3(filename)
    else:
        msg = 'Version {} is not supported.'.format(version)
        raise RinexNavFileError(msg)
Ejemplo n.º 3
0
    def parse_epoch(file_object):
        """Returns epoch components

        Parameters
        ----------
        file_object : file-like object

        Returns
        -------
        epoch_components : tuple
            (satellite_system, satellite_number, epoch, sv_clock)

        Raises
        ------
        EOFError
            on the end of the file.

        RinexNavFileError
            when it can't parse the epoch record.
        """
        try:
            line = next(file_object)
        except StopIteration:
            raise EOFError

        system = line[0]
        number = line[1:3]

        # month, day, hour, min, sec; year + ...
        epoch = [line[i:i + 3] for i in range(8, 23, 3)]
        epoch = [line[4:9]] + epoch

        sv_clock = [line[i:i + 19] for i in (23, 42, 61)]
        sv_clock = [i.lower().replace('d', 'e') for i in sv_clock]

        try:
            number = int(number)

            epoch = [int(i) for i in epoch]
            epoch = validate_epoch(epoch)

            sv_clock = [float(f) for f in sv_clock]

        except ValueError:
            msg = "Can't read epoch: {}.".format(line)
            raise RinexNavFileError(msg)

        return system, number, epoch, tuple(sv_clock)
Ejemplo n.º 4
0
    def parse_orbits(self, orbits, values_per_orbit):
        """Return navigation message. Message parsed from the orbits list
        according to values_per_orbit.

        Parameters
        ----------
        orbits : list
            list of 'broadcast orbit' records from coordinates file

        values_per_orbit : list


        Returns
        -------
        message : tuple

        Raises
        ------
        RinexNavFileError
            Can't parse the orbit record.

        """
        message = []

        # shortcuts
        ln = self.item_len
        start = self.orbit_start
        end = self.orbit_end

        for num, orbit in enumerate(orbits):
            values = []
            for i in range(start, end, ln):
                value = orbit[i:i + ln].rstrip().lower().replace('d', 'e')
                values.append(value)

            try:
                values = values[:values_per_orbit[num]]
                values = [s and float(s) or 0. for s in values]
            except ValueError:
                msg = "Can't parse the orbit: {}".format(orbit)
                raise RinexNavFileError(msg)

            message += values

        return tuple(message)
Ejemplo n.º 5
0
    def parse_epoch(file_object):
        """Return satellite number, epoch and sv_clock

        Raises
        ------
        EOFError
            on the end of the file.

        RinexNavFileError
            when it can't parse the epoch record.
        """
        try:
            line = next(file_object)
        except StopIteration:
            raise EOFError

        number = line[0:2]

        # year, month, day, hour, min; +sec
        epoch = [line[i:i + 3] for i in range(2, 17, 3)]
        sec = line[17:22]

        sv_clock = [line[i:i + 19] for i in (22, 41, 60)]
        sv_clock = [i.lower().replace('d', 'e') for i in sv_clock]

        try:
            number = int(number)

            sec = sec2sec_ms(float(sec))

            epoch = [int(i) for i in epoch] + list(sec)
            epoch = validate_epoch(epoch)

            sv_clock = [float(f) for f in sv_clock]

        except ValueError:
            msg = "Can't read epoch: {}.".format(line)
            raise RinexNavFileError(msg)

        return number, epoch, tuple(sv_clock)
Ejemplo n.º 6
0
    def retrieve_ver_type(filename):
        """Returns RINEX version and type

        Returns
        -------
        tuple
            (float, str) -- RINEX version and type.

        Raises
        ------
        RinexNavFileError
            on empty file.

        """
        with open(filename) as rinex:
            try:
                header_line = next(rinex)
            except StopIteration:
                raise RinexNavFileError('Unexpected end of the file.')
            else:
                version = float(header_line[:9])
                file_type = header_line[20]
        return version, file_type
Ejemplo n.º 7
0
    def skip_header(file_object):
        """
        Skip the header of the file.

        Parameters
        ----------
        file_object : file-like object

        Returns
        -------
        None

        Raises
        ------
        RinexNavFileError
            on unexpected end of the file.
        """
        line = ''
        while line[60:73] != 'END OF HEADER':
            try:
                line = next(file_object)
            except StopIteration:
                msg = 'Unexpected end of the file.'
                raise RinexNavFileError(msg)