Commit 45d5c4586161f2c293bc780d0b6203326ff69055

Authored by Dany Dumont
0 parents
Exists in master and in 2 other branches mingan, simon

Premier depot de track

Showing 3 changed files with 285 additions and 0 deletions   Show diff stats
gpx2mat.m 0 โ†’ 100644
  1 +++ a/gpx2mat.m
... ... @@ -0,0 +1,72 @@
  1 +function gpx2mat(gpxfile)
  2 +% GPX2MAT - Convert gpx files to mat files
  3 +%
  4 +% Syntax: gpx2mat(gpxfile)
  5 +%
  6 +% Inputs:
  7 +% gpxfile - The name of the gpx file to convert, excluding the .gpx
  8 +% extension
  9 +%
  10 +% Example:
  11 +% g_interp('spot_device')
  12 +%
  13 +% Other m-files required: gpxread
  14 +% Subfunctions: none
  15 +%
  16 +% See also: GPXREAD, TR_MAP, TR_MERGE
  17 +
  18 +% Author: Dany Dumont
  19 +% UQAR/ISMER
  20 +% email: dany_dumont@uqar.ca
  21 +% Website: http://www.ismer.ca/dumont-dany
  22 +% September 2014
  23 +% ______________________________________________________________________
  24 +%
  25 +
  26 +curdir = pwd;
  27 +matdir = [curdir,'/mat'];
  28 +
  29 +file = dir(['./',gpxfile,'.gpx']);
  30 +
  31 +wpt = gpxread(file.name);
  32 +
  33 +lat = wpt.Latitude;
  34 +lon = wpt.Longitude;
  35 +clock = wpt.Time;
  36 +
  37 +trk = gpxread(file.name,'FeatureType','track','Index',1);
  38 +
  39 +ind = 0;
  40 +while ~isempty(trk)
  41 + ind = ind + 1;
  42 + trk = gpxread(file.name,'FeatureType','track','Index',ind);
  43 + if ~isempty(trk)
  44 + lat = [lat trk.Latitude];
  45 + lon = [lon trk.Longitude];
  46 + clock = [clock trk.Time];
  47 + end
  48 +end
  49 +
  50 +N = length(lat);
  51 +
  52 +for n = 1:N
  53 +
  54 + yr(n) = str2double(clock{n}(1:4));
  55 + mo(n) = str2double(clock{n}(6:7));
  56 + da(n) = str2double(clock{n}(9:10));
  57 + hh(n) = str2double(clock{n}(12:13));
  58 + mm(n) = str2double(clock{n}(15:16));
  59 + ss(n) = str2double(clock{n}(18:19));
  60 +
  61 + time(n) = datenum([yr(n) mo(n) da(n) hh(n) mm(n) ss(n)]);
  62 +end
  63 +
  64 +data = [time' lon' lat'];
  65 +
  66 +data = sortrows(data,1);
  67 +
  68 +if ~exist(matdir,'dir')
  69 + mkdir(matdir)
  70 +end
  71 +
  72 +save([matdir,'/',gpxfile],'data');
... ...
tr_map.m 0 โ†’ 100644
  1 +++ a/tr_map.m
... ... @@ -0,0 +1,158 @@
  1 +function tr_map
  2 +% TR_MAP - Display and save a map showing drifter trajectories specified
  3 +% in the input file.
  4 +%
  5 +% Syntax: tr_map
  6 +%
  7 +% Inputs: The function reads an ascii input file called infile, which
  8 +% must be written according to the following rules:
  9 +% - The first line indicates the number of trajectories or GPS
  10 +% devices to plot.
  11 +% - The second line indicates the name of the device (e.g. spot15).
  12 +% - The third line indicates the name of the mat file containing
  13 +% the trajectory data. This file must be located in a directory
  14 +% called mat/, which is located where infile is.
  15 +% - Subsequent lines indicate, in the same order, the name of the
  16 +% device and the name the mat file. The number of devices must
  17 +% equal the number specified at the first line.
  18 +%
  19 +%
  20 +% Example of infile:
  21 +%
  22 +% 3
  23 +% spot15
  24 +% spot15_20140910a
  25 +% spot17
  26 +% spot17_20140912a
  27 +% spot19
  28 +% spot19_20140910a
  29 +%
  30 +%
  31 +% Other m-files required: Image Processing Toolbox
  32 +% Subfunctions: none
  33 +% MAT-files required: none
  34 +%
  35 +% See also: TR_MERGE, GPX2MAT
  36 +%
  37 +% Author: Dany Dumont
  38 +% UQAR/ISMER
  39 +% email: dany_dumont@uqar.ca
  40 +% Website: http://www.ismer.ca/dumont-dany
  41 +% September 2014
  42 +% ______________________________________________________________________
  43 +
  44 +
  45 +curdir = pwd;
  46 +matdir = [curdir,'/mat'];
  47 +
  48 +if ~exist(matdir)
  49 + disp(' ERROR : The /mat directory does not exist. Make')
  50 + disp(' sure mat files exist and that they ')
  51 + disp(' are placed in a directory named mat. ')
  52 + return
  53 +end
  54 +
  55 +if exist('infile')
  56 + fid = fopen('infile');
  57 +else
  58 + disp(' ERROR : You need an input file named infile ')
  59 + disp(' which must be written according to the ')
  60 + disp(' following rules: ')
  61 + disp(' 3 % # of trajectories ')
  62 + disp(' spot15 % device 1 ')
  63 + disp(' spot15_20140910a % mat file of device 1')
  64 + disp(' spot17 % device 2 ')
  65 + disp(' spot17_20140912a % mat file of device 2')
  66 + disp(' spot19 % device 3 ')
  67 + disp(' spot19_20140910a % mat file of device 3')
  68 + return
  69 +end
  70 +
  71 +ndstr = fgetl(fid);
  72 +nd = str2double(ndstr);
  73 +
  74 +lonmin = 360;
  75 +lonmax = -360;
  76 +latmin = 90;
  77 +latmax = -90;
  78 +
  79 +for n = 1:nd
  80 + A(n).dev = fgetl(fid);
  81 + A(n).file = fgetl(fid);
  82 + load([matdir,'/',A(n).file]);
  83 +
  84 + [~,ds] = legs(data(:,3),data(:,2)); % distance (nm)
  85 + dt = data(2:end,1) - data(1:end-1,1); % time difference (days)
  86 + v = 1000.*nm2km(ds)./(dt.*86400); % average speed (m s-1)
  87 + travel = nm2km(sum(ds)); % km
  88 +
  89 + A(n).data = data;
  90 + A(n).ds = ds;
  91 + A(n).dt = dt;
  92 + A(n).v = v;
  93 + A(n).travel = travel;
  94 +
  95 + lonmin = min(lonmin,min(A(n).data(:,2)));
  96 + lonmax = max(lonmax,max(A(n).data(:,2)));
  97 + latmin = min(latmin,min(A(n).data(:,3)));
  98 + latmax = max(latmax,max(A(n).data(:,3)));
  99 +end
  100 +
  101 +%% Compute and display relevant quantities
  102 +
  103 +disp(' -------------- Summary -------------- ')
  104 +disp(' ')
  105 +for n = 1:nd
  106 + disp([' ',A(n).dev]);
  107 + disp(' ')
  108 + disp([' Number of points : ',num2str(length(A(n).data(:,2)))]);
  109 + disp([' Total travel : ',num2str(A(n).travel),' km']);
  110 + disp([' Initial position : ',num2str(A(n).data(1,2)),'E, ',num2str(A(n).data(1,3)),'N']);
  111 + disp([' Final position : ',num2str(A(n).data(end,2)),'E, ',num2str(A(n).data(end,3)),'N']);
  112 + disp([' Deployment time : ',datestr(A(n).data(1,1))]);
  113 + disp([' Beach time : ',datestr(A(n).data(end,1))]);
  114 + disp([' Total time : ',num2str(A(n).data(end,1) - A(n).data(1,1)),' days']);
  115 + disp([' Average speed : ',num2str(1000.*A(n).travel./(86400.*(A(n).data(end,1) - A(n).data(1,1)))),' m/s']);
  116 + disp(' ')
  117 +end
  118 +disp(' -------------------------------------- ')
  119 +
  120 +
  121 +%% Create the map
  122 +% Track and land colors
  123 +trk(1,:,1) = [0.8 0.2 0.2];
  124 +trk(1,:,2) = [0.2 0.8 0.2];
  125 +trk(1,:,3) = [0.2 0.2 0.8];
  126 +trk(1,:,4) = [0.4 0.2 0.8];
  127 +trk(1,:,5) = [0.2 0.4 0.8];
  128 +
  129 +%land_color = [241 235 144]./255;
  130 +land_color = [0.7 0.7 0.7];
  131 +
  132 +% Close-up
  133 +tol = (lonmax - lonmin)./10;
  134 +lonmin = lonmin - tol;
  135 +lonmax = lonmax + tol;
  136 +latmin = latmin - tol;
  137 +latmax = latmax + tol;
  138 +
  139 +figure(1)
  140 +m_proj('mercator', ...
  141 + 'longitudes',[lonmin lonmax], ...
  142 + 'latitudes',[latmin latmax]);
  143 +
  144 +m_gshhs_f('patch',land_color);
  145 +hold on
  146 +
  147 +for n = 1:nd
  148 + h(n) = m_plot(A(n).data(:,2),A(n).data(:,3),'-o','LineWidth',2, ...
  149 + 'Color',trk(1,:,n), ...
  150 + 'MarkerSize',1, ...
  151 + 'MarkerFaceColor',trk(1,:,n));
  152 +end
  153 +
  154 +m_grid('box','fancy','linestyle','none','fontsize',13,'fontname','Verdana');
  155 +hold off
  156 +
  157 +print(gcf,'map.png','-dpng','-painters');
  158 +print(gcf,'map.eps','-depsc2','-painters');
0 159 \ No newline at end of file
... ...
tr_merge.m 0 โ†’ 100644
  1 +++ a/tr_merge.m
... ... @@ -0,0 +1,55 @@
  1 +function tr_merge(dev)
  2 +% TR_MERGE - Merge trajectories of multiple mat files in a single one,
  3 +% supposing that all pieces are parts of the same trajectory.
  4 +%
  5 +% Syntax: tr_merge(dev)
  6 +%
  7 +% Inputs:
  8 +% dev - name of the device, which appear in the first part of the files
  9 +% to merge.
  10 +%
  11 +% Example:
  12 +% tr_merge('spot24')
  13 +%
  14 +%
  15 +% Other m-files required: none
  16 +% Subfunctions: none
  17 +% MAT-files required: Trajectory files to merge.
  18 +%
  19 +% See also: TR_MAP, GPX2MAT
  20 +%
  21 +% Author: Dany Dumont
  22 +% UQAR/ISMER
  23 +% email: dany_dumont@uqar.ca
  24 +% Website: http://www.ismer.ca/dumont-dany
  25 +% September 2014
  26 +% ______________________________________________________________________
  27 +
  28 +
  29 +curdir = pwd;
  30 +matdir = [curdir,'/mat'];
  31 +
  32 +if ~exist(matdir)
  33 + disp(' ERROR : The /mat directory does not exist. Make')
  34 + disp(' sure mat files exist and that they ')
  35 + disp(' are placed in a directory named mat. ')
  36 + return
  37 +end
  38 +
  39 +files = dir([matdir,'/',dev,'_*.mat']);
  40 +nf = length(files);
  41 +
  42 +A = [];
  43 +for n = 1:nf
  44 + load([matdir,'/',files(n).name]);
  45 + A = cat(1,A,data);
  46 +end
  47 +
  48 +% Sort rows chronologically
  49 +A = sortrows(A,1);
  50 +% Remove time replicates
  51 +A = unique(A,'rows','first');
  52 +
  53 +data = A;
  54 +
  55 +save([matdir,'/',dev,'_merged'],'data');
0 56 \ No newline at end of file
... ...