def dataFromNC(fnc, fnav, sv, fsp3=None, el_mask=30, tlim=None, satpos=False, ipp=False, ipp_alt=None): leap_seconds = uf.getLeapSeconds(fnav) D = gr.load(fnc, useindicators=True).sel(sv=sv) D['time'] = np.array([np.datetime64(ttt) for ttt in D.time.values]) if tlim is not None: if len(tlim) == 2: D = D.where(np.logical_and(D.time >= np.datetime64(tlim[0]), D.time <= np.datetime64(tlim[1])), drop=True) obstimes64 = D.time.values dt = np.array([Timestamp(t).to_pydatetime() for t in obstimes64]) - \ datetime.timedelta(seconds = leap_seconds) if fsp3 is None: aer = gpsSatPosition(fnav, dt, sv=sv, rx_position=D.position, coords='aer') else: aer = gpsSatPositionSP3(fsp3, dt, sv=sv, rx_position=D.position_geodetic, coords='aer') idel = (aer[1, :] >= el_mask) aer[:, ~idel] = np.nan D['time'] = dt if satpos: D['az'] = aer[0, :] D['el'] = aer[1, :] D['idel'] = idel if ipp: if ipp_alt is None: print('Auto assigned altitude of the IPP: 250 km') ipp_alt = 250e3 else: ipp_alt *= 1e3 rec_lat, rec_lon, rec_alt = D.position_geodetic fm = np.sin(np.radians(aer[1])) r_new = ipp_alt / fm lla_vector = np.array( aer2geodetic(aer[0], aer[1], r_new, rec_lat, rec_lon, rec_alt)) D['ipp_lon'] = lla_vector[1] D['ipp_lat'] = lla_vector[0] D['ipp_alt'] = ipp_alt return D
def dataFromNC(fnc, fnav, el_mask=30, tlim=None): leap_seconds = gu.getLeapSeconds(fnav) D = gr.load(fnc, useindicators=True).sel(sv=sv) if tlim is not None: if len(tlim) == 2: D = D.where(np.logical_and(D.time >= np.datetime64(tlim[0]), D.time <= np.datetime64(tlim[1])), drop=True) obstimes64 = D.time.values dt = np.array([Timestamp(t).to_pydatetime() for t in obstimes64]) - \ timedelta(seconds = leap_seconds) rx_xyz = D.position aer = pyGnss.gpsSatPosition(fnav, dt, sv=sv, rx_position=rx_xyz, coords='aer') idel = (aer[1] >= el_mask) dt = dt[idel] return dt, D, idel
def singleRx(obs, nav, sv='G23', args=['L1','S1'], tlim=None,rawplot=False, sp=True,s4=False,polyfit=False,indicator=False, alt=300,el_mask=30,skip=20,porder=8,tec_ch=2, forder=5,fc=0.1,fs=1): def _plot(x,y,title=''): plt.figure() plt.title(title) plt.plot(x,y,'b') D = xarray.open_dataset(obs, group='OBS') rx_xyz = D.position leap_seconds = uf.getLeapSeconds(nav) obstimes64 = D.time.values times = np.array([Timestamp(t).to_pydatetime() for t in obstimes64]) - \ timedelta(seconds = leap_seconds) # define tlim ie. skip if tlim is not None: s = ((times>=tlim[0]) & (times<=tlim[1])) else: s = np.full(times.shape[0], True, dtype=bool) s[:skip] = False times = times[s] # Get satellite position aer = gpsSatPosition(nav, times, sv=sv, rx_position=rx_xyz, coords='aer') # Elevation mask idel = aer[1] >= el_mask times = times[idel] # times to output dict: Y Y = {'times': times} Y['rx_xyz'] = rx_xyz Y['az'] = aer[0][idel] Y['el'] = aer[1][idel] for arg in args: if not arg[1:] == 'TEC': X = D.sel(sv=sv)[arg].values[s][idel] # To dict Y[arg] = X # Indicators? if indicator: try: if arg[0] == 'L' and arg[-1] != '5': argi = arg + 'lli' elif arg[0] == 'C' or arg[0] == 'P' or arg == 'L5': argi = arg + 'ssi' else: argi = '' Xi = D.sel(sv=sv)[argi].values[s:][idel] Y[argi] = Xi except Exception as e: print (e) if rawplot: _plot(times,X,arg) if arg[0] == 'L' or arg[0] == 'C': if arg == 'C1': X = X * f1 / c0 # To cycles Xd = uf.phaseDetrend(X, order=porder) if polyfit: # To dict Y[arg+'polyfit'] = Xd if rawplot: if rawplot: _plot(times,Xd,arg+'_detrend_poly') if sp: Xy = uf.hpf(Xd, order=forder,fc=fc,plot=False,fs=fs) # To dict Y['sp'] = Xy if rawplot: _plot(times[100:],Xy[100:],arg+'_scint') if arg[0] == 'S': if s4: Xy = AmplitudeScintillationIndex(X,60) # To dict Y['s4'] = Xy if rawplot: _plot(times,Xy,arg+'_S4') if arg[1:] == 'TEC': if tec_ch == 2: C1 = D.sel(sv=sv)['C1'].values[s][idel] L1 = D.sel(sv=sv)['L1'].values[s][idel] C2 = D.sel(sv=sv)['P2'].values[s][idel] L2 = D.sel(sv=sv)['L2'].values[s][idel] elif tec_ch == 5: C1 = D.sel(sv=sv)['C1'].values[s][idel] L1 = D.sel(sv=sv)['L1'].values[s][idel] C2 = D.sel(sv=sv)['C5'].values[s][idel] L2 = D.sel(sv=sv)['L5'].values[s][idel] sTEC = getPhaseCorrTEC(L1, L2, C1, C2,channel=tec_ch) sTEC = sTEC - np.nanmin(sTEC) if arg == 'sTEC': # To dict Y[arg] = sTEC if rawplot: _plot(times, sTEC,title=arg) elif arg == 'vTEC': vTEC = getVerticalTEC(sTEC,aer[1][idel],alt) # To dict Y[arg] = vTEC if rawplot: _plot(times, vTEC, title=arg) # return dict with data/args return Y
arg = 'L1' el_mask = 30 skip = 10 porder = 8 forder = 6 fc = 0.1 fs = 1 D = xarray.open_dataset(obs, group='OBS') # Dummy arrays T = np.nan * np.ones(D.sizes['time'] - skip) Ls = np.copy(T) Ss = np.copy(T) # rx_xyz = D.position leap_seconds = gu.getLeapSeconds(nav) obstimes64 = D.time[skip:].values obstimes_dt = np.array([Timestamp(t).to_pydatetime() for t in obstimes64]) \ - timedelta(seconds = leap_seconds) Ds = D.sel(sv=sv) L1 = Ds['L1'][skip:].values S1 = Ds['S1'][skip:].values aer = pyGnss.getSatellitePosition(rx_xyz, sv, obstimes_dt, nav, cs='aer', dtype='georinex') idel = (aer[1] >= el_mask)