General
Follow


Hans Scharler

Solar Eclipse 2024 and MATLAB R2024a

Hans Scharler on 25 Mar 2024
Latest activity Reply by Steve Eddins on 7 Apr 2024

Are you going to be in the path of totality? How can you predict, track, and simulate the solar eclipse using MATLAB?
Steve Eddins
Steve Eddins on 7 Apr 2024 (Edited on 7 Apr 2024)
Here is the anticipated viewing location of another well-known MATLAB figure.
% Show where I'll be on the map
wmmarker(44.259444, -72.575833, ...
'OverlayName','Where''s Default Image Boy?', ...
'Description', 'Path of totality', ...
'icon', 'https://shorturl.at/ghsL1')
wmmarker(30.2752, -98.87198, ...
'OverlayName','Where''s Adam?', ...
'Description', 'Path of totality', ...
'icon', 'https://shorturl.at/vzA49')
wmmarker(42.15485, -71.35157, ...
'OverlayName','CJ at home', ...
'Description', 'off path', ...
'icon', 'https://shorturl.at/aoIZ6')
% Read in eclipse path data
eclipse = webread('https://eclipse.gsfc.nasa.gov/SEpath/SEpath2001/SE2024Apr08Tpath.html');
startChar = strfind(eclipse,'16:40');
endChar = strfind(eclipse,'ΔT =');
theTable = extractBetween(eclipse,startChar,(endChar));
pip = textscan(theTable{1,1},'%s %2s %5s %3s %5s %2s %5s %3s %5s %2s %5s %3s %5s %*[^\n]');
North = strcat(pip{1,2}," ",pip{1,3}," ",pip{1,4}," ",pip{1,5});
South = strcat(pip{1,6}," ",pip{1,7}," ",pip{1,8}," ",pip{1,9});
% Convert degrees-minutes strings to decimal
[northLat, northLon] = dmstr2degrees(North);
[southLat, southLon] = dmstr2degrees(South);
% Plot path of totality
wmline(northLat,northLon);
wmline(southLat,southLon)
wmlimits([25.311 44.892],[-106.08 -73.121])
function [lat, lon] = dmstr2degrees(str)
% Converts degrees-minutes in the form of "05 30.6S 149 47.6W" to latitude
% and longitude decimals
pattern = '(\d{2})\s+(\d{2}\.\d)([NS])\s+(\d{3})\s+(\d{2}\.\d)([EW])';
northTokens = regexp(str, pattern, 'tokens','once');
northTokens = vertcat(northTokens{:});
lat = dm2degrees(str2double(northTokens(:,1:2))) .* (strcmpi(northTokens(:,3),"N")*2-1);
lon = dm2degrees(str2double(northTokens(:,4:5))) .* (strcmpi(northTokens(:,6),"E")*2-1);
end
Adam Danz
Adam Danz on 25 Mar 2024 (Edited on 25 Mar 2024)
Here's where I'll be (run this in MATLAB)
% Show where I'll be on the map
wmmarker(30.2752, -98.87198, ...
'OverlayName','Where''s Adam?', ...
'Description', 'Path of totality', ...
'icon', 'https://shorturl.at/vzA49')
% Read in eclipse path data
% https://eclipse.gsfc.nasa.gov/SEpath/SEpath2001/SE2024Apr08Tpath.html
T = readtable("eclipsePathData.txt",'Delimiter',' ','TextType','string');
% Convert degrees-minutes strings to decimal
[northLat, northLon] = dmstr2degrees(T.NorthLatLon);
[southLat, southLon] = dmstr2degrees(T.SouthLatLon);
% Plot path of totality
wmline(northLat,northLon);
wmline(southLat,southLon)
wmlimits([25.311 44.892],[-106.08 -73.121])
function [lat, lon] = dmstr2degrees(str)
% Converts degrees-minutes in the form of "05 30.6S 149 47.6W" to latitude
% and longitude decimals
pattern = '(\d{2})\s+(\d{2}\.\d)([NS])\s+(\d{3})\s+(\d{2}\.\d)([EW])';
northTokens = regexp(str, pattern, 'tokens','once');
northTokens = vertcat(northTokens{:});
lat = dm2degrees(str2double(northTokens(:,1:2))) .* (strcmpi(northTokens(:,3),"N")*2-1);
lon = dm2degrees(str2double(northTokens(:,4:5))) .* (strcmpi(northTokens(:,6),"E")*2-1);
end
Christopher Stapels
Christopher Stapels on 27 Mar 2024
If you wanna read the file automatically, here is a hack with me added in too.
% Show where I'll be on the map
wmmarker(30.2752, -98.87198, ...
'OverlayName','Where''s Adam?', ...
'Description', 'Path of totality', ...
'icon', 'https://shorturl.at/vzA49')
wmmarker(42.15485, -71.35157, ...
'OverlayName','CJ at home', ...
'Description', 'off path', ...
'icon', 'https://shorturl.at/aoIZ6')
% Read in eclipse path data
eclipse = webread('https://eclipse.gsfc.nasa.gov/SEpath/SEpath2001/SE2024Apr08Tpath.html');
startChar = strfind(eclipse,'16:40');
endChar = strfind(eclipse,'ΔT =');
theTable = extractBetween(eclipse,startChar,(endChar));
pip = textscan(theTable{1,1},'%s %2s %5s %3s %5s %2s %5s %3s %5s %2s %5s %3s %5s %*[^\n]');
North = strcat(pip{1,2}," ",pip{1,3}," ",pip{1,4}," ",pip{1,5});
South = strcat(pip{1,6}," ",pip{1,7}," ",pip{1,8}," ",pip{1,9});
% Convert degrees-minutes strings to decimal
[northLat, northLon] = dmstr2degrees(North);
[southLat, southLon] = dmstr2degrees(South);
% Plot path of totality
wmline(northLat,northLon);
wmline(southLat,southLon)
wmlimits([25.311 44.892],[-106.08 -73.121])
function [lat, lon] = dmstr2degrees(str)
% Converts degrees-minutes in the form of "05 30.6S 149 47.6W" to latitude
% and longitude decimals
pattern = '(\d{2})\s+(\d{2}\.\d)([NS])\s+(\d{3})\s+(\d{2}\.\d)([EW])';
northTokens = regexp(str, pattern, 'tokens','once');
northTokens = vertcat(northTokens{:});
lat = dm2degrees(str2double(northTokens(:,1:2))) .* (strcmpi(northTokens(:,3),"N")*2-1);
lon = dm2degrees(str2double(northTokens(:,4:5))) .* (strcmpi(northTokens(:,6),"E")*2-1);
end
Mike Croucher
Mike Croucher on 26 Mar 2024
Is it possible to get your co-ordinates from Google Maps or something into this? Maybe make a button that says 'Use my current location' that includes the API call? How would you do that?
Hans Scharler
Hans Scharler on 26 Mar 2024
So, are you going to Texas for eclipse, Adam?
Adam Danz
Adam Danz on 26 Mar 2024
I'm headin' deep into the Lone Star State where I hear the moon's gonna throw more shade than a mesquite tree in July.

See Also