How to determine dates when aircraft moving northwards or southwards?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Subhodh Sharma
le 10 Mai 2023
Commenté : Star Strider
le 10 Mai 2023
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.
0 commentaires
Réponse acceptée
Star Strider
le 10 Mai 2023
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')
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(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 commentaires
Plus de réponses (1)
Selena Mastrodonato
le 10 Mai 2023
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 commentaires
William Rose
le 10 Mai 2023
Modifié(e) : William Rose
le 10 Mai 2023
@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.
William Rose
le 10 Mai 2023
@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.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!