def test_navheader(): # %% rinex 2 hdr = gr.rinexheader(R / 'demo.10n') assert isinstance(hdr, dict) assert int(hdr['version']) == 2 # %% rinex 3 hdr = gr.rinexheader(R / 'demo3.10n') assert isinstance(hdr, dict) assert int(hdr['version']) == 3
def test_obsheader(): # %% rinex 2 hdr = gr.rinexheader(R / 'demo.10o') assert isinstance(hdr, dict) assert len(hdr['position']) == 3 # %% rinex 3 hdr = gr.rinexheader(R / 'demo3.10o') assert isinstance(hdr, dict) assert len(hdr['position']) == 3
def test_header(fn, rtype, vers): if fn.suffix == ".nc" and netCDF4 is None: pytest.skip("no netCDF4") hdr = gr.rinexheader(fn) assert isinstance(hdr, dict) assert rtype in hdr["rinextype"] assert hdr["version"] == pytest.approx(vers) # make sure string filenames work too hdr = gr.rinexheader(str(fn)) assert isinstance(hdr, dict)
def test_header(fn, rtype, vers): if fn.suffix == '.nc' and netCDF4 is None: pytest.skip('no netCDF4') hdr = gr.rinexheader(fn) assert isinstance(hdr, dict) assert rtype in hdr['rinextype'] assert hdr['version'] == pytest.approx(vers) # make sure string filenames work too hdr = gr.rinexheader(str(fn)) assert isinstance(hdr, dict)
def initialize(self): """ Initialize the process :return: """ files = sorted(os.listdir(self.folder)) logging.info(">> Found " + str(len(files)) + " file(s)") start_general = time.perf_counter() for file in files: start = time.perf_counter() complete_path = os.path.join(self.folder, file) logging.info(">>>> Reading rinex: " + file) hdr = gr.rinexheader(complete_path) version = hdr.get('version') columns_to_be_load = Utils.which_cols_to_load() if version >= settings.REQUIRED_VERSION: obs = gr.load(complete_path, meas=columns_to_be_load, use=settings.CONSTELLATIONS) year, month, doy = Utils.setup_rinex_name(file) obs = self._cycle_slip_analysis(hdr, obs, year, month, doy) else: logging.info(">>>>>> Rinex version {}. This code comprises the 3.01+ rinex version.".format(version)) continue stop = time.process_time() logging.info(">> File " + file + " checked! Time: %.4f minutes" % float((start - stop) / 60)) stop_general = time.process_time() logging.info(">> Processing done for " + str(len(files)) + " files in %.4f minutes" % float((stop_general - start_general) / 60))
def eachfile(fn: Path, verbose: bool = False): try: times = gr.gettime(fn) except ValueError as e: if verbose: print(f"{fn.name}: {e}") return # %% output Ntimes = times.size if Ntimes == 0: return ostr = f"{fn.name}:" f" {times[0].isoformat()}" f" {times[-1].isoformat()}" f" {Ntimes}" hdr = gr.rinexheader(fn) interval = hdr.get("interval", np.nan) if ~np.isnan(interval): ostr += f" {interval}" Nexpect = (times[-1] - times[0]) // timedelta(seconds=interval) + 1 if Nexpect != Ntimes: logging.warning( f"{fn.name}: expected {Nexpect} but got {Ntimes} times") print(ostr) if verbose: print(times)
def test_nav3header(fname): hdr = gr.rinexheader(R / fname) assert hdr["IONOSPHERIC CORR"]["GPSA"] == approx( [1.1176e-08, -1.4901e-08, -5.9605e-08, 1.1921e-07] ) assert hdr["TIME SYSTEM CORR"]["GPUT"] == approx( [-3.7252902985e-09, -1.065814104e-14, 61440, 1976] )
def test_dont_care_file_extension(): """ GeoRinex ignores the file extension and only considers file headers to determine what a file is.""" fn = R / 'brdc0320.16l.txt' hdr = gr.rinexheader(R / fn) assert int(hdr['version']) == 3 nav = gr.load(fn) assert nav.ionospheric_corr_GAL == approx([139, 0.132, 0.0186])
def test_dont_care_file_extension(): """ GeoRinex ignores the file extension and only considers file headers to determine what a file is.""" fn = R / 'brdc0320.16l.txt' hdr = gr.rinexheader(R/fn) assert int(hdr['version']) == 3 nav = gr.load(fn) assert nav.ionospheric_corr_GAL == approx([139, 0.132, 0.0186])
def getklobucharvalues(navfile): navhead = gr.rinexheader(navfile) #load navigation header to obtain klobuchar alpha = navhead['ION ALPHA'] #klobuchar alphas beta = navhead['ION BETA'] #klobuchar betas alpha2 = alpha.replace("D", "E") #nav headers sometimes use D instead of E for power beta2 = beta.replace("D", "E") alp1= numpy.asarray(alpha2.split()) bet1= numpy.asarray(beta2.split()) alp = alp1.astype(numpy.float) #numpy array of klobuchar alphas bet = bet1.astype(numpy.float) #numpy array of klobuchar betas return(alp,bet)
def test_obs2_lzw(): pytest.importorskip('unlzw3') fn = R / 'ac660270.18o.Z' obs = gr.load(fn) hdr = gr.rinexheader(fn) assert hdr['t0'] <= gr.to_datetime(obs.time[0]) assert not obs.fast_processing
def test_obs2(): pytest.importorskip('unlzw') fn = R/'ac660270.18o.Z' obs = gr.load(fn) hdr = gr.rinexheader(fn) assert hdr['t0'] <= gr.to_datetime(obs.time[0]) assert not obs.fast_processing
def test_obs2_lzw(): pytest.importorskip("unlzw3") fn = R / "ac660270.18o.Z" obs = gr.load(fn) hdr = gr.rinexheader(fn) assert hdr["t0"] <= gr.to_datetime(obs.time[0]) assert not obs.fast_processing
def test_Z_lzw(): pytest.importorskip('unlzw') fn = R / 'ac660270.18o.Z' obs = gr.load(fn) hdr = gr.rinexheader(fn) assert hdr['t0'] <= obs.time[0].values.astype('datetime64[us]').astype( datetime) assert not obs.fast_processing
def test_zip(): fn = R/'ABMF00GLP_R_20181330000_01D_30S_MO.zip' obs = gr.load(fn) assert (obs.sv.values == ['E04', 'E09', 'E12', 'E24', 'G02', 'G05', 'G06', 'G07', 'G09', 'G12', 'G13', 'G17', 'G19', 'G25', 'G30', 'R01', 'R02', 'R08', 'R22', 'R23', 'R24', 'S20', 'S31', 'S35', 'S38']).all() times = gr.gettime(fn) assert (times == [datetime(2018, 5, 13, 1, 30), datetime(2018, 5, 13, 1, 30, 30), datetime(2018, 5, 13, 1, 31)]).all() hdr = gr.rinexheader(fn) assert hdr['t0'] <= times[0]
def test_zip(): fn = R/'ABMF00GLP_R_20181330000_01D_30S_MO.zip' obs = gr.load(fn) assert (obs.sv.values == ['E04', 'E09', 'E12', 'E24', 'G02', 'G05', 'G06', 'G07', 'G09', 'G12', 'G13', 'G17', 'G19', 'G25', 'G30', 'R01', 'R02', 'R08', 'R22', 'R23', 'R24', 'S20', 'S31', 'S35', 'S38']).all() times = gr.gettime(fn).values.astype('datetime64[us]').astype(datetime) assert (times == [datetime(2018, 5, 13, 1, 30), datetime(2018, 5, 13, 1, 30, 30), datetime(2018, 5, 13, 1, 31)]).all() hdr = gr.rinexheader(fn) assert hdr['t0'] <= times[0]
def test_zip(fname): fn = R / fname obs = gr.load(fn) assert ( obs.sv.values == [ "E04", "E09", "E12", "E24", "G02", "G05", "G06", "G07", "G09", "G12", "G13", "G17", "G19", "G25", "G30", "R01", "R02", "R08", "R22", "R23", "R24", "S20", "S31", "S35", "S38", ] ).all() times = gr.gettime(fn) assert times.tolist() == [ datetime(2018, 5, 13, 1, 30), datetime(2018, 5, 13, 1, 30, 30), datetime(2018, 5, 13, 1, 31), ] hdr = gr.rinexheader(fn) assert hdr["t0"] <= times[0]
def read_one_rnx_file(rfn_with_path): import georinex as gr import pandas as pd from pandas.errors import OutOfBoundsDatetime from aux_gps import get_timedate_and_station_code_from_rinex def parse_field(field): field_new = [x.split(' ') for x in field] flat = [item for sublist in field_new for item in sublist] return [x for x in flat if len(x) > 1] hdr = gr.rinexheader(rfn_with_path) header = {} ant = [val for key, val in hdr.items() if 'ANT' in key] try: header['ant'] = parse_field(ant)[1] except IndexError: header['ant'] = parse_field(ant) try: header['ant_serial'] = parse_field(ant)[0] except IndexError: header['ant_serial'] = parse_field(ant) rec = [val for key, val in hdr.items() if 'REC' in key] try: rec = ' '.join(parse_field(rec)[1:3]) except IndexError: rec = parse_field(rec) header['rec'] = rec name = [val for key, val in hdr.items() if 'NAME' in key] try: header['name'] = parse_field(name)[0] except IndexError: header['name'] = parse_field(name) try: dts = pd.to_datetime(hdr['t0']) except OutOfBoundsDatetime: rfn = rfn_with_path.as_posix().split('/')[-1][0:12] dts = get_timedate_and_station_code_from_rinex(rfn, True) except KeyError: rfn = rfn_with_path.as_posix().split('/')[-1][0:12] dts = get_timedate_and_station_code_from_rinex(rfn, True) header['dt'] = dts return header
def test_zip(): fn = R / "ABMF00GLP_R_20181330000_01D_30S_MO.zip" obs = gr.load(fn) assert (obs.sv.values == [ "E04", "E09", "E12", "E24", "G02", "G05", "G06", "G07", "G09", "G12", "G13", "G17", "G19", "G25", "G30", "R01", "R02", "R08", "R22", "R23", "R24", "S20", "S31", "S35", "S38", ]).all() times = gr.gettime(fn) assert (times == [ datetime(2018, 5, 13, 1, 30), datetime(2018, 5, 13, 1, 30, 30), datetime(2018, 5, 13, 1, 31), ]).all() hdr = gr.rinexheader(fn) assert hdr["t0"] <= times[0]
def _prepare_rinex(self, complete_path): """ Prepare the rinexs, such as checking if it is a valid file and if it has all the information need for the calculation :param complete_path: The absolute path to the rinex :return: The Python objects after to successful read the prev and rinex, it includes the header and measures of both files """ if not os.path.isfile(complete_path): logging.error( ">>>> Rinex {} does not exist. Process stopped!\n".format( complete_path)) raise Exception( ">>>> Rinex {} does not exist. Process stopped!\n".format( complete_path)) logging.info(">> Validating file and measures...") hdr = gr.rinexheader(complete_path) logging.info(">>>> Rinex version {}!".format(hdr['version'])) self.validate_version(hdr, complete_path) columns, constellations, l1_col, l2_or_l3_col, p1_or_c1_col, p2_or_c2_col, l2_channel = self.which_data_to_load( hdr) if not constellations: logging.info( ">>>> This rinex ({}) does not have the measures required for the TEC and bias estimation.\n" .format(complete_path)) raise Exception( ">>>> This rinex ({}) does not have the measures required for the TEC and " "bias estimation.\n".format(complete_path)) else: logging.info( ">> Reading rinex measures... Only constellation(s) {} will " "be considered!".format(constellations)) obs = gr.load(complete_path, meas=columns, use=constellations) return hdr, obs, columns, constellations, l1_col, l2_or_l3_col, p1_or_c1_col, p2_or_c2_col, l2_channel
def writeRxlist2HDF(obsfolder='/media/smrak/Eclipse2017/Eclipse/cors/all/233/', sufix='*.*d', listfilename=None): """ Make a list of receivers in a given folder, ordered by their geographical location. The list is organized as hdf5 file. "obsfolder" is path to the folder with RINEX files, which need to be first converted into .yaml cfg file containing their header information. "listfilename" is the wanted filename which will contain converted lat/lon information. Itshould contain path/to/file.h5, if you forget .h5 extension, it will auto make one for you. """ rxlist = getRxList(obsfolder, sufix) if listfilename is None: listfilename = obsfolder assert len(rxlist) > 0 head, tail = os.path.split(listfilename) year = tail[-3:-1] doy = tail[4:7] if tail == '': F = os.path.expanduser(listfilename).split(os.sep) year = F[-3] doy = F[-2] listfilename = listfilename + 'rxlist{}.{}.h5'.format(doy, year) if listfilename[-3:] != '.h5': listfilename += '.h5' print('Number of receivers in the folder: ', len(rxlist)) c = 0 table = nan * zeros((len(rxlist), 2)) for fn in rxlist: sx = os.path.splitext(fn)[1] try: if sx.endswith('.yaml'): stream = yaml.load(open(fn, 'r')) rx_xyz = stream.get('APPROX POSITION XYZ') rec_lat, rec_lon, rec_alt = ecef2geodetic( rx_xyz[0], rx_xyz[1], rx_xyz[2]) elif sx.endswith('o') or sx.endswith('d'): hdr = grx.rinexheader(fn) if 'position_geodetic' in hdr: rec_lat, rec_lon, rec_alt = hdr['position_geodetic'] elif 'position' in hdr: rx_xyz = hdr['position'] rec_lat, rec_lon, rec_alt = ecef2geodetic( rx_xyz[0], rx_xyz[1], rx_xyz[2]) elif 'APPROX POSITION XYZ': rx_xyz = hdr['APPROX POSITION XYZ'] rec_lat, rec_lon, rec_alt = ecef2geodetic( rx_xyz[0], rx_xyz[1], rx_xyz[2]) else: print('Cant find the position of the gps receiver: {}'. format(fn)) rec_lat = nan rec_lon = nan elif sx.endswith('.nc'): D = grx.load(fn) rec_lat, rec_lon, rec_alt = D.position_geodetic table[c, :] = [rec_lat, rec_lon] c += 1 except Exception as e: print('Couldnt process: ', fn) print(e) c += 1 print('Saving as: ', listfilename) gpslist = [os.path.split(l)[1][:4] for l in rxlist] h5file = h5py.File(listfilename, 'w') tab = h5file.create_group('data') tab.create_dataset('table', data=table) asciiList = [n.encode("ascii", "ignore") for n in gpslist] tab.create_dataset('rx', (len(asciiList), 1), 'S10', asciiList) h5file.close() print('Successfully saved!')
) * tk - OMEGA_DOT_EARTH * ephemeris.Toe x = xk_orbital_plane + math.cos( omegak) - yk_orbital_plane * math.cos(ik) * math.sin(omegak) y = xk_orbital_plane + math.sin( omegak) + yk_orbital_plane * math.cos(ik) * math.cos(omegak) z = yk_orbital_plane * math.sin(ik) return x, y, z def find_distance_3d(x1, y1, z1, x2, y2, z2): return math.sqrt( math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2)) navigation_entry = gr.load('gps_data.n') observation_entry = gr.load('obs_data.o', use='G', interval=10) receiver_position = gr.rinexheader('obs_data.o').get('position') times = observation_entry.get('time') distance_array = [] time_array = [] for index, epoch in enumerate(times.data): xyz_satellite = find_satellite_xyz(epoch, navigation_entry) distance = find_distance_3d(xyz_satellite[0], xyz_satellite[1], xyz_satellite[2], receiver_position[0], receiver_position[1], receiver_position[2]) distance_array.append(distance) time_array.append(epoch) plt.plot(time_array, distance_array) plt.show()
def test_position(fn): hdr = gr.rinexheader(fn) assert len(hdr["position"]) == 3
def __init__(self, rinex_file): self._hdr = gr.rinexheader(rinex_file) self.times = gr.gettime(rinex_file) self.file = rinex_file self.T01_file = rinex_file.replace('rnx', 'T01') self.rinex_filename = ''
[gpsweek,gpsdow]=gpsweekdow(int(year),int(doy)) week = str(int(gpsweek)) #convert to strings dow = str(int(gpsdow)) getbcorbit(year, doy) #Download broadcast orbit getrinexhr(site, year, doy) #Download RINEX obsfile = 'rinex_hr/' + site + doy + '0.' + year[-2:] + 'o' #rinex file name navfile = 'nav/brdc' + doy + '0.' + year[-2:] + 'n' #broadcast navigation file name #use teqc to convert the rinex to remove comments within and remove non gps satellites #Also, the -st command sets the start time and +dm is the number of minutes to consider os.system('./teqc -R -E -S -C -J -phc -st ' + st + ' +dm ' + nummin + ' ' + obsfile + ' > example.o') #os.system('tac example.o | sed -e "/post/{N;d;}" | tac > example2.o') #remove the comment lines that teqc didn't remove header=gr.rinexheader('example.o')#read the RINEX header (x0,y0,z0)=header['position'] #use the a priori location of the site from the RINEX header. If its really bad, you might want to change it [latsta,lonsta,altsta]=ecef2lla(float(x0),float(y0),float(z0)) #station lat and lon are needed for klobuchar correction nav = gr.load(navfile) #Load the broadcast navigation file [alpha,beta]=getklobucharvalues(navfile) #get klobuchar corrections from navigation file obs = gr.load('example.o') #Load the RINEX file L1 = obs['L1'].values#phase values L2 = obs['L2'].values obs_time = obs.time.values #observation times