propagateOrbit function fails on Epoch field format
Show older comments
I am feeding the same tleStruct data to the propagateOrbit function twice, but in one case propagageOrbit is successful, and in the other case it fails with the following error message:
Error using propagateOrbit
An error was encountered when propagating the orbit of spacecraft at index 1 using sdp4 orbit propagator.
error in test_TLE (line 17)
[r1,v1] = propagateOrbit(epoch_date,tleStruct,PropModel="sdp4",OutputCoordinateFrame="fixed-frame");
Caused by:
Error using - (line 43)
Cannot combine or compare a datetime array within a time zone with one without a time zone.
The tleStruct data looks identical in both cases. In the first case, I use tleread() to input the data and feed it directly to propagateOrbit. In the second case, I write the tleStruct to an Excel .csv file, read it back in as a new tleStruct, and feed it to propagateOrbit. That is when I run into issues with the epoch_date and tleStruct.Epoch fields.
Here is a sample test script:
function test_TLE()
epoch_date = datetime('09-Mar-2025 07:26:58');
tleStruct = struct;
input_pathname = pwd;
[filename, filepath] = uigetfile(fullfile(input_pathname, '*.tle'));
fullpath = strcat(filepath,filename);
[~,name,~] = fileparts(filename);
csv_filepath = strcat(filepath, name, '.csv');
if isfile(csv_filepath)
csvtext = readtable(csv_filepath);
tleStruct = table2struct(csvText);
% script fails here:
[r1,v1] = propagateOrbit(epoch_date,tleStruct, PropModel="sdp4",OutputCoordinateFrame="fixed-frame");
disp(num2str(r1);
else
tleStruct = tleread(fullpath);
[r1,v1] = propagateOrbit(epoch_date,tleStruct, PropModel="sdp4",OutputCoordinateFrame="fixed-frame");
disp(num2str(r1);
% save struct to file so you can read it in faster the next time:
tleTable = struct2table(tleStruct);
tlePath = strrep(fullpath,'.tle','.csv');
writetable(tleTable, tlePath, 'Delimiter', ',', 'fileType', 'text');
end
end
input file "day_068.tle":
1 00011U 59001A 25067.89046599 +.00002526 +00000-0 +13240-2 0 9994
2 00011 32.8783 45.0235 1450212 290.5993 54.5192 11.89297186480028
Output file "day_068.csv":
Name SatelliteCatalogNumber Epoch Bstar RightAscensionOfAscendingNode Eccentricity Inclination ArgumentOfPeriapsis MeanAnomaly MeanMotion
UNKNOWN 11 3/8/2025 21:22 0.001324 45.0235 0.1450212 32.8783 290.5993 54.5192 0.049554049
The Epoch field appears as shown above in the Excel table. When you examine it in the edit field, it says "3/8/2025 9:22:16 PM
The first time you run the script, it will read the TLE file and create a tleStruct for propagateOrbit() to read. This call is successful. It then outputs a new "day_068.csv" file to save time on subsequent function calls.
The second time you run the script, it reads the "day_068.csv" file and converts it to a tleStruct. When you attempt to read this
tleStruct into propagateOrbit(), it throws an error.
Apparently propagateOrbit calls arithUtil(a,b) which checks for datetime compatibility and throws an exception.
The time fields appear identical to me in both cases, when I examine them in the tleStruct.Epoch field. Is Excel doing something funny to the datetime structure?
1 Comment
dpb
25 minutes ago
"Is Excel doing something funny to the datetime structure?"
Excel is notoriously bad in handling dates, particularly if it is interpreted as a date/time field. I'm not sure just where it's going wrong there, but I'd be pretty sure it's in that translation into/back out of Excel that is causing the problem.
Why not forego Excel altogether if the point is to save processing time on subsequent case and just save the desired variable(s) in native MATLAB .mat format? It/they will be read back in then identically as were in memory to the identical bit pattern besides being a much smaller file size and faster operation.
Answers (1)
Umar
about 2 hours ago
0 votes
Hi @Kurt,
Wanted to close the loop on the Excel/datetime thing properly before saying anything definitive.
Ran a couple of tests on my end first: round-tripped a datetime through writetable/readtable in plain MATLAB, no Excel involved — came out clean, TimeZone empty both sides, values identical. Then did the same thing with a full struct shaped like your actual tleStruct (Name, SatelliteCatalogNumber, Epoch, all the fields) — also completely clean. So that rules out writetable, readtable, struct2table, and table2struct as the cause — none of them introduce the mismatch on their own.
That leaves Excel as the only part of your workflow we haven't directly tested, and by elimination it's the most likely explanation — dpb's instinct about Excel and dates lines up with that. If you get a chance and don't mind, one quick way to confirm it directly: take a fresh CSV, open it in real Excel, save it (even without changing anything), read it back into MATLAB, and check tleStruct.Epoch.TimeZone before and after. If that's what introduces the mismatch, it'll confirm it outright rather than just by process of elimination.
That said — since what you're actually trying to do is just cache the parsed struct so you're not reprocessing that huge file every time, the practical fix doesn't depend on nailing the exact mechanism. save()/load() with a .mat file sidesteps the whole thing, since it stores the datetime exactly as it exists in memory with no text step for anything to go wrong in. Probably the simplest path forward regardless of what Excel turns out to be doing.
1 Comment
Walter Roberson
16 minutes ago
Moved: Walter Roberson
16 minutes ago
Excel does not store the timezone. It appears that writetable() strips out the timezone information and writes the localtime relative to the timezone (rather than writing a UTC timestamp.)
T1 = datetime(1980, 2, 29, 19, 00, 0)
T1.TimeZone
T2 = datetime(1980, 2, 29, 19, 00, 0, 'timezone', 'America/Chicago')
T2.TimeZone
D = table(T1, T2)
Filename = tempname() + ".xlsx";
writetable(D, Filename)
E = readtable(Filename)
E.T1.TimeZone
E.T2.TimeZone
OutFolder = tempdir();
filenames = unzip(Filename, OutFolder)
dbtype( filenames{7} )
Categories
Find more on Satellite Mission Analysis 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!