How to determine dates when aircraft moving northwards or southwards?

Hello community,
I have a aircraft track dataset name Test.xlsx attached. It contains time, latitude, longitude and height of aircraft tracks. Now I want to find the dates when aircraft was heading towards north and also dates when aircraft heading towards south.
I am at beginner stage of coding, therefore, looking forward to any helps.
Thanks in advance.

 Accepted Answer

I am not certain that I understand what you want.
This approach uses day differences to segment the data into individual ‘FlightLeg’ cell arrays (segments of a given flight are referred to as ‘legs’), each cell array being a separate table. It then plots the legs, determines whether it was northbound or southbound, retains that information, as well as the start and end times of each ‘FlightLeg’ in the ‘DateRange’ cell array, and plots them with specific colours. (It almost takes longer to describe what the code does than it took to write it!)
Try this —
T1 = readtable('Test.xlsx', 'VariableNamingRule','preserve')
T1 = 16059×4 table
Var1 Obs_Lat Obs_Lon Alt(m) ____________________ _______ _______ ______ 24-Mar-2010 18:01:00 40.39 -104.96 5088.6 24-Mar-2010 18:01:00 40.4 -104.95 5164.1 24-Mar-2010 18:01:00 40.42 -104.95 5238.8 24-Mar-2010 18:01:00 40.44 -104.95 5314.9 24-Mar-2010 18:02:00 40.46 -104.94 5390.5 24-Mar-2010 18:02:00 40.47 -104.94 5466.1 24-Mar-2010 18:02:00 40.49 -104.93 5541.8 24-Mar-2010 18:02:00 40.51 -104.93 5617.5 24-Mar-2010 18:02:00 40.53 -104.93 5693.2 24-Mar-2010 18:02:00 40.54 -104.92 5770.1 24-Mar-2010 18:03:00 40.56 -104.92 5846.9 24-Mar-2010 18:03:00 40.58 -104.91 5922.5 24-Mar-2010 18:03:00 40.6 -104.91 5998.4 24-Mar-2010 18:03:00 40.62 -104.9 6073.9 24-Mar-2010 18:03:00 40.64 -104.9 6149.5 24-Mar-2010 18:03:00 40.65 -104.9 6226
Time = day(T1{:,1}, 'dayofyear'); % Assumes All Flights In Same Year
TimeG = cumsum(diff([0; Time]) ~= 0); % Mark Non-Consecutive Days As Groups
FlightLegs = accumarray(TimeG, (1:size(T1,1)).', [], @(x){T1(x,:)}) % Use 'TimeG' (Non-Consecutive Day Groups) To Segment Flight Legs
FlightLegs = 13×1 cell array
{1852×4 table} { 255×4 table} {2084×4 table} { 734×4 table} {2090×4 table} { 819×4 table} {1245×4 table} { 144×4 table} {1169×4 table} {1319×4 table} {1577×4 table} {2055×4 table} { 716×4 table}
figure
hold on
for k = 1:numel(FlightLegs)
hFL{k} = plot3(FlightLegs{k}{:,3}, FlightLegs{k}{:,2}, FlightLegs{k}{:,1}, 'LineWidth',2); % Plot Flight Leg
if FlightLegs{k}{end,2} > FlightLegs{k}{1,2} % End Latitude > Start Latitude => 'N'
DateRange{k} = [FlightLegs{k}{1,2}; FlightLegs{k}{end,2}]; % Flight Leg: Start & End Times
FLDir{k} = 'N'; % Mark: 'N'
hFL{k}.Color = 'b'; % Color: Blue
else % Same Data For Southbound Legs
DateRange{k} = [FlightLegs{k}{1,2}; FlightLegs{k}{end,2}];
FLDir{k} = 'S';
hFL{k}.Color = 'r';
end
end
hold off
xlabel('Lon')
ylabel('Lat')
zlabel('Time')
grid on
view(30,30)
legend([hFL{1} hFL{4}],'Northbound','Southbound')
I did not plot it on a map because I do not know what map you are using, and lacking the Mapping Toolbox (so I have very little experience with it), am not certain how to do that anyway.
.

4 Comments

@Star Strider Thanks for you response. I don't want to put time on z axis. I want to correctly show whether one particular (lat,lon) corresponds to northbound (aircraft heading north) or southbounds ( aircraft heading south). Earlier comment by @William Rose was helpful but yet not what it actually should come. I am trying to figure it out. I have put Coming.png and expected.png for you if only norther hemis. is considered.
Hope Im clear. Otherwise i may share more info if required.
Thanks once again.
Cheers
I plotted it as I did simply to demonstrate how my code works and what it produces.
Obviously, a single Lat/Lon cannot determine a direction, since it is necessary to compare it with earlier and later Lat/Lon values to determine that. My code breaks up the flight into legs separated by day differences in order to determine the direction of a particular leg. It determines the N/S direction by comparing the latitude at the start of the leg and the latitude and the end of the leg. It does not calculate directions based on any segment of a leg.
It is straightforward to ‘flatten’ the plot to elimiinate the time variation and keep all the other inforrmation —
T1 = readtable('Test.xlsx', 'VariableNamingRule','preserve')
T1 = 16059×4 table
Var1 Obs_Lat Obs_Lon Alt(m) ____________________ _______ _______ ______ 24-Mar-2010 18:01:00 40.39 -104.96 5088.6 24-Mar-2010 18:01:00 40.4 -104.95 5164.1 24-Mar-2010 18:01:00 40.42 -104.95 5238.8 24-Mar-2010 18:01:00 40.44 -104.95 5314.9 24-Mar-2010 18:02:00 40.46 -104.94 5390.5 24-Mar-2010 18:02:00 40.47 -104.94 5466.1 24-Mar-2010 18:02:00 40.49 -104.93 5541.8 24-Mar-2010 18:02:00 40.51 -104.93 5617.5 24-Mar-2010 18:02:00 40.53 -104.93 5693.2 24-Mar-2010 18:02:00 40.54 -104.92 5770.1 24-Mar-2010 18:03:00 40.56 -104.92 5846.9 24-Mar-2010 18:03:00 40.58 -104.91 5922.5 24-Mar-2010 18:03:00 40.6 -104.91 5998.4 24-Mar-2010 18:03:00 40.62 -104.9 6073.9 24-Mar-2010 18:03:00 40.64 -104.9 6149.5 24-Mar-2010 18:03:00 40.65 -104.9 6226
Time = day(T1{:,1}, 'dayofyear'); % Assumes All Flights In Same Year
TimeG = cumsum(diff([0; Time]) ~= 0); % Mark Non-Consecutive Days As Groups
FlightLegs = accumarray(TimeG, (1:size(T1,1)).', [], @(x){T1(x,:)}); % Use 'TimeG' (Non-Consecutive Day Groups) To Segment Flight Legs
figure
hold on
for k = 1:numel(FlightLegs)
hFL{k} = plot3(FlightLegs{k}{:,3}, FlightLegs{k}{:,2}, FlightLegs{k}{:,1}, 'LineWidth',2); % Plot Flight Leg
if FlightLegs{k}{end,2} > FlightLegs{k}{1,2} % End Latitude > Start Latitude => 'N'
DateRange{k} = [FlightLegs{k}{1,2}; FlightLegs{k}{end,2}]; % Flight Leg: Start & End Times
FLDir{k} = 'N'; % Mark: 'N'
hFL{k}.Color = 'b'; % Color: Blue
else % Same Data For Southbound Legs
DateRange{k} = [FlightLegs{k}{1,2}; FlightLegs{k}{end,2}];
FLDir{k} = 'S';
hFL{k}.Color = 'r';
end
end
hold off
xlabel('Lon')
ylabel('Lat')
zlabel('Time')
grid on
view(0,90)
legend([hFL{1} hFL{4}],'Northbound','Southbound')
.

Sign in to comment.

More Answers (1)

I would do it in this way
Test = readtimetable("Test.xlsx","VariableNamingRule","preserve"); % to import data (or using Import Data tool)
d = diff(Test.Obs_Lat); % difference between latitudes
south = Test.Time(find(d<0)); % if the right element is lower than left element the aircraft heads south
north = Test.Time(find(d>0)); % otherwise tha aicraft heads north

3 Comments

@Selena Mastrodonato Thanks for your quick reply. I tried with given code using the Test.xlsx
I am getting Coming.png but I expected something like expect.png (reliable source). Here, red for northwards and blue for southwards for both figures.
Looking forward to anymore suggestion.
Thanks in adance.
@Selena Mastrodonato, excellent answer!
[Edit: change red and blue colors in plot, to match the colors used by @Subhodh Sharma. Add comments about the plotting code.]
You can also leave out the "find()" function and get the exact same results:
Test = readtimetable("Test.xlsx","VariableNamingRule","preserve"); % to import data (or using Import Data tool)
d = diff(Test.Obs_Lat); % difference between latitudes
south = Test.Time(d<0); % if the right element is lower than left element the aircraft heads south
north = Test.Time(d>0); % otherwise tha aicraft heads north
Or you could eliminate d entirely.
Test = readtimetable("Test.xlsx","VariableNamingRule","preserve"); % to import data (or using Import Data tool)
south = Test.Time(diff(Test.Obs_Lat)<0); % if the right element is lower than left element the aircraft heads south
north = Test.Time(diff(Test.Obs_Lat)>0); % otherwise tha aicraft heads north
@Selena Mastrodonato uses many comments to explain her code. May we all follow her good example.
"otherwise the aircraft heads north" suggests an aircraft must have non-zero north/ south velocity at all times. However, the north-south velocity could be zero, and sometimes is, in this example. The code correctly find the times when the norh-south velocity is non-zero.
Make a plot:
plot(Test.Obs_Lon,Test.Obs_Lat,'-k',...
Test.Obs_Lon(d>0),Test.Obs_Lat(d>0),'-r',...
Test.Obs_Lon(d<0),Test.Obs_Lat(d<0),'-b')
legend('Entire Track','Northbound','Southbound') %add legend
grid on; xlabel('Longitude'); ylabel('Latitude') %grid, axis titles
The plotting code above does not attempt to identify separate flight segments. Therefore the plot includes straight lines connecting the end of one segent to the start of a separate segment. You could identify separate flight segments by finding where the time or the position changes by a large amount from one row to the next.
Good luck.
@Subhodh Sharma, The difference between Coming.png and Expected.png may be due to the order in which the north and south plots were done, since they overlap one another.
Provide the code you used to make Coming.png, if you want further assistance.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!