Exemple #1
0
def getAllIonosphericPP(data, navdata, obstimes, sv_list, header, ipp_alt):
    """
    WTF?
    """
    r_new = []
    lonPP = []
    latPP = []
    for gps in sv_list:
        xyz = getSatXYZ(navdata, gps, obstimes)
        rec_position_ecef = np.asarray(header['APPROX POSITION XYZ'],
                                       float)[:, None]
        rec_lat, rec_lon, rec_alt = ecef2geodetic(rec_position_ecef)
        az, el, r = ecef2aer(xyz[:, 0], xyz[:, 1], xyz[:, 2], rec_lat, rec_lon,
                             rec_alt)
        for i in range(len(el)):
            r_new.append(ipp_alt / math.sin(math.radians(el[i])))
        max_ix = el.tolist().index(max(el))
        ipp_lat, ipp_lon, ipp_alt = aer2geodetic(az[max_ix], el[max_ix],
                                                 r_new[max_ix], rec_lat,
                                                 rec_lon, rec_alt)
        r_new = []
        lonPP.append(ipp_lon[0])
        latPP.append(ipp_lat[0])

    return lonPP, latPP
Exemple #2
0
def getSatellitePosition(rx_xyz, sv, obstimes, navfn, cs='wsg84'):
    """
    Sebastijan Mrak
    Function returns satellite position in AER and LLA coordinates for a chosen
    satellite vehicle and obseravtion times. Rx_xyz is a receiver position in 
    ECEF CS, as an np. array. Obstimes gat to be in format pandas.to_datetime
    """
    navdata = pyRinex.readRinexNav(navfn)
    rec_lat, rec_lon, rec_alt = ecef2geodetic(rx_xyz[0], rx_xyz[1], rx_xyz[2])
    xyz = getSatXYZ(navdata, sv, obstimes)
    az, el, r = ecef2aer(xyz[:, 0], xyz[:, 1], xyz[:, 2], rec_lat, rec_lon,
                         rec_alt)
    lat, lon, alt = ecef2geodetic(xyz[:, 0], xyz[:, 1], xyz[:, 2])
    if cs == 'wsg84':
        return [lat, lon, alt]
    elif cs == 'aer':
        return [az, el, r]
    else:
        print('Wrong frame of reference. Type "wsg84" or "aer".')
        return 0
