<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Rawiński on Medium]]></title>
        <description><![CDATA[Stories by Daniel Rawiński on Medium]]></description>
        <link>https://medium.com/@danielrawinski?source=rss-d76c54969ff6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QTzRFwGTAdep8QCNF7KWhQ.jpeg</url>
            <title>Stories by Daniel Rawiński on Medium</title>
            <link>https://medium.com/@danielrawinski?source=rss-d76c54969ff6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 13:25:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielrawinski/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding The Best Place To View A Solar Eclipse: A Pythonic Solution]]></title>
            <link>https://medium.com/geekculture/finding-the-best-place-to-view-a-solar-eclipse-a-pythonic-solution-88591e3ad775?source=rss-d76c54969ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/88591e3ad775</guid>
            <category><![CDATA[solar-eclipse]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Daniel Rawiński]]></dc:creator>
            <pubDate>Mon, 24 May 2021 22:16:58 GMT</pubDate>
            <atom:updated>2021-05-28T06:30:52.566Z</atom:updated>
            <content:encoded><![CDATA[<h4>With less than a month left until an <a href="https://www.timeanddate.com/eclipse/solar/2021-june-10">annular solar eclipse</a>, it might make sense to start looking for your preferred place for viewing.</h4><p>This is not that easy a task, though. First, the <a href="https://www.timeanddate.com/eclipse/map/2021-june-10">path of annular eclipse</a> itself, where Moon covers the center of the Sun, leaving the thin ring of the outer edge visible, will cross parts of Canada, Greenland, Russian Far East and a very tiny bit of United States: these are not the most densely populated places in the world and it’s very unlikely you are living within that zone. Traveling there for many of us is also quite expensive, long, and not very environmental-friendly to say the least. Second, Covid. As of present, vaccination is stalling even in many of the developed countries and even those vaccinated, while able to travel more than unvaccinated people, are still limited in their options, different across countries and even regions. For example, while I will be able to enter my home country in June, traveling anywhere inside it for anything more ambitious than a daytrip would not really be feasible, since I will not be able to book a room with my girlfriend if we are vaccinated in another country, and only married couples are allowed to book hotel rooms together in this case.</p><p>What’s left for many of us is to observe a <em>partial</em> solar eclipse, where Moon eclipses a part of the Solar disc, from somewhere relatively close to our homes. That will still allow only a minority of people worldwide to see <em>any kind of an eclipse </em>this time, but for those with more luck this year, it’s still better than nothing. Those who are outside the eclipse path this time — this is not the last eclipse of our lifetimes, so this article can be useful for you in the future!</p><p>Now, when choosing a general area of where would I plan to go for an eclipse hunt, I am considering two things: how much of the Sun will be covered by Moon, since I am settling for a partial eclipse, and what’s the weather going to be like at the time of the main event. The first could be measured by either obscuration (the percentage of apparent solar disc covered by the Moon) or magnitude (the part of diameter of solar disc covered by the Moon) — much more better explanation than mine can be found <a href="https://www.geogebra.org/m/SnZ7QGTJ">here</a>, you can even play with sliders there in order to better comprehend the difference. The second one for me in this case is synonymous with cloud cover — it’s nice to have pleasant temperature and light wind, but that’s a secondary priority.</p><figure><img alt="Difference between magnitude and obscuration illustrated, as per geogebra.org" src="https://cdn-images-1.medium.com/max/1024/1*SqTu1TZWrJBY_nKJxaqxtQ.png" /><figcaption>Difference between magnitude and obscuration illustrated, as per <a href="http://geogebra.org/">geogebra.org</a></figcaption></figure><p>If I had stayed for an eclipse in Poland, just as planned a couple of days ago, I would have been looking for seaside. It faces north, and that is roughly where an eclipse would be the “strongest” when viewed from Poland. The thing is, it’s only a <em>rough</em> prediction, and while the difference between point A and point B along Polish shore line is small, within a single percentage point, but I was feeling nerdy, so I decided to dive deeper.</p><figure><img alt="Difference between visibility of a solar eclipse in different parts of Poland" src="https://cdn-images-1.medium.com/max/1024/1*Je5ly7LV8xKZchJJF88mvg.jpeg" /><figcaption>The differences between how will 2021 partial eclipse look like in different parts of Poland. First and second disks represent views from easternmost and westernmost points along Polish seashore, respectively. It’s not that easy to spot a difference, but it’s more noticeable when compared to a view from Warsaw in third disk and a view from Ustrzyki Dolne in south-eastern Poland in the last one. Source: <a href="http://heavens-above.com/">heavens-above.com</a></figcaption></figure><p><strong>Scraping viewing conditions for the list of populated places</strong></p><p>And so, I have embarked on a journey to find a perfect spot for observation in the closed borders epoch. As a first step, I have decided to compile a list of all populated places with a status of a town in Poland — there are 954 of them. I have used Wikipedia list as my source, but in your country, you may want to get more creative: maybe your census/statistical office or geographical naming authority has the list easily available for a download; of course, you are free to make the list yourself, consisting of places you would consider for viewing the eclipse from.</p><p>First, a list of towns and tools that will be needed later are imported:</p><pre>import pandas as pd<br>from selenium import webdriver<br>import time<br>from selenium.webdriver.common.keys import Keys<br>import csv</pre><pre>listOfCities = []</pre><pre>with open(r&#39;yourlocation.csv&#39;, newline=&#39;&#39;) as inputfile:<br>    for row in csv.reader(inputfile):<br>        listOfCities.append(row[0])</pre><pre>places = []<br>latitudes = []<br>longitudes = []<br>obscuration = []<br>magnitude = []</pre><p>The five latter lists will store the results of a loop that will look for viewing conditions and other parameters across the list of cities. This will be discussed below.</p><p>I have no doubts that finding viewing conditions for a particular place can be much easier if you know astrophysics relatively well, but after searching the Web for good sources for eclipse viewing conditions that would allow web scraping, I have settled for the two options: <a href="https://www.timeanddate.com/eclipse/map/2021-june-10?n=262">timeanddate.com</a> and <a href="https://www.heavens-above.com/SolarEclipseLocal.aspx?jdmax=2459375.94660477">heavens-above.com</a>; the first one proved to lead to more errors in finding the location I have meant and was more dependent on connection quality, so the rest of the entry will deal only with the second website. Therefore, let’s launch a Firefox using Selenium and go to heavens-above. Remember, that you need to have <a href="https://github.com/mozilla/geckodriver/releases">geckodriver.exe</a> downloaded in order to control a browser through Selenium!</p><pre>driver = webdriver.Firefox(executable_path=r&quot;yourlocation\geckodriver.exe&quot;)<br>time.sleep(5) # just in case<br>driver.get(&quot;<a href="https://www.heavens-above.com/">https://www.heavens-above.com/</a>&quot;)<br>time.sleep(5) # giving it time to load</pre><p>Now, once a Selenium-controlled browser window is open, we can loop through the list of towns in order to find the following things:</p><ul><li>name of the place found on heavens-above when searching for a town from a list (allows to control for mistakes in search engine), will be stored in variable places ;</li><li>coordinates of a place found — will be required for retrieving weather data — stored in variables latitudes and longitudes ;</li><li>viewing conditions at the peak of eclipse — obscuration and magnitude variables. Time of the peak can also be scraped from the same page, but I was not doing that here.</li></ul><pre>for i in range(len(listOfCities)):<br>     <br>    driver.find_element_by_xpath(&#39;//*[<a href="http://twitter.com/id">@id</a>=&quot;ctl00_linkLatLong&quot;]&#39;).click() #go to location change page<br>    time.sleep(2)<br>    searchbox = driver.find_element_by_xpath(&#39;//*[<a href="http://twitter.com/id">@id</a>=&quot;ctl00_cph1_txtAddress&quot;]&#39;)<br>    searchbox.send_keys(f&quot;{listOfCities[i]}&quot;)<br>    time.sleep(2)<br>    searchbox.send_keys(Keys.ENTER)<br>    time.sleep(2)<br>    <br>    try:<br>        place = driver.find_element_by_xpath(&quot;/html/body/form/table/tbody/tr[3]/td[1]/div/table/tbody/tr[2]/td[2]/select/option[1]&quot;).text<br>    except:<br>        place = &quot;Error&quot;<br>    try:<br>        lat = driver.find_element_by_xpath(&quot;/html/body/form/table/tbody/tr[3]/td[1]/table[2]/tbody/tr[1]/td[2]/input&quot;).get_attribute(&quot;value&quot;)<br>    except:<br>        lat = &quot;Error&quot;<br>    try:<br>        lon = driver.find_element_by_xpath(&quot;/html/body/form/table/tbody/tr[3]/td[1]/table[2]/tbody/tr[2]/td[2]/input&quot;).get_attribute(&quot;value&quot;)<br>    except:<br>        lon = &quot;Error&quot;<br>    <br>    driver.find_element_by_xpath(&#39;//*[<a href="http://twitter.com/id">@id</a>=&quot;ctl00_cph1_btnSubmit&quot;]&#39;).click() #confirmation of location change<br>    time.sleep(2)<br>        <br>    try:<br>        driver.get(&quot;<a href="https://www.heavens-above.com/SolarEclipseLocal.aspx?jdmax=2459375.94660477">https://www.heavens-above.com/SolarEclipseLocal.aspx?jdmax=2459375.94660477</a>&quot;) #go to the eclipse info page<br>    except:<br>        pass<br>    try:<br>        obs = float(driver.find_element_by_xpath(&#39;/html/body/form/table/tbody/tr[3]/td[1]/div[2]/div[1]/div[2]/div/div[2]/table/tbody/tr[4]/td[2]&#39;).text[:-1].replace(&quot;,&quot;, &quot;.&quot;))<br>    except:<br>        obs = &quot;Error&quot;<br>    try:<br>        magn = float(driver.find_element_by_xpath(&#39;/html/body/form/table/tbody/tr[3]/td[1]/div[2]/div[1]/div[2]/div/div[2]/table/tbody/tr[3]/td[2]&#39;).text.replace(&quot;,&quot;, &quot;.&quot;))<br>    except:<br>        magn = &quot;Error&quot;<br>        <br>    places.append(place)<br>    latitudes.append(lat)<br>    longitudes.append(lon)<br>    obscuration.append(obs)<br>    magnitude.append(magn)<br>        <br>    time.sleep(2)<br>        <br>driver.quit()</pre><pre>df = pd.DataFrame(list(zip(listOfCities, places, latitudes, longitudes, obscuration, magnitude)), columns = [&quot;City&quot;, &quot;Place found&quot;, &quot;Latitude&quot;, &quot;Longitude&quot;, &quot;Obscuration&quot;, &quot;Magnitude&quot;])<br>df.to_csv(&quot;yourfilename.csv&quot;, sep = &quot;;&quot;, index = False)</pre><p>Every iteration of the loop has to do two steps: first, the browser is directed to a location choice page, where the town searched for is entered into a searchbox. This allows to change the place that eclipse conditions will be viewed for and gather information about which place was, in fact, found. Then, the browser is redirected to the eclipse conditions website, where information about conditions can be scraped from and saved. This is saved to a dataframe which will afterwards require a check for errors, possible corrections, and then it would be used for gathering weather data.</p><p>The resulting data frame will probably need some more manual cleansing, unfortunately. This is a result of erroneous search results (probably the most illustrative example here would be a search engine understanding two Polish towns — Lipsk and Lipsko as German Leipzig, since Leipzig is known as Lipsk in Polish as well), which one cannot really avoid, and errors resulting from unstable connection, which can obviously be avoided. In my case, this led to ca. 2–3% of entries requiring a correction and manual review of viewing conditions. This cleansed dataset can be found <a href="https://github.com/danielrawinski/eclipseconditions/blob/main/poland_eclipses_ha_corrected_with_coords.csv">here</a><strong><em>.</em></strong></p><p><strong>What’s the weather like in df.iloc[i][‘Latitude’]?</strong></p><p>Not only does the cleansed dataset allow to see the top solar eclipse viewing spots in terms of obscuration and/or magnitude, but it can be used, as already mentioned, for finding weather conditions for them. To do that, we will use <a href="https://openweathermap.org/api">Open Weather Map API</a>. Their free plan allows for up to 60 calls/minute and 1 million calls per month, and that places this exercise comfortably within these limits. We will be using their <a href="https://openweathermap.org/api/one-call-api">One Call API</a>.</p><p>As of now, when there are more than two weeks left until the event, the forecast is obviously not available yet, but let’s for testing purposes pretend the eclipse is the day after day after tomorrow. This is within 8 days range One Call Api contains daily data for (today+7 next days), but not yet within 48 hours range for hourly data; the switch to those can, and should, be done once eclipse time is closer.</p><p>Let’s loop over the list of towns, viewing conditions, and their coordinates:</p><pre>import pandas as pd<br>import requests<br>import time</pre><pre>df = pd.read_csv(r&quot;yourfilename.csv&quot;, sep = &quot;;&quot;)</pre><pre>clouds = []</pre><pre>for i in range(len(df)):<br>    request = requests.get(f&quot;<a href="https://api.openweathermap.org/data/2.5/onecall?lat={corrected_df.iloc[i][&#39;Latitude&#39;]}&amp;lon={corrected_df.iloc[i][&#39;Longitude&#39;]}&amp;exclude=current,minutely,hourly,alerts&amp;appid=b50e805ea2a45e1159521aa1a95bbe5b">https://api.openweathermap.org/data/2.5/onecall?lat={df.iloc[i][&#39;Latitude&#39;]}&amp;lon={df.iloc[i][&#39;Longitude&#39;]}&amp;exclude=current,minutely,hourly,alerts&amp;appid=y</a>ourapikey&quot;)<br>    requestJson = request.json()</pre><pre>clouds.append(requestJson[&quot;daily&quot;][3][&quot;clouds&quot;])<br>    time.sleep(1)<br>    <br>df[&quot;Clouds&quot;] = clouds    <br>del clouds</pre><pre>results = df.loc[(df[&quot;Clouds&quot;] &lt;= 50)].sort_values(by=[&quot;Magnitude&quot;], ascending=False)</pre><p>I am using an f-string in specifying an API call destination so that it takes geographical coordination from a dataframe. Next, current, minutely, hourly and weather alerts outputs are excluded (though, as I have mentioned, with eclipse coming closer you should include hourly forecasts and start excluding daily ones; including weather alerts may also be a good idea for safety). Lastly, API key is provided — it is easily obtainable upon registration on OpenWeatherMap website.</p><p>clouds list is then appended by the output of requestJson[&quot;daily&quot;][3][&quot;clouds&quot;], which illustrates cloud coverage, that is, the percentage of sky obscured by clouds. requestJson[&quot;daily&quot;] is a list of dictionaries, each containing a lot of useful information about weather for a particular day (seriously, take a look at what they carry there!), so 0th element there represents today, 1st — tomorrow, and so on. This logic also applies for hourly output, when included into a request.results dataframe is created from the viewing conditions dataframe (now with column representing cloud coverage being added), filtered by cloud coverage and sorted by magnitude of an eclipse. I am using 50% as a cut-off value here, but this is, of course, completely arbitrary and you might want to use less, if weather allows you to, or more, if you are unlucky.</p><p><strong>Choosing the observation point</strong></p><figure><img alt="Results dataframe as seen on Spyder IDE" src="https://cdn-images-1.medium.com/max/964/1*A7yIN2ckqiApgwvlWO0UzA.png" /><figcaption>Results table head as seen on Spyder IDE</figcaption></figure><p>It’s entirely up to you which place you would pick based on the output. Personally, out of these I would be eyeing Kołobrzeg, as it has much better forecast than the leading in terms of obscuration-magnitude combination Ustka and is close to Darłowo, should weather conditions change for the better there.</p><p><strong>Summary</strong></p><p>This text shows how to try and find the best place for viewing the 2021 annular solar eclipse when most of the borders are closed and there are still movement restrictions, based on a) region that is available to a viewer, b) viewing conditions of the eclipse in different points of the region, c) cloud coverage forecast.</p><p>While battling for having a one-thousandth more in eclipse magnitude or one percentage point less in cloud coverage is admittedly nerdy, I am also sure this can make eclipse observing preparations quite exciting in their own way and one might discover some hidden gems of one’s own region/country by travelling there just for an eclipse and staying for it’s natural and/or human built beauty. And isn’t sometimes the journey more important than the destination?</p><p><strong>References</strong></p><p>[1] <a href="https://www.timeanddate.com/eclipse/solar/2021-june-10">Annular Solar Eclipse on 10 June 2021 (timeanddate.com)</a><br>[2] <a href="https://www.geogebra.org/m/SnZ7QGTJ">Eclipse magnitude and obscuration — GeoGebra</a><br>[3] <a href="https://heavens-above.com/">Heavens-Above</a><br>[4] <a href="https://pl.wikipedia.org/wiki/Miasta_w_Polsce">Miasta w Polsce — Wikipedia, wolna encyklopedia</a><br>[5] <a href="https://github.com/mozilla/geckodriver/releases">Releases · mozilla/geckodriver (github.com)</a><br>[6] <a href="https://github.com/danielrawinski/eclipseconditions">danielrawinski/eclipseconditions: Building a solution for finding the best place for viewing 2021 Solar eclipse (github.com)</a><br>[7] <a href="https://openweathermap.org/api">Weather API — OpenWeatherMap</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88591e3ad775" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/finding-the-best-place-to-view-a-solar-eclipse-a-pythonic-solution-88591e3ad775">Finding The Best Place To View A Solar Eclipse: A Pythonic Solution</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>