SXGOODFIX Discard null and repeated fixes in SeaExplorer position data. Syntax: GOOD = SXGOODFIX(LONGITUDE, LATITUDE, STATE) Description: GOOD = SXGOODFIX(LONGITUDE, LATITUDE, STATE) returns a boolean vector GOOD indicating whether the position coordinates in vectors LONGITUDE and LATITUDE taken in the glider state in vector STATE are taken in the right state, are valid and not null, and are not a repetition of the previous fix (see note on defects of SeaExplorer position data). Notes: SeaExplorer position data both in glider and payload data set is defective. According to the manufacturer, SeaExplorer gliders can only get valid GPS fixes while the glider is in 'transmitting state' (116). The glider state and the fix coordinates (in NMEA degrees format) are the columns `NAV_RESOURCE`, `NAV_LONGITUDE`, and `NAV_LATITUDE` in the glider data set, and the columns `Lon`, `Lat`, and `NavState` in the payload data set. However, wrong position coordinates may appear even in the right state: - Entries equal to [0, 0] may appear when there is no proper fix instead of the expected value [NaN, NaN]. - Apparently right entries that are in fact repetitions of the previous fix, which can be taken too far away in the past. Hence, this function flags a position as good only if: - It was taken in the right state ('transmitting state', 116). - The coordinates are valid (not NaN). - It is not null (both coordinates equal to zero). - It differs from the previous good position. Note that the last two conditions may discard potentially valid fixes: fixes effectively at the location [0, 0] (it is not on land), or consecutive fixes that are effectively at the same location or so close that due to the number of decimal digits used in the data file they result in the same NMEA coordinates (although with 3 decimal digits in NMEA degrees points at a distance of >=3 meters should have distinguishable coordinates at all locations). Examples: data = [105 0.000 0.000 115 0.000 0.000 115 0.000 0.000 116 0.000 0.000 116 0.000 0.000 116 4303.860 641.011 116 4303.857 641.004 116 4303.852 640.996 116 4303.848 640.989 110 4303.848 640.989 110 4303.848 640.989 NaN NaN NaN NaN NaN NaN NaN NaN NaN 117 4303.848 640.989 117 4303.848 640.989 116 4303.848 640.989 116 4303.479 642.385 116 4303.477 642.377 116 4303.477 642.377 116 4303.471 642.363 116 4303.467 642.355 116 4303.467 642.355 116 4303.467 642.355 116 4303.449 642.313 116 4303.442 642.299]; longitude = data(:, 3); latitude = data(:, 2); state = data(:, 1); good = sxgoodfix(longitude,latitude, state) data(good, :) Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function good = sxgoodfix(longitude, latitude, state) 0002 %SXGOODFIX Discard null and repeated fixes in SeaExplorer position data. 0003 % 0004 % Syntax: 0005 % GOOD = SXGOODFIX(LONGITUDE, LATITUDE, STATE) 0006 % 0007 % Description: 0008 % GOOD = SXGOODFIX(LONGITUDE, LATITUDE, STATE) returns a boolean vector 0009 % GOOD indicating whether the position coordinates in vectors LONGITUDE 0010 % and LATITUDE taken in the glider state in vector STATE are taken in the 0011 % right state, are valid and not null, and are not a repetition of the 0012 % previous fix (see note on defects of SeaExplorer position data). 0013 % 0014 % Notes: 0015 % SeaExplorer position data both in glider and payload data set is defective. 0016 % According to the manufacturer, SeaExplorer gliders can only get valid GPS 0017 % fixes while the glider is in 'transmitting state' (116). 0018 % The glider state and the fix coordinates (in NMEA degrees format) 0019 % are the columns `NAV_RESOURCE`, `NAV_LONGITUDE`, and `NAV_LATITUDE` 0020 % in the glider data set, and the columns `Lon`, `Lat`, and `NavState` 0021 % in the payload data set. However, wrong position coordinates may appear 0022 % even in the right state: 0023 % - Entries equal to [0, 0] may appear when there is no proper fix 0024 % instead of the expected value [NaN, NaN]. 0025 % - Apparently right entries that are in fact repetitions of the previous 0026 % fix, which can be taken too far away in the past. 0027 % Hence, this function flags a position as good only if: 0028 % - It was taken in the right state ('transmitting state', 116). 0029 % - The coordinates are valid (not NaN). 0030 % - It is not null (both coordinates equal to zero). 0031 % - It differs from the previous good position. 0032 % 0033 % Note that the last two conditions may discard potentially valid fixes: 0034 % fixes effectively at the location [0, 0] (it is not on land), 0035 % or consecutive fixes that are effectively at the same location 0036 % or so close that due to the number of decimal digits used in the data file 0037 % they result in the same NMEA coordinates (although with 3 decimal digits 0038 % in NMEA degrees points at a distance of >=3 meters should have 0039 % distinguishable coordinates at all locations). 0040 % 0041 % Examples: 0042 % data = [105 0.000 0.000 0043 % 115 0.000 0.000 0044 % 115 0.000 0.000 0045 % 116 0.000 0.000 0046 % 116 0.000 0.000 0047 % 116 4303.860 641.011 0048 % 116 4303.857 641.004 0049 % 116 4303.852 640.996 0050 % 116 4303.848 640.989 0051 % 110 4303.848 640.989 0052 % 110 4303.848 640.989 0053 % NaN NaN NaN 0054 % NaN NaN NaN 0055 % NaN NaN NaN 0056 % 117 4303.848 640.989 0057 % 117 4303.848 640.989 0058 % 116 4303.848 640.989 0059 % 116 4303.479 642.385 0060 % 116 4303.477 642.377 0061 % 116 4303.477 642.377 0062 % 116 4303.471 642.363 0063 % 116 4303.467 642.355 0064 % 116 4303.467 642.355 0065 % 116 4303.467 642.355 0066 % 116 4303.449 642.313 0067 % 116 4303.442 642.299]; 0068 % longitude = data(:, 3); 0069 % latitude = data(:, 2); 0070 % state = data(:, 1); 0071 % good = sxgoodfix(longitude,latitude, state) 0072 % data(good, :) 0073 % 0074 % Authors: 0075 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0076 0077 % Copyright (C) 2016 0078 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears. 0079 % <http://www.socib.es> 0080 % 0081 % This program is free software: you can redistribute it and/or modify 0082 % it under the terms of the GNU General Public License as published by 0083 % the Free Software Foundation, either version 3 of the License, or 0084 % (at your option) any later version. 0085 % 0086 % This program is distributed in the hope that it will be useful, 0087 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0088 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0089 % GNU General Public License for more details. 0090 % 0091 % You should have received a copy of the GNU General Public License 0092 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0093 0094 error(nargchk(3, 3, nargin, 'struct')); 0095 0096 good = (state == 116) ... 0097 & ~(isnan(longitude) | isnan(latitude)) ... 0098 & ~((longitude == 0) & (latitude == 0)); 0099 good_indices = find(good); 0100 good(good_indices(2:end)) = (diff(longitude(good)) ~= 0) ... 0101 & (diff(latitude (good)) ~= 0); 0102 0103 end