-
Notifications
You must be signed in to change notification settings - Fork 15
/
Gobs.m
1460 lines (1443 loc) · 63.4 KB
/
Gobs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef Gobs < handle
% Gobs: GNSS RINEX observation data class
% ---------------------------------------------------------------------
% Gobs Declaration:
% gobs = Gobs(); Create empty gt.Gobs object
%
% gobs = Gobs(file); Create gt.Gobs object from RINEX file
% file : 1x1, RINEX observation file
%
% gobs = Gobs(obsstr); Create gt.Gobs object from observation struct
% obsstr : 1x1, RTKLIB observation struct
% ---------------------------------------------------------------------
% Gobs Properties:
% n : 1x1, Number of epochs
% nsat : 1x1, Number of satellites
% sat : 1x(obj.nsat), Satellite number (Compliant RTKLIB)
% prn : 1x(obj.nsat), Satellite PRN/slot number
% sys : 1x(obj.nsat), Satellite system (SYS_GPS, SYS_GLO, ...)
% satstr : 1x(obj.nsat), Satellite ID cell array ('Gnn','Rnn','Enn','Jnn','Cnn','Inn' or 'nnn')
% time : 1x1, Observation time, gt.Gtime object
% dt : 1x1, Observation time interval (s)
% pos : 1x1, Position in RINEX header, gt.Gpos object
% glofcn : 1x(obj.nsat), Frequency channel number for GLONASS
% L1 : 1x1, L1 observation struct
% .P : (obj.n)x(obj.nsat), Pseudorange (m)
% .L : (obj.n)x(obj.nsat), Carrier phase (cycle)
% .D : (obj.n)x(obj.nsat), Doppler (Hz)
% .S : (obj.n)x(obj.nsat), SNR (dB-Hz)
% .I : (obj.n)x(obj.nsat), LLI flag
% .ctype : 1x(obj.nsat), Observation code cell array {'1C', '1P', '1P',...}
% .freq : 1x(obj.nsat), Carrier frequency (Hz)
% .lam : 1x(obj.nsat), Wavelength (m)
% L2 : 1x1, L2 observation struct
% L5 : 1x1, L5 observation struct
% L6 : 1x1, L6 observation struct
% L7 : 1x1, L7 observation struct
% L8 : 1x1, L8 observation struct
% L9 : 1x1, L9 observation struct
% (Lwl) : 1x1, Wide-lane linear combination struct
% (Lml) : 1x1, Middle-lane linear combination struct
% (Lewl) : 1x1, Extra wide-lane linear combination struct
% (Lif) : 1x1, Ionosphere-free linear combination struct
% ---------------------------------------------------------------------
% Gobs Methods:
% setObsFile(file); Set observation from RINEX file
% setObsStruct(obsstr); Set observation from observation struct
% setFrequency(); Set carrier frequency and wavelength
% setFrequencyFromNav(nav); Set carrier frequency and wavelength from navigation
% outObs(file); Output RINEX observation file
% insert(idx, gobs); Insert gt.Gobs object
% append(gobs); Append of gt.Gobs object
% maskP(mask, [freq]); Apply mask to pseudorange observations
% maskD(mask, [freq]); Apply mask to Doppler observations
% maskL(mask, [freq]); Apply mask to carrier phase observations
% mask(mask, [freq]); Apply mask to observations
% maskLLI(mask); Apply mask to carrier phase from LLI flag
% gobs = eliminateNaN(); Eliminate satellites whose observations are all NaN
% gobs = copy(); Copy object
% gobs = select(tidx, sidx); Select observation from time/satellite index
% gobs = selectSat(sidx); Select observation from satellite index
% gobs = selectTime(tidx); Select observation from time index
% gobs = selectTimeSpan(ts, te); Select observation from time span
% obsstr = struct([tidx], [sidx]); Convert from gt.Gobs object to observation struct
% gobs = fixedInterval([dt]); Resampling object at fixed interval
% [gobsc, gobsrefc] = commonObs(gobsref); Extract common observations with reference observation
% [gobsc, gobsrefc] = commonSat(gobsref); Extract common satellite with reference observation
% [gobsc, gobsrefc] = commonTime(gobsref);Extract common time with reference observation
% gobs = sameObs(gobsref); Same satellite and time as reference observation
% gobs = sameSat(gobsref); Same satellite as reference observation
% gobs = sameTime(gobsref); Same time as reference observation
% gobs = linearCombination(); Compute linear combination of observations
% gobs = residuals(gsat); Compute observation residuals
% gobsSD = singleDifference(gobs); Compute single-difference observations
% gobsDD = doubleDifference(gobs); Compute double-difference observations
% plot([freq], [sidx]); Plot received observations and SNR
% plotNSat([freq], [snrth], [sidx]); Plot received number of satellites
% plotSky(nav, [sidx]); Plot satellite constellation
% help(); Show help
% ---------------------------------------------------------------------
% Gobs Overloads:
% gobsSD = obj - gobs; Compute single-difference observations
% ---------------------------------------------------------------------
% Author: Taro Suzuki
%
properties
n % Number of epochs
nsat % Number of satellites
sat % Satellite number (Compliant RTKLIB)
prn % Satellite PRN number/slot number
sys % Satellite system (SYS_GPS, SYS_GLO, ...)
satstr % Satellite id cell array
time % Observation time, gt.Gtime object
dt % Observation time interval (s)
pos % Position in RINEX header, gt.Gpos object
glofcn % Frequency channel number for GLONASS
L1 % L1 observation struct {P, L, D, S, I, ctype, freq, lam}
L2 % L2 observation struct
L5 % L5 observation struct
L6 % L6 observation struct
L7 % L7 observation struct
L8 % L8 observation struct
L9 % L9 observation struct
Lwl % Wide-lane linear combination struct
Lml % Middle-lane linear combination struct
Lewl % Extra wide-lane linear combination struct
Lif % Ionosphere-free linear combination struct
end
properties(Access=private)
FTYPE = ["L1","L2","L5","L6","L7","L8","L9","Lwl","Lml","Lewl","Lif"];
end
methods
%% constructor
function obj = Gobs(varargin)
if nargin==0 % generate empty object
obj.n = 0;
obj.nsat = 0;
elseif nargin==1 && (ischar(varargin{1}) || isStringScalar(varargin{1}))
obj.setObsFile(char(varargin{1})); % file
elseif nargin==1 && isstruct(varargin{1})
obj.setObsStruct(varargin{1}); % obs struct
else
error('Wrong input arguments');
end
end
%% setObsFile
function setObsFile(obj, file)
% setObsFile: Set observation from RINEX file
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.setObsFile(file)
%
% Input: ------------------------------------------------------
% file : 1x1, RINEX observation file
%
arguments
obj gt.Gobs
file (1,:) char
end
try
[obs, basepos, fcn] = rtklib.readrnxobs(obj.absPath(file));
catch
error('Wrong RINEX observation file: %s',file);
end
% pos
if ~all(basepos==[0,0,0])
obj.pos = gt.Gpos(basepos,'xyz');
end
% glofcn
idxglo = obs.sys==gt.C.SYS_GLO;
fcn(fcn==0) = NaN;
obj.glofcn = NaN(1,obs.nsat);
obj.glofcn(idxglo) = fcn(obs.prn(idxglo))-8;
obj.setObsStruct(obs);
end
%% setObsStruct
function setObsStruct(obj, obsstr)
% setObsStruct: Set observation from observation struct
% -------------------------------------------------------------
% The observation struct is the output of the RTKLIB wrapper
% function.
%
% Usage: ------------------------------------------------------
% obj.setObsStruct(obsstr)
%
% Input: ------------------------------------------------------
% obsstr : 1x1, Observation struct
%
arguments
obj gt.Gobs
obsstr (1,1) struct
end
ep = obsstr.ep;
obj.n = size(obsstr.ep,1);
obj.nsat = size(obsstr.sat,2);
obj.sat = obsstr.sat;
[sys_, obj.prn] = rtklib.satsys(obj.sat);
obj.sys = gt.C.SYS(sys_);
obj.satstr = rtklib.satno2id(obj.sat);
obj.time = gt.Gtime(ep);
obj.dt = obj.time.estInterval();
for f = obj.FTYPE
if isfield(obsstr,f)
obj.(f) = obsstr.(f);
end
end
if isempty(obj.glofcn)
obj.glofcn = NaN(1,obj.nsat);
end
if ~all(isnan(obj.glofcn))
obj.setFrequency();
end
end
%% setFrequency
function setFrequency(obj)
% setFrequency: Set carrier frequency and wavelength
% -------------------------------------------------------------
% Carrier frequency is determined from the type of observation.
% For GLONASS, the carrier frequency is determined from the
% frequency channel number (FCN) in the RINEX header.
%
% If the RINEX header does not contain an FCN, the GLONASS
% frequency is not set.
%
% Usage: ------------------------------------------------------
% obj.setFrequency()
%
arguments
obj gt.Gobs
end
for f = obj.FTYPE
if ~isempty(obj.(f))
code = rtklib.obs2code(obj.(f).ctype);
obj.(f).freq = rtklib.code2freq(double(obj.sys), code, obj.glofcn);
obj.(f).freq(obj.(f).freq==0) = NaN;
obj.(f).lam = gt.C.CLIGHT./obj.(f).freq;
end
end
end
%% setFrequencyFromNav
function setFrequencyFromNav(obj, nav)
% setFrequencyFromNav: Set carrier frequency and wavelength from navigation
% -------------------------------------------------------------
% Carrier frequency is determined from the type of observeation.
% For GLONASS, the carrier frequency is determined from the
% frequency channel number (FCN) in the navigation data.
%
% Usage: ------------------------------------------------------
% obj.setObsStruct(nav)
%
% Input: ------------------------------------------------------
% nav : 1x1, Navigation struct or gt.Gnav object
%
arguments
obj gt.Gobs
nav (1,1)
end
if ~isstruct(nav)
if isa(nav, 'gt.Gnav')
nav = nav.struct();
else
error('Input must be nav struct of gt.Gnav');
end
end
for f = obj.FTYPE
if ~isempty(obj.(f))
if isfield(obj.(f),"ctype")
code = rtklib.obs2code(obj.(f).ctype);
obj.(f).freq = rtklib.sat2freq(obj.sat,code,nav);
obj.(f).freq(obj.(f).freq==0) = NaN;
obj.(f).lam = gt.C.CLIGHT./obj.(f).freq;
end
end
end
end
%% outObs
function outObs(obj, file)
% outObs: Output RINEX observation file
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.outObs(file)
%
% Input: ------------------------------------------------------
% file : Output RINEX observation file name
%
arguments
obj gt.Gobs
file (1,:) char
end
obsstr = obj.struct();
fcn = zeros(1,32);
xyz = zeros(1,3);
% GLONASS FCN for RINEX header
if ~any(isnan(obj.glofcn))
sysglo = obj.sys==gt.C.SYS_GLO;
fcn(obj.prn(sysglo)) = obj.glofcn(sysglo)+8;
end
if ~isempty(obj.pos)
xyz = obj.pos.xyz;
end
rtklib.outrnxobs(obj.absPath(file), obsstr, xyz, fcn);
end
%% insert
function insert(obj, idx, gobs)
% insert: Insert gt.Gobs object
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.insert(idx, gobs)
%
% Input: ------------------------------------------------------
% idx : 1x1, Integer index to insert data
% gobs: 1x1, gt.Gobs object
%
arguments
obj gt.Gobs
idx (1,1) {mustBeInteger}
gobs gt.Gobs
end
if idx<=0 || idx>obj.n
error('Index is out of range');
end
obsstr.n = obj.n+gobs.n;
obsstr.sat = unique([obj.sat, gobs.sat]);
obsstr.nsat = length(obsstr.sat);
[obsstr.sys, obsstr.prn] = rtklib.satsys(obsstr.sat);
obsstr.satstr = rtklib.satno2id(obsstr.sat);
obsstr.ep = obj.insertdata(obj.time.ep, idx, gobs.time.ep);
obsstr.tow = obj.insertdata(obj.time.tow, idx, gobs.time.tow);
obsstr.week = obj.insertdata(obj.time.week, idx, gobs.time.week);
[~,sidx1] = intersect(obsstr.sat, obj.sat);
[~,sidx2] = intersect(obsstr.sat, gobs.sat);
tidx1 = [1:(idx-1) (idx+gobs.n):(idx+gobs.n+obj.n)];
tidx2 = idx:(idx+gobs.n-1);
for f = obj.FTYPE
if ~isempty(obj.(f)) || ~isempty(gobs.(f))
obsstr.(f) = obj.initFreqStruct(f,obsstr.n,obsstr.nsat);
if ~isempty(obj.(f))
obsstr.(f) = obj.setFreqStruct(obsstr.(f),obj.(f),tidx1,1:obj.n,sidx1,1:obj.nsat);
end
if ~isempty(gobs.(f))
obsstr.(f) = obj.setFreqStruct(obsstr.(f),gobs.(f),tidx2,1:gobs.n,sidx2,1:gobs.nsat);
end
end
end
obj.setObsStruct(obsstr);
end
%% append
function append(obj, gobs)
% append: Append gt.Gobs object
% -------------------------------------------------------------
% Add gt.Gobs object.
% obj.n will be obj.n+gobs.n
%
% Usage: ------------------------------------------------------
% obj.append(gobs)
%
% Input: ------------------------------------------------------
% gobs : 1x1, gt.Gobs object
%
arguments
obj gt.Gobs
gobs gt.Gobs
end
obsstr.n = obj.n+gobs.n;
obsstr.sat = unique([obj.sat, gobs.sat]);
obsstr.nsat = length(obsstr.sat);
[obsstr.sys, obsstr.prn] = rtklib.satsys(obsstr.sat);
obsstr.satstr = rtklib.satno2id(obsstr.sat);
obsstr.ep = [obj.time.ep; gobs.time.ep];
obsstr.tow = [obj.time.tow; gobs.time.tow];
obsstr.week = [obj.time.week; gobs.time.week];
[~,sidx1] = intersect(obsstr.sat, obj.sat);
[~,sidx2] = intersect(obsstr.sat, gobs.sat);
for f = obj.FTYPE
if ~isempty(obj.(f)) || ~isempty(gobs.(f))
obsstr.(f) = obj.initFreqStruct(f,obsstr.n,obsstr.nsat);
if ~isempty(obj.(f))
obsstr.(f) = obj.setFreqStruct(obsstr.(f),obj.(f),1:obj.n,1:obj.n,sidx1,1:obj.nsat);
end
if ~isempty(gobs.(f))
obsstr.(f) = obj.setFreqStruct(obsstr.(f),gobs.(f),(obj.n+1):obsstr.n,1:gobs.n,sidx2,1:gobs.nsat);
end
end
end
% merge glofcn
glofcn_ = obj.glofcn;
obj.glofcn = NaN(1,obsstr.nsat);
obj.glofcn(sidx1) = glofcn_;
obj.glofcn(sidx2) = gobs.glofcn;
obj.setObsStruct(obsstr);
end
%% maskP
function maskP(obj, mask, freq)
% maskP: Apply mask to pseudorange observations
% -------------------------------------------------------------
% Mask size must be [obj.n, obj.nsat].
% The masked observations will be NaN.
%
% Usage: ------------------------------------------------------
% obj.maskP(mask, [freq])
%
% Input: ------------------------------------------------------
% mask : (obj.n)x(obj.nsat), Logical index array to mask
% [freq] : String array of frequency types to mask (e.g. "L1")
% (optional) Default: obj.FTYPE (all frequencies)
%
arguments
obj gt.Gobs
mask logical
freq string {mustBeMember(freq,["L1","L2","L5","L6","L7","L8","L9","Lwl","Lml","Lewl","Lif","ALL"])} = "ALL"
end
if size(mask,1)~=obj.n || size(mask,2)~=obj.nsat
error('mask array size does not match');
end
if freq=="ALL"
freq = obj.FTYPE;
end
for f = freq
if ~isempty(obj.(f))
if isfield(obj.(f),'P')
obj.(f).P(mask) = NaN;
end
if isfield(obj.(f),'resP')
obj.(f).resP(mask) = NaN;
obj.(f).resPc(mask) = NaN;
end
if isfield(obj.(f),'Pd')
obj.(f).Pd(mask) = NaN;
if isfield(obj.(f),'resPd')
obj.(f).resPd(mask) = NaN;
end
end
if isfield(obj.(f),'Pdd')
obj.(f).Pdd(mask) = NaN;
if isfield(obj.(f),'resPdd')
obj.(f).resPdd(mask) = NaN;
end
end
end
end
end
%% maskD
function maskD(obj, mask, freq)
% maskD: Apply mask to Doppler observations
% -------------------------------------------------------------
% Mask size must be [obj.n, obj.nsat].
% The masked observations will be NaN.
%
% Usage: ------------------------------------------------------
% obj.maskD(mask, [freq])
%
% Input: ------------------------------------------------------
% mask : (obj.n)x(obj.nsat), Logical index array to mask
% [freq] : String array of frequency types to mask (e.g. "L1")
% (optional) Default: obj.FTYPE (all frequencies)
%
arguments
obj gt.Gobs
mask logical
freq string {mustBeMember(freq,["L1","L2","L5","L6","L7","L8","L9","Lwl","Lml","Lewl","Lif","ALL"])} = "ALL"
end
if size(mask,1)~=obj.n || size(mask,2)~=obj.nsat
error('mask array size does not match');
end
if freq=="ALL"
freq = obj.FTYPE;
end
for f = freq
if ~isempty(obj.(f))
if isfield(obj.(f),'D')
obj.(f).D(mask) = NaN;
end
if isfield(obj.(f),'resD')
obj.(f).resD(mask) = NaN;
obj.(f).resDc(mask) = NaN;
end
if isfield(obj.(f),'Dd')
obj.(f).Dd(mask) = NaN;
if isfield(obj.(f),'resDd')
obj.(f).resDd(mask) = NaN;
end
end
end
end
end
%% maskL
function maskL(obj, mask, freq)
% maskL: Apply mask to carrier phase observations
% -------------------------------------------------------------
% Mask size must be [obj.n, obj.nsat].
% The masked observations will be NaN.
%
% Usage: ------------------------------------------------------
% obj.maskL(mask, [freq])
%
% Input: ------------------------------------------------------
% mask : (obj.n)x(obj.nsat), Logical index array to mask
% [freq] : String array of frequency types to mask (e.g. "L1")
% (optional) Default: obj.FTYPE (all frequencies)
%
arguments
obj gt.Gobs
mask logical
freq string {mustBeMember(freq,["L1","L2","L5","L6","L7","L8","L9","Lwl","Lml","Lewl","Lif","ALL"])} = "ALL"
end
if size(mask,1)~=obj.n || size(mask,2)~=obj.nsat
error('mask array size does not match');
end
if freq=="ALL"
freq = obj.FTYPE;
end
for f = freq
if ~isempty(obj.(f))
if isfield(obj.(f),'L')
obj.(f).L(mask) = NaN;
end
if isfield(obj.(f),'resL')
obj.(f).resL(mask) = NaN;
obj.(f).resLc(mask) = NaN;
end
if isfield(obj.(f),'Ld')
obj.(f).Ld(mask) = NaN;
if isfield(obj.(f),'resLd')
obj.(f).resLd(mask) = NaN;
end
end
if isfield(obj.(f),'Ldd')
obj.(f).Ldd(mask) = NaN;
if isfield(obj.(f),'resLdd')
obj.(f).resLdd(mask) = NaN;
end
end
end
end
end
%% mask
function mask(obj, mask, freq)
% mask: Apply mask to observations
% -------------------------------------------------------------
% Apply mask to pseudorange, Doppler, and carrier phase.
% Mask size must be [obj.n, obj.nsat].
% The masked observations will be NaN.
%
% Usage: ------------------------------------------------------
% obj.mask(mask, [freq])
%
% Input: ------------------------------------------------------
% mask : (obj.n)x(obj.nsat), Logical index array to mask
% [freq] : String array of frequency types to mask (e.g. "L1")
% (optional) Default: obj.FTYPE (all frequencies)
%
arguments
obj gt.Gobs
mask logical
freq string {mustBeMember(freq,["L1","L2","L5","L6","L7","L8","L9","Lwl","Lml","Lewl","Lif","ALL"])} = "ALL"
end
if size(mask,1)~=obj.n || size(mask,2)~=obj.nsat
error('mask array size does not match the observations');
end
obj.maskP(mask,freq);
obj.maskL(mask,freq);
obj.maskD(mask,freq);
end
%% maskLLI
function maskLLI(obj)
% maskLLI: Apply mask to carrier phase from LLI flag
% -------------------------------------------------------------
% Carrier phase observations for cycle slip and half-cycle slip
% will be NaN.
%
% Usage: ------------------------------------------------------
% obj.maskLLI()
%
arguments
obj gt.Gobs
end
for f = obj.FTYPE
if ~isempty(obj.(f))
mask = obj.(f).I>=1; % 1:cycle slip, 2or3:half-cycle slip
obj.maskL(mask,f);
end
end
end
%% eliminateNaN
function gobs = eliminateNaN(obj)
% eliminateNaN: Eliminate satellites whose observations are all NaN
% -------------------------------------------------------------
% If all pseudorange observations are NaN, eliminate the satellite.
%
% Usage: ------------------------------------------------------
% gobs = obj.eliminateNaN()
%
% Output: -----------------------------------------------------
% gobs: 1x1, gt.Gobs object with satellites eliminated
%
arguments
obj gt.Gobs
end
sidx = false(size(obj.sat));
for f = obj.FTYPE
if ~isempty(obj.(f))
sidx = sidx | any(~isnan(obj.(f).P));
end
end
gobs = obj.selectSat(sidx);
end
%% copy
function gobs = copy(obj)
% copy: Copy object
% -------------------------------------------------------------
% MATLAB handle class is used, so if you want to create a
% different object, you need to use the copy method.
%
% Usage: ------------------------------------------------------
% gobs = obj.copy()
%
% Output: -----------------------------------------------------
% gobs: 1x1, Copied gt.Gobs object
%
arguments
obj gt.Gobs
end
gobs = obj.select(1:obj.n,1:obj.nsat);
end
%% select
function gobs = select(obj, tidx, sidx)
% select: Select observation from time/satellite index
% -------------------------------------------------------------
% Select observation from time/satellite index and return a new object.
% The index may be a logical or numeric index.
%
% Usage: ------------------------------------------------------
% gobs = obj.select(tidx, sidx)
%
% Input: ------------------------------------------------------
% tidx : Logical or numeric index to select time
% sidx : Logical or numeric index to select satellite
%
% Output: -----------------------------------------------------
% gobs : 1x1, Selected gt.Gobs object
%
arguments
obj gt.Gobs
tidx {mustBeInteger, mustBeVector}
sidx {mustBeInteger, mustBeVector}
end
if ~any(tidx)
warning('Selected time index is empty');
gobs = gt.Gobs();
return
end
if ~any(sidx)
warning('Selected satellite index is empty');
gobs = gt.Gobs();
return
end
obsstr = obj.struct(tidx, sidx);
gobs = gt.Gobs(obsstr);
gobs.pos = obj.pos;
gobs.glofcn = obj.glofcn(sidx);
obj.copyFrequency(gobs,1:gobs.nsat,sidx);
obj.copyAdditinalObservation(gobs,1:gobs.n,tidx,1:gobs.nsat,sidx);
end
%% selectSat
function gobs = selectSat(obj, sidx)
% selectSat: Select observation from satellite index
% -------------------------------------------------------------
% Select observation from satellite index and return a new object.
% The index may be a logical or numeric index.
%
% Usage: ------------------------------------------------------
% gobs = obj.selectSat(sidx)
%
% Input: ------------------------------------------------------
% sidx : Logical or numeric index to select satellite
%
% Output: -----------------------------------------------------
% gobs : 1x1, Selected gt.Gobs object
%
arguments
obj gt.Gobs
sidx {mustBeInteger, mustBeVector}
end
gobs = obj.select(1:obj.n, sidx);
end
%% selectTime
function gobs = selectTime(obj, tidx)
% selectTime: Select observation from time index
% -------------------------------------------------------------
% Select observation from time index and return a new object.
% The index may be a logical or numeric index.
%
% Usage: ------------------------------------------------------
% gobs = obj.selectTime(tidx)
%
% Input: ------------------------------------------------------
% tidx : Logical or numeric index to select time
%
% Output: -----------------------------------------------------
% gobs: 1x1, Selected gt.Gobs object
%
arguments
obj gt.Gobs
tidx {mustBeInteger, mustBeVector}
end
gobs = obj.select(tidx, 1:obj.nsat);
end
%% selectTimeSpan
function gobs = selectTimeSpan(obj, ts, te)
% selectTimeSpan: Select observation from time span
% -------------------------------------------------------------
% Select observation from the time span and return a new object.
% The time span is start and end time represented by gt.Gtime.
%
% Usage: ------------------------------------------------------
% gobs = obj.selectTimeSpan(ts, te)
%
% Input: ------------------------------------------------------
% ts : 1x1, gt.Gtime, Start time
% te : 1x1, gt.Gtime, End time
%
% Output: -----------------------------------------------------
% gobs: 1x1, Selected gt.Gobs object
%
arguments
obj gt.Gobs
ts gt.Gtime
te gt.Gtime
end
tr = obj.roundDateTime(obj.time.t, obj.dt);
tsr = obj.roundDateTime(ts.t, obj.dt);
ter = obj.roundDateTime(te.t, obj.dt);
tidx = tr>=tsr & tr<=ter;
gobs = obj.selectTime(tidx);
end
%% struct
function obsstr = struct(obj, tidx, sidx)
% struct: Convert from gt.Gobs object to observation struct
% -------------------------------------------------------------
% The input to the RTKLIB wrapper function must be a structure.
% The index may be a logical or numeric index.
%
% Usage: ------------------------------------------------------
% obsstr = obj.struct([tidx], [sidx][)
%
% Input: ------------------------------------------------------
% [tidx]: Logical or numeric to select time (optional)
% Default: tidx = 1:obj.n
% [sidx]: Logical or numeric index to select satellite (optional)
% Default: sidx = 1:obj.nsat
%
% Output: -----------------------------------------------------
% obsstr: 1x1, Observation struct (for interface to RTKLIB)
%
arguments
obj gt.Gobs
tidx {mustBeInteger, mustBeVector} = 1:obj.n
sidx {mustBeInteger, mustBeVector} = 1:obj.nsat
end
obsstr.sat = obj.sat(sidx);
obsstr.prn = obj.prn(sidx);
obsstr.sys = double(obj.sys(sidx));
obsstr.satstr = obj.satstr(sidx);
obsstr.ep = obj.time.ep(tidx,:);
obsstr.tow = obj.time.tow(tidx);
obsstr.week = obj.time.week(tidx);
obsstr.n = size(obsstr.ep,1);
obsstr.nsat = size(obsstr.sat,2);
for f = obj.FTYPE
if ~isempty(obj.(f))
obsstr.(f) = obj.selectFreqStruct(obj.(f), tidx, sidx);
end
end
end
%% fixedInterval
function gobs = fixedInterval(obj, dt)
% fixedInterval: Resampling observation at fixed interval
% -------------------------------------------------------------
% The time interval of the observed value will be constant at
% the specified second.
%
% If the time interval of the original observation is not
% constant, NaN is inserted into the observation at that time.
%
% Usage: ------------------------------------------------------
% gobs = obj.fixedInterval([dt])
%
% Input: ------------------------------------------------------
% [dt] : 1x1, double, Time interval for resampling (s)
% (optional) Default: dt = obj.dt
%
% Output: -----------------------------------------------------
% gobs: 1x1, Resampled gt.Gobs object
%
arguments
obj gt.Gobs
dt (1,1) double = 0
end
if dt==0; dt = obj.dt; end
tr = obj.roundDateTime(obj.time.t, obj.dt);
tfixr = obj.roundDateTime((tr(1):seconds(dt):tr(end))', dt);
nfix = length(tfixr);
tfix = NaT(nfix,1,"TimeZone","UTC");
[~, idx1,idx2] = intersect(tfixr,tr);
tfix(idx1) = obj.time.t(idx2);
tfix = fillmissing(tfix,'linear');
gtfix = gt.Gtime(tfix);
obsstr.n = nfix;
obsstr.nsat = obj.nsat;
obsstr.sat = obj.sat;
obsstr.prn = obj.prn;
obsstr.sys = double(obj.sys);
obsstr.satstr = obj.satstr;
obsstr.ep = gtfix.ep;
obsstr.tow = gtfix.tow;
obsstr.week = gtfix.week;
for f = obj.FTYPE
if ~isempty(obj.(f))
obsstr.(f) = obj.initFreqStruct(f,obsstr.n,obsstr.nsat);
obsstr.(f) = obj.setFreqStruct(obsstr.(f),obj.(f),idx1,idx2,1:obj.nsat,1:obj.nsat);
end
end
gobs = gt.Gobs(obsstr);
gobs.pos = obj.pos;
gobs.glofcn = obj.glofcn;
end
%% commonObs
function [gobsc, gobsrefc] = commonObs(obj, gobsref)
% commonObs: Extract common observation with reference observation
% -------------------------------------------------------------
% Extract the common time and satellite observations between
% the reference gt.Gobs object and the current object.
%
% Output new gt.Gobs object and reference gt.Gobs object.
%
% gobsc.time = obsrefc.time
% gobsc.sat = obsrefc.sat
%
% Usage: ------------------------------------------------------
% [gobsc, gobsrefc] = obj.commonObs(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobsc : 1x1, New gt.Gobs object
% gobsrefc: 1x1, New reference gt.Gobs object
%
arguments
obj gt.Gobs
gobsref gt.Gobs
end
[gobsc, gobsrefc] = obj.commonSat(gobsref);
[gobsc, gobsrefc] = gobsc.commonTime(gobsrefc);
end
%% commonSat
function [gobsc, gobsrefc] = commonSat(obj, gobsref)
% commonSat: Extract common satellite with reference observation
% -------------------------------------------------------------
% Extract the common satellites between the reference gt.Gobs
% object and the current object.
%
% Output new gt.Gobs object and reference gt.Gobs object.
%
% gobsc.sat = obsrefc.sat
%
% Usage: ------------------------------------------------------
% [gobsc, gobsrefc] = obj.commonObs(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobsc : 1x1, New gt.Gobs object
% gobsrefc: 1x1, New reference gt.Gobs object
%
arguments
obj gt.Gobs
gobsref gt.Gobs
end
[~,sidx1,sidx2] = intersect(obj.sat,gobsref.sat);
gobsc = obj.selectSat(sidx1);
gobsrefc = gobsref.selectSat(sidx2);
end
%% commonTime
function [gobsc, gobsrefc] = commonTime(obj, gobsref)
% commonTime: Extract common time with reference observation
% -------------------------------------------------------------
% Extract the common time between the reference gt.Gobs object
% and the current object.
%
% Output new gt.Gobs object and reference gt.Gobs object.
%
% gobsc.time = gobsrefc.time
%
% Usage: ------------------------------------------------------
% [gobsc, gobsrefc] = obj.commonObs(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobsc : 1x1, New gt.Gobs object
% gobsrefc: 1x1, New reference gt.Gobs object
%
arguments
obj gt.Gobs
gobsref gt.Gobs
end
t = obj.roundDateTime(obj.time.t, obj.dt);
tref = obj.roundDateTime(gobsref.time.t, gobsref.dt);
[~,tidx1,tidx2] = intersect(t,tref);
gobsc = obj.selectTime(tidx1);
gobsrefc = gobsref.selectTime(tidx2);
end
%% sameObs
function gobs = sameObs(obj, gobsref)
% sameObs: Same satellite and time as reference observation
% -------------------------------------------------------------
% Create an gt.Gobs object whose time and satellite are
% consistent with the reference gt.Gobs object.
%
% gobs.time = gobsref.time
% gobs.sat = gobsref.sat
%
% If the time or satellite of the reference observation is not
% included in the current observation, NaN is inserted into the
% observations.
%
% Usage: ------------------------------------------------------
% gobs = obj.sameObs(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobs : 1x1, New gt.Gobs object
%
arguments
obj gt.Gobs
gobsref gt.Gobs
end
gobs = obj.sameSat(gobsref);
gobs = gobs.sameTime(gobsref);
end
%% sameSat
function gobs = sameSat(obj, gobsref)
% sameSat: Same satellite as reference observation
% -------------------------------------------------------------
% Create an gt.Gobs object whose satellite are consistent with
% the reference gt.Gobs object.
%
% gobs.sat = gobsref.sat
%
% If the satellite of the reference observation is not
% in the current observation, NaN is inserted into the
% observations.
%
% Usage: ------------------------------------------------------
% gobs = obj.sameSat(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobs : 1x1, New gt.Gobs object
%
arguments
obj gt.Gobs
gobsref gt.Gobs
end
[~,sidx1,sidx2] = intersect(gobsref.sat,obj.sat);
obsstr.n = obj.n;
obsstr.nsat = gobsref.nsat;
obsstr.sat = gobsref.sat;
obsstr.ep = obj.time.ep;
for f = obj.FTYPE
if ~isempty(obj.(f))
obsstr.(f) = obj.initFreqStruct(f,obsstr.n,obsstr.nsat);
obsstr.(f) = obj.setFreqStruct(obsstr.(f),obj.(f),1:obj.n,1:obj.n,sidx1,sidx2);
end
end
gobs = gt.Gobs(obsstr);
gobs.pos = obj.pos;
gobs.glofcn = gobsref.glofcn;
obj.copyAdditinalObservation(gobs,1:gobs.n,1:gobs.n,sidx1,sidx2);
end
%% sameTime
function gobs = sameTime(obj, gobsref)
% sameTime: Same time as reference observation
% -------------------------------------------------------------
% Create an gt.Gobs object whose time are consistent with
% the reference gt.Gobs object.
%
% gobs.time = gobsref.time
%
% If the time of the reference observation is not
% in the current observation, NaN is inserted into the
% observations.
%
% Usage: ------------------------------------------------------
% gobs = obj.sameTime(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobs : 1x1, New gt.Gobs object
%