Exemple #3
0
    def __init__(self,
                 interval=[
                     np.datetime64('2015-10-07T06:10:00'),
                     np.datetime64('2015-10-07T06:50:00')
                 ],
                 directory='C:/Users/f**k/Desktop/565 Research/rinex/',
                 sat_num=23):

        self.interval_length = int(
            (interval[1] - interval[0]).item().total_seconds()) - 1
        self.parameters = ['L1', 'S1', 'detrended', 'ACF', 'PSD']
        self.interval = interval
        self.sat_num = sat_num
        self.directory = directory
        self.flist = glob(self.directory + '*.h5')
        self.data = np.empty(
            (len(self.parameters), self.interval_length, len(self.flist)),
            complex)  #receiver,parameter(L1,S1,detrended,ACF),time
        self.rec_pos = np.empty((len(self.flist), 3), float)  #rec pos
        self.rec_names = [fn.split('\\')[-1][:4] for fn in self.flist]
        self.times = self.interval[0] + np.arange(self.interval_length)
        if isfile(self.directory + 'arraydata.npy') and isfile(self.directory +
                                                               'recpos.npy'):
            self.data = np.load(self.directory + 'arraydata.npy')
            self.rec_pos = np.load(self.directory + 'recpos.npy')
            return

        for fn in self.flist:
            print(fn)
            #data extraction
            header, data, svset, obstimes = readRinexObsHdf(fn)
            L1 = data['L1', sat_num, :, 'data']
            S1 = data['S1', sat_num, :, 'data']
            #interval bounds
            start = np.argmin(np.abs(self.interval[0] - L1.index))
            stop = np.argmin(np.abs(self.interval[1] - L1.index))
            #data grooming/calculation
            phase = np.array(L1.values, float)[start + 1:stop]
            snr = np.array(S1.values, float)[start + 1:stop]
            fit = np.poly1d(
                np.polyfit(
                    np.arange(self.interval_length) - np.argmin(phase), phase,
                    6))
            y = fit(np.arange(self.interval_length) - np.argmin(phase))
            detrended = phase - y
            sigma_phi = np.var(detrended)
            ro_phi = np.correlate(detrended, detrended,
                                  mode='full')[self.interval_length //
                                               2:self.interval_length +
                                               self.interval_length // 2]
            ro_phi /= (sigma_phi * np.concatenate(
                (np.arange(self.interval_length // 2 + 1,
                           self.interval_length),
                 np.arange(self.interval_length, self.interval_length // 2,
                           -1))))
            PSD = sigma_phi * ifft(ro_phi)
            #array assignment
            i = self.flist.index(fn)
            self.data[0, :, i] = phase
            self.data[1, :, i] = snr
            self.data[2, :, i] = detrended
            self.data[3, :, i] = ro_phi
            self.data[4, :, i] = PSD

            x, y, z = np.array(header['APPROX POSITION XYZ'], float)
            self.rec_pos[i] = ecef2geodetic(x, y, z)
        np.save(self.directory + 'arraydata', self.data)
        np.save(self.directory + 'recpos', self.rec_pos)
Exemple #4
0
def getIonosphericPiercingPoints(rx_xyz,
                                 sv,
                                 obstimes,
                                 ipp_alt,
                                 navfn,
                                 cs='wsg84',
                                 sattype='G'):
    """
    Sebastijan Mrak
    Function returns a list of Ionospheric Piersing Point (IPP) trajectory in WSG84
    coordinate system (CS). Function takes as parameter a receiver location in 
    ECEF CS, satellite number, times ob observation and desired altitude of a IPP
    trajectory. You also have to specify a full path to th navigation data file.
    It returns IPP location in either WSG84 or AER coordinate system.
    """

    ipp_alt = ipp_alt * 1000
    rec_lat, rec_lon, rec_alt = ecef2geodetic(rx_xyz[0], rx_xyz[1], rx_xyz[2])

    if sattype == 'G':
        navdata = pyRinex.readRinexNav(navfn)
        xyz = getSatXYZ(navdata, sv, obstimes)
        az, el, r = ecef2aer(xyz[:, 0], xyz[:, 1], xyz[:, 2], rec_lat, rec_lon,
                             rec_alt)
        y_out = np.array([az, el, r])
        r_new = []
        for i in range(len(el)):
            if el[i] > 0:
                r_new.append(ipp_alt / math.sin(math.radians(el[i])))
            else:
                r_new.append(np.nan)
        output = np.array(
            aer2geodetic(az, el, r_new, rec_lat, rec_lon, rec_alt))

    elif sattype == 'R':
        f = h5py.File(navfn, 'r')
        sat_xyz = np.array(f[str(sv) + '/data'])[:, 0:3]
        sat_time = np.array(f[str(sv) + '/obstimes'])
        az, el, r = ecef2aer(sat_xyz[:, 0] * 1E3, sat_xyz[:, 1] * 1E3,
                             sat_xyz[:, 2] * 1E3, rec_lat, rec_lon, rec_alt)
        t = datetime2posix(obstimes)
        y_out = []

        for y in [az, el, r]:
            x_new = t
            f = interpolate.interp1d(sat_time, y, kind='cubic')
            y_new = f(x_new)
            y_out.append(y_new)
        y_out = np.array(y_out)

        r_new = []
        for i in range(y_out.shape[1]):
            if y_out[1, i] > 0:
                r_new.append(ipp_alt / math.sin(math.radians(y_out[1, i])))
            else:
                r_new.append(np.nan)
        ipp_lat, ipp_lon, ipp_alt = aer2geodetic(y_out[0, :], y_out[1, :],
                                                 r_new, rec_lat, rec_lon,
                                                 rec_alt)
        output = np.array(
            aer2geodetic(y_out[0, :], y_out[1, :], r_new, rec_lat, rec_lon,
                         rec_alt))
    else:
        print('Type in valid sattype initial. "G" for GPS and "R" for glonass')

    if (cs == 'wsg84'):
        return output
    elif (cs == 'aer'):
        return y_out
    else:
        print(
            'Enter either "wsg84" or "aer" as coordinate system. "wsg84" is default one.'
        )
Exemple #5
0
def saveTrajectories2HDF(day='184',
                         state='tn',
                         el_mask=30,
                         altitude=100,
                         hdffilename='trajectories_tn.h5',
                         loop=True):

    hdffolder = '/home/smrak/sharedrive/cors/'
    navfolder = '/home/smrak/sharedrive/cors/nav/'
    ymlfolder = '/home/smrak/sharedrive/cors/'
    #Find HDF5 filename
    wlstr = '*' + day + '*.h5'
    filestr = os.path.join(hdffolder + state + '/' + day + '/', wlstr)
    flistHDF = glob.glob(filestr)
    #Find NAV filename
    wlstr = '*' + str(day) + '*.17n'
    filestr = os.path.join(navfolder, wlstr)
    flistNAV = glob.glob(filestr)
    #Find YAML filenamE
    wlstr = '*' + str(day) + '*.yaml'
    filestr = os.path.join(ymlfolder + state + '/' + day + '/', wlstr)
    flistYML = glob.glob(filestr)

    h5file = h5py.File(hdffilename, 'w')
    gr = h5file.create_group(day)
    h5state = gr.create_group(state)

    if loop:
        for i in range(len(flistHDF)):
            hdffn = flistHDF[i]
            navfn = flistNAV[0]
            ymlfn = flistYML[i]

            # YAML import header
            stream = yaml.load(open(ymlfn, 'r'))
            rx_xyz = stream.get('APPROX POSITION XYZ')
            rx_llt = ecef2geodetic(rx_xyz[0], rx_xyz[1], rx_xyz[2])
            #Timelim
            timelim = [
                datetime.datetime(2017, 7, 3, 15, 30, 0),
                datetime.datetime(2017, 7, 3, 19, 30, 0)
            ]

            h5rx = h5state.create_group(hdffn[-11:-7])
            h5rx.create_dataset('rxpos', data=rx_llt)

            # HDF Observations
            try:
                data = read_hdf(hdffn)
                obstimes = np.array((data.major_axis))
                obstimes = pandas.to_datetime(
                    obstimes[::10]) - datetime.timedelta(seconds=18)
                idt = np.where((obstimes > timelim[0])
                               & (obstimes < timelim[1]))
                obstimes = obstimes[idt]
                #
                h5rx.create_dataset('time',
                                    data=pyGps.datetime2posix(obstimes))
                #
                dumb = data['L1', :, 1, 'data']
                svlist = dumb.axes[0]
                for sv in svlist:
                    # GPS only svnum <=32
                    az = np.nan * np.zeros(obstimes.shape[0])
                    el = np.nan * np.zeros(obstimes.shape[0])
                    lat = np.nan * np.zeros(obstimes.shape[0])
                    lon = np.nan * np.zeros(obstimes.shape[0])
                    if sv <= 32:
                        h5sv = h5rx.create_group('sv' + str(sv))
                        aer = pyGps.getIonosphericPiercingPoints(rx_xyz,
                                                                 sv,
                                                                 obstimes,
                                                                 altitude,
                                                                 navfn,
                                                                 cs='aer')
                        llt = pyGps.getIonosphericPiercingPoints(rx_xyz,
                                                                 sv,
                                                                 obstimes,
                                                                 altitude,
                                                                 navfn,
                                                                 cs='wsg84')
                        idel = np.where(aer[1] > el_mask)[0]
                        az[idel] = aer[0][idel]
                        el[idel] = aer[1][idel]
                        lat[idel] = llt[0][idel]
                        lon[idel] = llt[1][idel]
                        h5sv.create_dataset('az', data=az)
                        h5sv.create_dataset('el', data=el)
                        h5sv.create_dataset('lat', data=lat)
                        h5sv.create_dataset('lon', data=lon)
                        print('Saving data for sat: ' + str(sv))
                    else:
                        break
            except:
                raise ValueError
    h5file.close()