Clear Filters
Clear Filters

Plot data for each orbital pass.

4 views (last 30 days)
root
root on 24 Apr 2023
Answered: Rasmita on 9 Jun 2023
Hello
This code was supposed to plot Ne vs MLT for each orbital pass of SWARM satellite. It looks like the passes are not correctly separeted. Can you comment on what is happening to this code?
Thank you so much
% Load the data
DATA = 'SW_EXTD_EFIA_LP_HM_20201101T000000_20201101T235959_0101.cdf';
info = cdfinfo(DATA);
vars = info.Variables;
lati = cell2mat(cdfread(DATA, 'Variables', {'Latitude'}));
loni = cell2mat(cdfread(DATA, 'Variables', {'Longitude'}));
Ne = cell2mat(cdfread(DATA, 'Variables', {'n'}));
ti = (cdfread(DATA, 'Variables', {'Timestamp'}));
MLT = cell2mat(cdfread(DATA, 'Variables', {'MLT'}));
MLAT = cell2mat(cdfread(DATA, 'Variables', {'MLat'}));
% Convert timestamps to MATLAB datenum format and then to minutes
for k = 1:length(ti)
datenum2(k) = todatenum(ti{k});
end
TT = datetime(datenum2, 'Format', 'HH:mm:ss', 'ConvertFrom', 'excel');
T1 = TT';
t_minutes = datenum(T1)*24*60; % convert t to minutes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the orbit period
alt = 500; % km
mu = 3.986004418e14; % m^3/s^2
R = 6378.137; % km
T = 2*pi*sqrt((R+alt)*1000/mu)/60; % minutes
% Identify the start and end times for each orbit pass
pass_num = 1;
start_index = 1;
for i = 2:length(t_minutes)
if (t_minutes(i) - t_minutes(i-1)) > T*1.5 % allow for some buffer time
end_index = i-1;
ne = Ne(start_index:end_index);
mlt = MLT(start_index:end_index);
% Plot the data for this pass
figure
plot(mlt, ne)
xlabel('MLT')
ylabel('Ne')
title(['Orbit Pass ', num2str(pass_num)])
pass_num = pass_num + 1;
start_index = i;
end
end
% Extract the data for the last orbit pass
end_index = length(t_minutes);
ne = Ne(start_index:end_index);
mlt = MLT(start_index:end_index);
% Plot the data for the last pass
figure
plot(mlt, ne)
xlabel('MLT')
ylabel('Ne')
title(['Orbit Pass ', num2str(pass_num)])

Answers (1)

Rasmita
Rasmita on 9 Jun 2023
Hi,
It is my understanding that, you are trying to plot Ne vs MLT for each orbital pass of SWARM satellite. But the passes are not correctly separated.
In the provided code, the condition ‘(t_minutes(i) - t_minutes(i-1)) > T*1.5’ is used to determine the end of one pass and the start of the next pass. However, it does not accurately capture the transitions between passes, leading to incorrect separation.
Instead of this, look for the points where the MLT values wrap around from high to low or vice versa using the sign of gradient of the MLT, as this indicates the start or end of a new orbit pass.
Please refer to the below modified code:
% Identify the start and end times for each orbit pass
pass_num = 1;
start_index = 1;
grad_mlt = gradient(MLT);
for i = 2:length(grad_mlt)
if sign(grad_mlt(i)) ~= sign(grad_mlt(i-1)) % check for sign change
end_index = i-1;
ne = Ne(start_index:end_index);
mlt_pass = MLT(start_index:end_index);
% Plot the data for this pass
figure
plot(mlt_pass, ne)
xlabel('MLT')
ylabel('Ne')
title(['Orbit Pass ', num2str(pass_num)])
pass_num = pass_num + 1;
start_index = i;
end
end
% Extract the data for the last orbit pass
end_index = length(t_minutes);
ne = Ne(start_index:end_index);
mlt_pass = MLT(start_index:end_index);
% Plot the data for the last pass
figure
plot(mlt_pass, ne)
xlabel('MLT')
ylabel('Ne')
title(['Orbit Pass ', num2str(pass_num)])
For more information on ‘gradient’ function, please refer to the below documentation link:
For more information on ‘sign’ function, please refer to the below documentation link:
Hope this helps you resolve the query!

Categories

Find more on Gravitation, Cosmology & Astrophysics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!