<?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 Leonardo Godói on Medium]]></title>
        <description><![CDATA[Stories by Leonardo Godói on Medium]]></description>
        <link>https://medium.com/@leonardogodoi?source=rss-f2dffbda433b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XP7COihx1N6Ttw4KBI_pCA.jpeg</url>
            <title>Stories by Leonardo Godói on Medium</title>
            <link>https://medium.com/@leonardogodoi?source=rss-f2dffbda433b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:43:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leonardogodoi/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[Storing a full TensorFlow model (architecture + parameters) in a PostgreSQL database]]></title>
            <link>https://medium.com/@leonardogodoi/storing-a-full-tensorflow-model-architecture-parameters-in-a-postgresql-database-35f985dc9e3d?source=rss-f2dffbda433b------2</link>
            <guid isPermaLink="false">https://medium.com/p/35f985dc9e3d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Leonardo Godói]]></dc:creator>
            <pubDate>Sat, 24 Jun 2023 12:27:39 GMT</pubDate>
            <atom:updated>2023-06-24T14:16:40.356Z</atom:updated>
            <content:encoded><![CDATA[<p>How to save and load serialized models without headaches</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jv7Br9_ZQ3Q1_W1xSSfzBA.png" /></figure><p>A crucial step in the development of data analysis systems involving neural networks is the design of the persistence for the created models, aiming to make their use and maintenance as easy as possible. In general, TensorFlow neural network models are composed of two structures: <strong>architecture</strong> and <strong>parameters</strong>, both represented by dictionaries that can reach high levels of size and complexity. Therefore, the purpose of this tutorial is to show how a neural network can be fully saved in a <strong>PostgreSQL</strong> database by using model serialization. This method guarantees three important benefits:</p><ul><li>Aggregation of architecture and parameters in a single database column instead of separate columns.</li><li>Flexibility regarding the neural network type, since any kind of model can be stored this way without any change in table definition.</li><li>Straightforward model retrieval and reuse.</li></ul><h4>Setting up the PostgreSQL database</h4><p>Since we are going to use PostgreSQL in its simplest form, I recommend to run a PostgreSQL container using <strong>Docker</strong> rather than actually installing PostgreSQL on your host. In case you still don’t have Docker installed on your computer, you can check the link below to install it.</p><p><a href="https://docs.docker.com/get-docker/"><em>https://docs.docker.com/get-docker/</em></a></p><p>With Docker properly installed, we can have a PostgreSQL container running simply by using the following command.</p><pre>docker run --name db-container -e POSTGRES_USERNAME=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=db -p 5432:5432 -d postgres</pre><p>Let’s access our PostgreSQL container and navigate to the database we specified in the previous command.</p><pre>docker exec -it db-container /bin/bash<br><br>psql -U postgres<br><br>\c db;</pre><p>We now run the following command to create a table for storing our model. The column type for storing our model must be <strong>bytea</strong>, which supports storage of binary strings.</p><pre>CREATE TABLE models (<br>    id SERIAL PRIMARY KEY,<br>    data BYTEA<br>);</pre><h4>Creating and training the neural network</h4><p>Let’s start by importing all packages we’ll need throughout this tutorial.</p><pre>import tensorflow as tf<br>import numpy as np<br>import pickle<br>import psycopg2</pre><p>Now, we can generate some random data to train and evaluate our model, assuming 1000 samples with 9 features for X array, with 70% of zeros (class 0) and 30% of ones (class 1) for y array. You can change this parameters however you like.</p><pre>n_samples = 1000<br>n_features = 9<br>X = np.random.random((n_samples, n_features))<br>y = np.random.choice([0, 1], size=n_samples, p=[.7, .3])</pre><p>In our example, a simple neural network is created with two dense layers, a dropout layer and an output layer with sigmoid function, suitable for binary classification. Since the neural network’s performance is not relevant for the purpose of this tutorial, feel free to make changes.</p><pre>original_model = tf.keras.models.Sequential([<br>  tf.keras.layers.Flatten(input_shape=(n_features,)),<br>  tf.keras.layers.Dense(32, activation=&#39;relu&#39;),<br>  tf.keras.layers.Dropout(0.2),<br>  tf.keras.layers.Dense(16, activation=&#39;relu&#39;),<br>  tf.keras.layers.Dense(1, activation=&#39;sigmoid&#39;)<br>])</pre><p>We compile our model using Adam optimizer, setting Binary Cross Entropy as loss function, and monitoring the model’s accuracy.</p><pre>original_model.compile(optimizer=&#39;adam&#39;,<br>                       loss=&#39;binary_crossentropy&#39;,<br>                       metrics=[&#39;accuracy&#39;])</pre><p>Let’s train the model on the generated data for 10 epochs.</p><pre>original_model.fit(X, y, epochs=10)</pre><p>And evaluate it to get its loss and accuracy.</p><pre>original_loss, original_accuracy = original_model.evaluate(X, y)</pre><h4>Saving the model in the database</h4><p>We now start the main part of this tutorial by serializing our model using the <strong>Pickle</strong> module.</p><pre>pickled_original_model = pickle.dumps(original_model)</pre><p>So we establish a connection to the database we created previously in this tutorial.</p><pre>conn = psycopg2.connect(<br>           host=&quot;localhost&quot;,<br>           database=&quot;db&quot;,<br>           port=5432,<br>           user=&quot;postgres&quot;,<br>           password=&quot;postgres&quot;)</pre><p>Finally, we save the serialized model in the bytea column of the table we created.</p><pre>cursor = conn.cursor()<br>cursor.execute(&quot;INSERT INTO models (data) VALUES (%s) RETURNING id&quot;, <br>               (pickled_original_model,))<br>conn.commit()</pre><p>It’s convenient to get the ID automatically generated by PostgreSQL for the saved model.</p><pre>model_id = cursor.fetchone()[0]</pre><h4>Retrieving the saved model</h4><p>Now, we use the ID to get the model back from the database.</p><pre>pickled_retrieved_model = cursor.fetchone()[0]</pre><p>Right away, we need to deserialize the retrieved model so that it’s possible to make predictions with it.</p><pre>retrieved_model = pickle.loads(pickled_retrieved_model)</pre><p>Similar to how we did for the original model, we evaluate the retrieved model object to get its loss and accuracy on the same data.</p><pre>retrieved_loss, retrieved_accuracy = original_model.evaluate(X, y)</pre><h4>Comparing the original and the retrieved model</h4><p>Printing the loss and the accuracy obtained from both models we can check whether the model retrieved corresponds to the original one.</p><pre>print(f&quot;Original loss: {original_loss}&quot;)<br>print(f&quot;Retrieved loss: {retrieved_loss}&quot;)<br>print(f&quot;Original accuracy: {original_accuracy}&quot;)<br>print(f&quot;Retrieved accuracy: {retrieved_accuracy}&quot;)</pre><pre>Original loss: 0.6023926734924316<br>Retrieved loss: 0.6023926734924316<br>Original accuracy: 0.7070000171661377<br>Retrieved accuracy: 0.7070000171661377</pre><p>By comparing the metrics we can conclude that the model has been successfully saved and retrieved without having its quality affected. But in case you still need a more exact proof that the models are equivalent, you can print and compare a few weights resulting from training.</p><pre>print(f&quot;Some weights of original model: {original_model.weights[0][0]}\n&quot;)<br>print(f&quot;Some weights of retrieved model: {retrieved_model.weights[0][0]}&quot;)</pre><pre>Some weights of original model: [-0.37762427 -0.31172457  0.16281793  0.20875677 -0.03447147 -0.01916301<br>  0.0424621   0.26985747 -0.3445434   0.05018247  0.23163241 -0.37049234<br> -0.30362964  0.06312352  0.0663638  -0.26932436  0.02068468 -0.05438694<br>  0.25234967 -0.34015387  0.20112173 -0.01952727 -0.08877492  0.3514789<br>  0.19104229 -0.34066972 -0.29300463  0.09896617 -0.00937416  0.2626564<br> -0.28591692 -0.24513282]<br><br>Some weights of retrieved model: [-0.37762427 -0.31172457  0.16281793  0.20875677 -0.03447147 -0.01916301<br>  0.0424621   0.26985747 -0.3445434   0.05018247  0.23163241 -0.37049234<br> -0.30362964  0.06312352  0.0663638  -0.26932436  0.02068468 -0.05438694<br>  0.25234967 -0.34015387  0.20112173 -0.01952727 -0.08877492  0.3514789<br>  0.19104229 -0.34066972 -0.29300463  0.09896617 -0.00937416  0.2626564<br> -0.28591692 -0.24513282]</pre><h4>The full project</h4><p>The full project resulting from this tutorial is available in the following repository.</p><p><a href="https://github.com/lfgodoi/tutorials"><em>https://github.com/lfgodoi/tutorials</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35f985dc9e3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How are exoplanets found?]]></title>
            <link>https://medium.com/@leonardogodoi/how-are-exoplanets-found-4404d6e90c66?source=rss-f2dffbda433b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4404d6e90c66</guid>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[universe]]></category>
            <category><![CDATA[space-exploration]]></category>
            <dc:creator><![CDATA[Leonardo Godói]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 20:48:54 GMT</pubDate>
            <atom:updated>2023-01-27T12:44:44.855Z</atom:updated>
            <content:encoded><![CDATA[<p>A short review of methods used to detect planets, targeting especially those with potential to support life</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBDkKGycMNf5y-LhNl1y5Q.jpeg" /><figcaption>Some exoplanets found so far compared to Earth (Credit: CalTech GPS)</figcaption></figure><h4>First of all… What are exoplanets and why is it important to study them?</h4><p>In order for a celestial object to be considered a planet, it must match three requirements:</p><ul><li>It must orbit a star;</li><li>It must have gravity enough to be forced into a spherical shape.</li><li>Its gravity must be enough to have pushed away objects close to its orbit around the sun.</li></ul><p>An exoplanet, also referred to as an <strong>extrasolar planet</strong>, is a planet that orbits a star other than our sun, that is, a planet located outside our solar system.</p><p>Studying exoplanets allowed us to discover numerous Earth-like planets that can help us understand how these (and our) particular systems formed and evolved, as well as providing us with fundamental clues about the possibility of life elsewhere in the universe.</p><p>The search for exoplanets is based on the application of different methods. Without further ado, let’s review how the main exoplanet detection methods work and the performance that each one has achieved in this exciting mission.</p><h4>Method 1: Transit</h4><p><em>(Planets discovered so far: </em><strong><em>3941</em></strong><em>)</em></p><p>This method is based on the simple fact that when a planet passes directly between an observer (us) and the star it orbits, that star’s light gets dimmer. This event is pretty similar to what happens during a solar eclipse.</p><p>The level of light observed from the star constitutes the so-called <strong>light curve</strong> chart, which is used as a powerful indicator to determine whether or not the star is being orbited by a planet. A real example of light curve is shown in the figure below. The light level is represented on the y-axis, whereas the time period is represented on the x-axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*qffoLyj8TZmih1lBzEJxIA.png" /><figcaption>A real example of light curve obtained from the planet HAT-P-32 b, detected through the transit method (Credit: NASA EXOTIC)</figcaption></figure><p>The <strong>transit length </strong>observed in the light curve, that is, the time it takes for the planet to pass in front of its star, tells us how further the planet is from the star. The longer the planet takes to pass in front of the star, the farther away it is.</p><p>The <strong>light level drop</strong>, on the other hand, gives us some important clues about the planet’s size. Deeper light curves result from bigger planets since they can block more light.</p><p>In addition to finding new planets, the transit method is also applied to infer information about the <strong>temperature</strong> or <strong>composition</strong> of a planet through the light colors observed.</p><p>The transit method has been the most successful method and has been used to find most exoplanets found so far.</p><h4>Method 2: Radial velocity</h4><p><em>(Planets discovered so far: </em><strong><em>1023</em></strong><em>)</em></p><p>Due to the star’s massive gravity, usually extremely larger than that of its orbiting planets, it applies a huge impact on the motion of them all. However, it is true that each planet also exerts its gravity on the sun, even if in obviously much smaller proportions. The result is that the planet’s gravity causes the star to wobble around slightly. For this reason, bigger planets have stronger effect on their sun. This is the principle that leads the radial velocity method.</p><p>According to the <strong>Doppler shift</strong> effect, waves can be stretched and squeezed based on the movement of the object that is producing them. So, when viewed from a distance, such movements change the star’s light spectrum. The color signature of a star that is moving towards the observer takes on a <strong>bluer tone</strong>, which corresponds to <strong>shorter wavelengths</strong>, whereas it takes on a <strong>redder tone</strong>, which corresponds to <strong>longer wavelengths</strong>, when the star is moving away from the observer. A simple example is presented in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*g84PIovojFA7F0ulFI-5Bg.png" /><figcaption>Representation of a star’s color signature over time (Credit: The Planetary Society)</figcaption></figure><p>This method has been applied to the detection of about 20% of exoplanets discovered so far, and has been especially used in two important observatories: the <strong>Keck Observatory</strong>, in <strong>Hawaii</strong>, and the <strong>La Silla Observatory</strong>, in <strong>Chile</strong>.</p><h4>Method 3: Gravitational microlensing</h4><p><em>(Planets discovered so far: </em><strong><em>152</em></strong><em>)</em></p><p>Following Albert Einstein’s theory, the gravity of a massive object distorts and changes direction of other objects’ light. As a result, gravity can bend and focus light like a lens in a magnifying glass. So, gravitational microlensing is the phenomenon observed when a planet’s gravity focuses the light of a more distant star, making it temporarily brighter.</p><p>An interesting event that can happen is the generation of quick microlensing effect by <strong>rogue planets</strong>, that is, planets that do not orbit a star. Such events are pretty common and must be taken into account when applying this method.</p><h4>Method 4: Direct imaging</h4><p><em>(Planets discovered so far: </em><strong><em>62</em></strong><em>)</em></p><p>Technological advances in the development of imaging devices and image treatment techniques are allowing scientists to take pictures of planets located in external solar systems.</p><p>The main challenge in this case is that the planets are easily obfuscated by the light of their host stars since they usually are million of times brighter. For this reason, instruments used to capture images directly from exoplanets are designed with some shine blocker technology, because only after softening the glare of a sun it is possible to properly analyze the objects around it.</p><p>A shine blocker can be designed using <strong>coronographs</strong>, which are devices built as internal add-ons to telescopes able to block light before it reaches the telescope’s detector, or using <strong>starshades</strong>, which are independent devices positioned to block light from a star before it even reaches the telescope.</p><p>It is important to point out that, if compared to the previous methods, direct imaging is still very recent and its prospects for advancement are optimistic. It is expected that in the future it will be able to provide even more detailed information on the characteristics of the observed planets in addition to “simply” detecting them.</p><h4>Method 5: Astrometry</h4><p><em>(Planets discovered so far: </em><strong><em>2</em></strong><em>)</em></p><p>One of the first techniques used to search for exoplanets, astrometry, also known as<strong> positional astronomy</strong>, consists in determining the location of a celestial object and its movement within the plane of the sky.</p><p>Similar to what was seen in the radial velocity method, astrometry relies on the star’s wobbles, but instead of analyzing Doppler shifts, such wobbles are analyzed as changes in the star’s apparent position in the sky.</p><p>Through the analysis of a series of images in a set of stars and by comparing the distance between them, scientists can check for exoplanets signs once the target star has moved in relation to the others.</p><p>What makes astrometry difficult is the distortion and the light bending caused by Earth’s atmosphere.</p><p>As of this writing, only two exoplanets have been found through astrometry: <strong>DENIS-P J082303.1–491201 b</strong> (2013)<strong> </strong>and <strong>GJ 896 A b</strong> (2022).</p><h4>You don’t need a telescope to help NASA search for exoplanets</h4><p>NASA has the help of interested people from all over the world to find new exoplanets. This is the purpose of the <strong>Exoplanet Transit Interpretation Code (EXOTIC)</strong> program. And the coolest thing about it is that you can be part of this mission even without having a telescope.</p><p>Using a provided interactive platform, you can perform analyzes on data provided from other people’s telescopes by applying the <strong>transit method</strong>.</p><p>To learn more about it, access the link below.</p><p><a href="https://exoplanets.nasa.gov/exoplanet-watch/exotic/welcome/"><em>https://exoplanets.nasa.gov/exoplanet-watch/exotic/welcome/</em></a></p><h3>To finish</h3><p>If you are interested and want to know more details about this subject, I recommend the following references used throughout this text.</p><p><strong>What is a planet?</strong></p><p><a href="https://solarsystem.nasa.gov/planets/in-depth/"><em>https://solarsystem.nasa.gov/planets/in-depth/</em></a></p><p><strong>What are exoplanets?</strong></p><p><a href="https://www.esa.int/Science_Exploration/Space_Science/Cheops/What_are_exoplanets"><em>https://www.esa.int/Science_Exploration/Space_Science/Cheops/What_are_exoplanets</em></a></p><p><strong>5 Ways to Find a Planet</strong></p><p><a href="https://exoplanets.nasa.gov/alien-worlds/ways-to-find-a-planet/"><em>https://exoplanets.nasa.gov/alien-worlds/ways-to-find-a-planet/</em></a></p><p><strong>How We Detect Exoplanets: The Radial-Velocity Method</strong></p><p><a href="https://www.planetary.org/space-images/how-to-search-for-exoplanets-rv-method"><em>https://www.planetary.org/space-images/how-to-search-for-exoplanets-rv-method</em></a></p><p><strong>Astrometry: An Overview</strong></p><p><a href="https://www.sciencedirect.com/topics/earth-and-planetary-sciences/astrometry"><em>https://www.sciencedirect.com/topics/earth-and-planetary-sciences/astrometry</em></a></p><p><strong>Exoplanet Watch</strong></p><p><a href="https://www.nasa.gov/stem-ed-resources/exoplanet-watch.html"><em>https://www.nasa.gov/stem-ed-resources/exoplanet-watch.html</em></a></p><p><strong>Exoplanet Catalog</strong></p><p><a href="https://exoplanets.nasa.gov/discovery/exoplanet-catalog/"><em>https://exoplanets.nasa.gov/discovery/exoplanet-catalog/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4404d6e90c66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Checking your classes using automated unit test in Python]]></title>
            <link>https://medium.com/@leonardogodoi/checking-your-classes-using-automated-unit-test-in-python-afbc6c9fc6c2?source=rss-f2dffbda433b------2</link>
            <guid isPermaLink="false">https://medium.com/p/afbc6c9fc6c2</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[unit-test-framework]]></category>
            <category><![CDATA[python-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Leonardo Godói]]></dc:creator>
            <pubDate>Sat, 26 Mar 2022 14:06:39 GMT</pubDate>
            <atom:updated>2023-01-27T16:01:20.473Z</atom:updated>
            <content:encoded><![CDATA[<p>Explaining the unittest framework with a full example code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*5Dfc1Yb3zhf01zjXzmj3qA.jpeg" /></figure><p>Testing your code has always been an important task, and with the growth of the agile methods it has become even more crucial. However, testing complex, modularized systems, which is the case of most current applications, can give you a lot of headaches, at least if you try to do it manually. Therefore, knowing how to implement automated tests is an essential skill for any developer nowadays.</p><p>There are multiple levels of tests that must be performed in order to ensure the robustness of a system. Some important ones are end to end test, integration test, and unit test. The latter is performed more frequently during development and aims to check the behavior of individual classes or modules. The Python programming language, one of the most popular today, provides the <strong>unittest</strong> framework, which allows us to elaborate unit tests in a very efficient way.</p><p>In the following steps, I will show you how to use this framework to test different functional aspects of methods of one or more classes.</p><h4>Writing the regular class</h4><p>We are going to implement a class for simulating the management of a parking lot in a file named <strong>parking_lot.py</strong>. For the sake of simplicity, we will be working with just two attributes: <strong>available_spaces</strong>, which refers to the number of spaces currently available in the parking lot, and <strong>total_spaces</strong>, which refers to the total number of existing spaces in the parking lot. Both of them are initialized in the class constructor method.</p><pre># Regular class<br>class ParkingLot():<br>    <br>    # Class constructor<br>    def __init__(self, initial_spaces):<br>        self.available_spaces = initial_spaces<br>        self.total_spaces = initial_spaces</pre><p>The first functional method we will implement has the role of updating the number of available spaces when one or more spaces are occupied.</p><pre># Method triggered when one or more spaces are occupied    <br>    def occupy_spaces(self, n_spaces):<br>        if type(n_spaces) != int:<br>            raise TypeError(&quot;Input type must be an integer&quot;)<br>        if self.available_spaces &gt; n_spaces:<br>            self.available_spaces -= n_spaces<br>        else:<br>            self.available_spaces = 0</pre><p>The second method has a reverse role. It updates the number of available spaces when one or more spaces are released.</p><pre># Method triggered when one or more spaces are released    <br>    def release_spaces(self, n_spaces):<br>        if type(n_spaces) != int:<br>            raise TypeError(&quot;Input type must be an integer&quot;)<br>        self.available_spaces += n_spaces<br>        if self.available_spaces &gt; self.total_spaces:<br>            self.available_spaces = self.total_spaces</pre><p>In both methods, we are checking the type of the variable <strong>n_spaces</strong>, corresponding to the number of spaces to be occupied or released when any of the methods is called. Thus, as it is expected to be an integer, a <strong>TypeError</strong> is raised when a different type is passed.</p><h4>Writing the test class</h4><p>We will be writing our tests in another file named <strong>test_parking_lot.py</strong>. That’s because, by default, the test files are identified by the unittest discovery tool through the following naming rule:</p><p><strong><em>test_ + &lt;regular_name&gt; + .py</em></strong></p><p>It is worthy highlighting some important points before we actually start implementing our test class. First, it is highly recommended, despite not being mandatory, to adopt the following convention when choosing the class name:</p><p><strong><em>Test + &lt;RegularClassName&gt;</em></strong></p><p>Also, we are inheriting our test class from the <strong>unittest.TestCase</strong> class. According to the unittest official documentation:</p><blockquote>This class is intended to be used as a base class, with specific tests being implemented by concrete subclasses. This class implements the interface needed by the test runner to allow it to drive the tests, and methods that the test code can use to check for and report various kinds of failure.</blockquote><p>Thus, each method within the test class has the role of checking the class behavior under a specific usage scenario.</p><pre># Test class<br>class TestParkingLot(unittest.TestCase):</pre><p>Finally, we can start by writing our first test method to check how our class will update the <strong>available_spaces</strong> attribute when it is required to occupy a number of spaces greater than the number of available spaces. The <strong>assertEqual()</strong> method is used to compare the resulting attribute value and the expected value, which in this case is 0 since there cannot be a negative number of spaces.</p><p>The convention used for naming a test method is as follows:</p><p><strong><em>test_ + &lt;functionality_to_be_tested&gt;</em></strong></p><pre># Case 1: trying to occupy 51 spaces when just 50 are available<br>    def test_occupy_more_than_available_spaces(self):<br>        parking_lot = ParkingLot(50)<br>        parking_lot.occupy_spaces(51)<br>        self.assertEqual(parking_lot.available_spaces, 0)</pre><p>The second test method checks how many available spaces are retrieved when we try to release spaces from an empty parking lot, that is, when no space has been occupied yet.</p><pre># Case 2: trying to release a space when no one has been occupied so far<br>    def test_release_unoccupied_spaces(self):<br>        parking_lot = ParkingLot(50)<br>        parking_lot.release_spaces(1)<br>        self.assertEqual(parking_lot.available_spaces, 50)</pre><p>We also want to check how many spaces are still available after occupying almost all possible spaces. In this case, we subtract 49 spaces from the 50 initially available, expecting to have only 1 available space as a result.</p><pre># Case 3: occupying 49 spaces when there are 50 available<br>    def test_normal_occupation(self):<br>        parking_lot = ParkingLot(50)<br>        parking_lot.occupy_spaces(49)<br>        self.assertEqual(parking_lot.available_spaces, 1)</pre><p>It is interesting to test what happens when we try to occupy a number of spaces greater than the number of spaces we released. In this case, the expected number of available spaces is the balance between them (5–3=2) subtracted from the initial number of available spaces (50–2=48).</p><pre># Case 4: releasing 3 spaces after occupying 5<br>    def test_normal_release(self):<br>        parking_lot = ParkingLot(50)<br>        parking_lot.occupy_spaces(5)<br>        parking_lot.release_spaces(3)<br>        self.assertEqual(parking_lot.available_spaces, 48)</pre><p>The <strong>TestCase</strong> class contains several assert variations that allow us to perform different kinds of test. Another interesting assert variation is <strong>assertRaises()</strong>, which is used to check whether a specific error is raised when something goes wrong during a procedure. In the following case, we try to pass the number of spaces as a string to the occupation method. A <strong>TypeError</strong> is then expected to be observed in the output.</p><pre># Case 5: trying to pass a non-int as the number of spaces to be occupied<br>    def test_occupy_spaces_type(self):<br>        parking_lot = ParkingLot(50)<br>        self.assertRaises(TypeError, parking_lot.occupy_spaces, &quot;My string&quot;)</pre><p>Similarly, we test the release method by passing a boolean input instead of an integer, so that the same kind of error is expected to be observed.</p><pre># Case 6: trying to pass a non-int as the number of spaces to be released<br>    def test_release_spaces_type(self):<br>        parking_lot = ParkingLot(50)<br>        parking_lot.occupy_spaces(5)<br>        self.assertRaises(TypeError, parking_lot.release_spaces, True)</pre><h4>Running the test</h4><p>We can easily run all methods within our test class by calling <strong>unittest.main()</strong>. A simple report is shown in the output telling us how many tests have been successful.</p><pre># Running the test<br>if __name__ == &quot;__main__&quot;:<br>    unittest.main()</pre><p>In this example, you are supposed to see something like this in the output. That basically means that all 6 tests have been successful.</p><pre>......<br>----------------------------------------------------------------------<br>Ran 6 tests in 0.002s</pre><pre>OK</pre><p>Let’s now see how a failed test should look like. After replacing the expected value in the first test case by 5 (the actual expected value is 0), the following output is shown.</p><pre>..F...<br>======================================================================<br>FAIL: test_occupy_more_than_available_spaces (__main__.TestParkingLot)<br>----------------------------------------------------------------------<br>Traceback (most recent call last):<br>  File &quot;/home/lfgodoi/Documentos/Projetos/tutorials/checking-your-classes-using-unit-test-in-python/parking_lot.py&quot;, line 41, in test_occupy_more_than_available_spaces<br>    self.assertEqual(parking_lot.available_spaces,5)<br>AssertionError: 0 != 5</pre><pre>----------------------------------------------------------------------<br>Ran 6 tests in 0.002s</pre><pre>FAILED (failures=1)</pre><p>That means that the same 6 tests were performed, but one of them has not been successful. The failure report is shown above the lower dashed line, specifying the associated test method and the reason why it failed.</p><h4>Running multiple test classes at once</h4><p>In a real system, you are more likely to have to test dozens or hundreds of methods very often. In order to make things easier, the unittest framework supports a <strong>discovery tool</strong>, which scans through the specified directory to detect and run all your test classes automatically.</p><p>Let’s first implement a second regular class for the management of the parking lot customers in a file named <strong>customer_management.py</strong>.</p><pre># Regular customer management class<br>class CustomerManagement:<br>    <br>    # Class constructor<br>    def __init__(self):<br>        self.customers = {}</pre><pre># Adding a customer<br>    def add_customer(self, name, car_id):<br>        self.customers[car_id] = name         <br>        <br>    # Removing a customer    <br>    def remove_customer(self, car_id):<br>        self.customers.pop(car_id)</pre><p>Then we will implement its respective test class in a file named <strong>test_customer_management.py</strong>.</p><pre>import unittest<br>from customer_management import CustomerManagement</pre><pre># Test customer management class<br>class TestCustomerManagement(unittest.TestCase):<br>    <br>    # Case 1: adding a customer<br>    def test_add_customer(self):<br>        customer_management = CustomerManagement()<br>        customer_management.add_customer(&quot;Leonardo Franco&quot;, &quot;ABC-1234&quot;)</pre><pre># Case 2: removing a customer<br>    def test_remove_customer(self):<br>        customer_management = CustomerManagement()<br>        customer_management.add_customer(&quot;Leonardo Franco&quot;, &quot;ABC-1234&quot;)<br>        customer_management.remove_customer(&quot;ABC-1234&quot;)<br>        <br># Running the test<br>if __name__ == &quot;__main__&quot;:<br>    unittest.main()</pre><p>For the next experiment. Let’s keep all four files created so far in the same directory. Once you are sure you are in the test files directory, run the following command.</p><pre>$ python3 -m unittest discover ./</pre><p>By default, the discovery tool looks for all files whose name is in the format <strong><em>“test_*.py”</em></strong>. If you want to specify your own naming convention, use the following version of the discovery command.</p><pre>$ python3 -m unittest discover ./ &quot;&lt;your-naming-convention&gt;&quot;</pre><p>The expected result should indicate that 8 tests have been successfully performed. That’s because there are 6 tests described in <strong>test_parking_lot.py</strong> and 2 tests described in <strong>test_customer_management.py</strong></p><pre>........<br>----------------------------------------------------------------------<br>Ran 8 tests in 0.000s</pre><pre>OK</pre><h4>The full project</h4><p>The full project resulting from this tutorial is available in the following repository.</p><p><a href="https://github.com/lfgodoi/tutorials"><em>https://github.com/lfgodoi/tutorials</em></a></p><h4>To finish</h4><p>Sometimes, you will have to test a class that depends on external source data, e.g., database, which generally implies the use of larger or more complex objects. In such cases, it is recommended to use mocks to simulate the behavior of real objects. Therefore, in addition to the unittest official documentation, I make available here an excellent article that deals with the use of mocks in unit test.</p><p><strong>The official unittest documentation</strong></p><p><a href="https://docs.python.org/3/library/unittest.html"><em>https://docs.python.org/3/library/unittest.html</em></a></p><p><strong>Understanding the Python Mock Object Library</strong></p><p><a href="https://realpython.com/python-mock-library/"><em>https://realpython.com/python-mock-library/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afbc6c9fc6c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fundamentals of OpenCV in Python]]></title>
            <link>https://medium.com/@leonardogodoi/fundamentals-of-opencv-in-python-589d181783d?source=rss-f2dffbda433b------2</link>
            <guid isPermaLink="false">https://medium.com/p/589d181783d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Leonardo Godói]]></dc:creator>
            <pubDate>Thu, 17 Mar 2022 21:19:24 GMT</pubDate>
            <atom:updated>2022-03-30T18:41:44.541Z</atom:updated>
            <content:encoded><![CDATA[<h4>From installation to basic image manipulation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*kdRv-UBcZALffWQsN4ohuQ.png" /></figure><p>OpenCV is a popular open-source computer vision library available for different programming languages, such as Python, C++, and JavaScript. It provides a rich set of tools for processing and analyzing images and videos, allowing you from resizing a single picture to building a complex object recognition application. The Python programming language, in addition to have been widely adopted as a standard for most of the image processing and computer vision applications, allows OpenCV to be installed in your computer in a really straightforward way.</p><p>In this tutorial, I will show you the steps required to install, setup and perform some basic manipulations on images using OpenCV, highlighting important fundamentals regarding the concepts behind this library.</p><p>Before we start, it is worthy mentioning that these steps were performed using <strong>Python3</strong> in a <strong>Linux-based operating system</strong>. So, if you are using different configurations, minor changes may be necessary.</p><h4>Setting up a virtual environment</h4><p>When working with Python, it is often recommended to run your applications within a virtual environment. By doing that, you can install only the packages you need to run your application, making it independent from the rest of the system. In case you still do not have a virtual environment tool installed on your computer, I recommend you to install the following.</p><pre> $ python3 -m pip install virtualenv</pre><p>Once installed, you can use this tool to create a new virtual environment. For this, navigate to your desired directory and run the following command. Note that I chose the name <strong>my_venv</strong> for my environment, but you can choose any name you want.</p><pre>$ python3 -m venv my_venv</pre><p>Finally, you just have to activate your virtual environment, so that anything you run in this terminal will be done within it.</p><pre>$ source my_venv/bin/activate</pre><h4>Installing OpenCV</h4><p>Start by updating your package manager and installing OpenCV for Python3.</p><pre>$ sudo apt update<br>$ sudo apt install python3-opencv</pre><p>Then, install OpenCV in your virtual environment using pip.</p><pre>$ pip install opencv-python</pre><h4>Opening an image</h4><p>Using your favorite IDE, create a new file with extension .py and start by importing the OpenCV class.</p><pre>import cv2</pre><p>The first thing we do here is to load an image using the <strong>imread()</strong> method and open it using the <strong>imshow()</strong> method. Please replace the path below by the path where your image is located.</p><pre>image = cv2.imread(&quot;messi.jpg&quot;)<br>cv2.imshow(&quot;Original image&quot;, image)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*v2dBSC3o77l1N1KWQFbl1Q.png" /><figcaption>Original image</figcaption></figure><p>The first interesting point about how OpenCV interprets images is that <strong>imread()</strong> returns an <strong>n-dimensional array object</strong>. In the case of an RGB image, such as the one used in this example, this array has the shape:</p><p><strong>[<em>width</em> × <em>height</em> × <em>number of channels</em>]</strong></p><p>You can confirm this by printing the image shape.</p><pre>print(&quot;Original image shape:&quot;, image.shape)</pre><h4>Changing the image color space</h4><p>A <strong>color space</strong> is a range of colors on a spectrum that is used to describe an image. Although there are several color space available, the most common are RGB and grayscale. OpenCV contains a particular method for color space conversion. In order to convert a image from RGB to grayscale, you need to apply the <strong>cvtColor()</strong> method.</p><pre>image_grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<br>cv2.imshow(“Grayscale image”, image_grayscale)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*tLoggYLYKwMdKcYthDOelQ.png" /><figcaption>Grayscale image</figcaption></figure><p>It is important to note that now your image no more contains three dimensions. That is because the third dimension, corresponding to channels, is not used in the grayscale color space.</p><pre>print(&quot;Grayscale image shape:&quot;, image_grayscale.shape)</pre><h4>Editing image channels</h4><p>Returning to the original image, containing three color channels, you can now manipulate the intensity values of each of them in order to suppress or highlight a specific channel. Contrary to what is usually assumed, the RGB channels are not accessed in the same order as in the acronym. In OpenCV, the channels are actually available in the BGR format:</p><p><strong><em>0 = B (blue)</em></strong></p><p><strong><em>1 = G (green)</em></strong></p><p><strong><em>2 = R (red)</em></strong></p><p>In the example below, I retrieve all the pixels in the first two channels and make them zero, so that the green and blue channels will take no effect on the resulting image, which will consequently assume an exclusively red tone.</p><pre>image_red = image.copy()<br>image_red[:, :, :2] = 0 <br>cv2.imshow(&quot;Red image&quot;, image_red)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Aw5CNUkvTT-Ap7RPaDrTJw.png" /><figcaption>Image with null blue and green channels</figcaption></figure><p>When printing the red image shape, note that there is still a third dimension, otherwise the resulting image would be described as a grayscale.</p><pre>print(&quot;Red image shape:&quot;, image_red.shape)</pre><h4>Rotating the image</h4><p>In addition to colors, it is also possible to perform manipulations on the image shape, e.g., size and orientation. You can start by obtaining the image dimensions just like you would do in a regular NumPy object.</p><pre>width, height, _ = image.shape</pre><p>The center points of the image can then be calculated by taking the half of its width and height.</p><pre>center = (width//2, height//2)</pre><p>In order to rotate the image, you have first to create a rotation matrix, passing as arguments the center points, the desired rotation in degrees, and the image scale, respectively. Using a scale different from 1 would change the image size.</p><pre>rotation_matrix = cv2.getRotationMatrix2D(center, 45, 1.0) </pre><p>The rotation matrix object itself is not enough to do what we want. It is passed as an argument to the <strong>warpAffine()</strong> method, which is what actually performs the rotation.</p><pre>image_rotated = cv2.warpAffine(image, rotation_matrix, (width, height))<br>cv2.imshow(“Rotated image”, image_rotated)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*qEHtFMEBwAFTHXgf7ZoELA.png" /><figcaption>Rotated image</figcaption></figure><h4>Resizing the image</h4><p>You can use the height and width values obtained previously to define the new dimensions for the image. In the example below I set them to reduce the image to a third of its original size.</p><pre>new_size = (width//3, height//3)</pre><p>The method in charge of resizing the image is <strong>resize()</strong>, which needs as arguments the original image object, the desired new size, and the interpolation method, respectively.</p><pre>image_resized = cv2.resize(image, new_size, interpolation=cv2.INTER_LINEAR)<br>cv2.imshow(“Resized image”, image_resized)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/133/1*RCue5LD6BkpJEvE2lG8UoA.png" /><figcaption>Resized image</figcaption></figure><p>You can then check the dimensions of the resized image.</p><pre>print(“Resized image shape:”, image_resized.shape)</pre><h4>Inserting drawings into the image</h4><p>In some applications, it may be necessary to add markers to the image. the OpenCV class provides multiple methods for drawing lines and shapes on it. A line is added as follows. The arguments here are the original image, the initial position, the final position, the line color RGB code, and the line width. Note that, actually, a copy of the original image is used since the drawing methods can affect the original image.</p><pre>image_line = cv2.line(image.copy(), (0, 0), (height//2, width//2), (0, 255, 255), 10)<br>cv2.imshow(“Image with line”, image_line)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*soyDxCBamZKkQLGKIgBsJw.png" /><figcaption>Image with a line</figcaption></figure><p>Similarly, there is a specific method for drawing rectangles in the image. In this case, the second and the third arguments are the positions of the rectangle opposite vertices (top left and bottom right).</p><pre>image_rectangle = cv2.rectangle(image.copy(), (500, 150), (900, 550), (0, 255, 255), 5)<br>cv2.imshow(“Image with rectangle”, image_rectangle)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*G1pPmPwyxhnemMfII-NJoQ.png" /><figcaption>Image with a rectangle</figcaption></figure><p>You can also draw a circle by specifying its center position and its radius as the second and third arguments, respectively.</p><pre>image_circle = cv2.circle(image.copy(), (300, 300), 200, (0, 255, 255), 5)<br>cv2.imshow(“Image with circle”, image_circle)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*YS-xifvfUJ5mmTEQeKrG_g.png" /><figcaption>Image with a circle</figcaption></figure><h4>The full script</h4><p>The script generated in this tutorial is available on the following repository.</p><p><a href="https://github.com/lfgodoi/tutorials"><em>https://github.com/lfgodoi/tutorials</em></a></p><h4>To finish</h4><p>Finally, I would like to list links to interesting content for those who want to go deeper into the computer vision with OpenCV.</p><p><strong>The OpenCV official site:</strong></p><p><a href="https://opencv.org/"><em>https://opencv.org/</em></a></p><p><strong>What is computer vision?</strong></p><p><a href="https://machinelearningmastery.com/what-is-computer-vision/"><em>https://machinelearningmastery.com/what-is-computer-vision/</em></a></p><p><strong>IBM: Computer Vision</strong></p><p><a href="https://www.ibm.com/topics/computer-vision"><em>https://www.ibm.com/topics/computer-vision</em></a></p><p><strong>TechTalks: Computer Vision Applications</strong></p><p><a href="https://bdtechtalks.com/2019/12/30/computer-vision-applications-deep-learning/"><em>https://bdtechtalks.com/2019/12/30/computer-vision-applications-deep-learning/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=589d181783d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How artificial intelligence is helping us break through the universe]]></title>
            <link>https://medium.com/@leonardogodoi/how-artificial-intelligence-is-helping-us-break-through-the-universe-5ac80d68a662?source=rss-f2dffbda433b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ac80d68a662</guid>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[astrophysics]]></category>
            <category><![CDATA[space-exploration]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Leonardo Godói]]></dc:creator>
            <pubDate>Sun, 30 Jan 2022 12:14:47 GMT</pubDate>
            <atom:updated>2023-01-13T21:01:10.227Z</atom:updated>
            <content:encoded><![CDATA[<h4>A brief list of AI contributions to space exploration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*e45Kxo5Ulvw8UcrQiCgBlQ.jpeg" /><figcaption>The first real image of a black hole ever, obtained with the aid of AI (Credit: National Geographic)</figcaption></figure><p>We can say that it is well known that artificial intelligence (AI) has become an inevitable element in our lives, whether we like it or not. The truth is that AI surrounds us on all sides. Netflix’s recommendation system creates for you accurate lists of movies that it “thinks” you might be interested in. Not too differently, Tinder suggests potential dates to you, and Instagram keeps pouring out countless videos of cats making mess and celebrities doing random things before your eyes. All, of course, based on how you interact with such platforms. What you like, what you comment, and what you follow. However, the use of AI is not restricted to social media or streaming services. As you read this text, it is possible that a robot is vacuuming the dust under your chair or that your home alarm is going off because some abnormal movement has been detected at the front door of your house (I really hope not). With a certain frequency, some algorithm created by your bank updates the parameters of your account according to your financial profile, while the algorithm of some job vacancy site “tears” your resume because it concluded that you are not suitable for the position you applied for. Well, I could easily write a few dozen more lines with examples of how AI affects us in different aspects of our lives, but in this text, I’m going to talk about a special application that, in my opinion, has been little talked about so far. One of the most underrated uses of AI is in activities related to space exploration. So here are some of the most amazing ways these algorithms are helping us understand and explore the universe.</p><h4>Answering fundamental questions</h4><p>There are still many mysteries and paradoxes that have bothered scientists around the world. Among them, we can highlight some relevant questions: Where did we come from? Where are we going? What is the true nature of the cosmos? Are we real or are we just characters of some sophisticated videogame? The analysis of such questions requires the study of numerous complex scenarios, since there is a wide set of parameters that can be varied in order to, at least, draw some possible conclusions. Therefore, performing such tasks is impractical for humans, but perhaps not so complicated for some computers with high processing capacity. With the help of AI algorithms that contribute to the generation of most likely scenarios, these computers simulate thousands or millions of combinations relevant for answering the most important questions of the universe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*uDzQhH1dOM573NrPig4k_g.jpeg" /><figcaption><em>View of the sky seen by the Pan-STARRS1 telescope in Hawaii. Researchers use AI techniques to analyze 2 petabytes of data (Credit: Danny Farrow, Pan-STARRS1 Science Consortium and Max Planck Institute for Extraterrestial Physics)</em></figcaption></figure><h4>Telling us what and how to do</h4><p>It is evident that the different fields of engineering have evolved significantly in the last decades and, thanks to increasingly skilled specialists, space agencies have been able to develop magnificent projects and achieve important feats. However, as the more you have, the more you want, the challenges of aerospace technology continue to become increasingly complex. Once again, AI is present to assist engineers during the design process, from the elaboration to the testing phases. Such contributions include optimization algorithms in structural engineering for the design of fail-safe aerospace structures, analysis of aerodynamic performance and improvement of flight control system parameters, among many others.</p><h4>Seeing things we can’t see</h4><p>One of the most fascinating subfields of AI is computer vision. It takes care of allowing computers to be able to interpret videos and images, capturing patterns and recognizing objects much more accurately and faster than we do. Given the wide field of application of computer vision, it is fair to say that this topic is the most generic among those listed here. In astronomy, there are computer programs making use of AI to catalog new galaxies and identify phenomena occurring thousands of light years away. In aerospace engineering, AI is applied for satellite imagery processing and to assist spacecraft activity. Of course, these are just a few of the many activities aided by AI in these amazing areas.</p><h4>Guiding rovers on Mars</h4><p>Until now, five rovers have already been sent by NASA to explore Mars. The last of them was Perseverance, aka Percy, together with its little flying friend Ingenuity. The main function of this rover is to collect properly selected samples of the Red Planet and, from them, detect possible traces of any microscopic life that may have been there millions of years ago. For this, it needs to use highly advanced instruments and, of course, algorithms that help it “see” and “understand” everything it collects. Percy also uses AI methods to automatically move around, manage its power system and assess the health of its general components all the time. That is because many tasks it performs in real time, mainly due to the communication latency, cannot be assisted even by those brilliant engineers who monitor it through numerous screens from a control room in Pasadena.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOiHyvw1Oeyy64XG74OgoA.jpeg" /><figcaption>The Perseverance Mars Rover (Credit: NASA)</figcaption></figure><h4>Looking for others like us</h4><p>Undoubtedly, one of man’s greatest desires is to find life outside of Earth, whether through extremely intelligent aliens in technologically advanced colonies or simple microorganisms living on the surface of some other planet. In this context, it is important to highlight the potentially habitable exoplanets, which are planets similar to Earth in terms of characteristics capable of supporting the existence of life. Considering that such planets can be located in extremely distant systems, the selection of candidates and the consequent analysis of such characteristics depends on sophisticated computational resources. For us, it would be like exhaustively analyzing every grain of sand on the planet even though we can’t have them all in our hands. AI algorithms do this heuristically, i.e. “selecting shortcuts” to get faster and more accurate results. With such a useful help, hopefully, if this is true, it won’t be long before we discover that we’re not alone in the universe.</p><h4>Avoiding the apocalypse</h4><p>Dr. Carl Sagan used to claim that planet Earth is, so far, the only home we know. Thus, as we try to learn more about the universe and other planets inside or outside our solar system, it is essential that we keep our own planet safe. In the absence of Avengers in the real world, AI can take on the role of keeping us safe not only from short or long-term natural disasters such as earthquakes, volcanic eruptions or global warming associated problems, but also helping to prevent cataclysmic events that may be caused by the collision of asteroids or, in millions of years, by the Sun’s death. Let’s focus here on the asteroid problem which, contrary to what many people think, is not just a movie thing. Imagine that the Earth is nothing more than a discrete blue dot (another reference to Carl Sagan) immersed in a “sea” of virtually infinite dimensions, at all times subject to being bombarded by multiple space elements, including those capable of destroying the entire planet. Identifying the existence of potential “world destroyers” and estimating their possible routes to discover the probability of them colliding with Earth can be an extremely complex task. AI algorithms help make sure that months or years from now we will not be, or in statistical terms, probably not be hit by some asteroid. That is, dinosaurs could still be living around here if they had invented something like AI.</p><h4><strong>To finish</strong></h4><p>As mentioned at the beginning of this text, my intention was only to point out, in a quick and relaxed way, some of the main contributions of AI to space exploration. Thus, if you are interested and want to know more details about this subject, I recommend the following references.</p><p><strong>Here’s how artificial intelligence is helping astronomers learn about the universe</strong></p><p><em>https://www.hindustantimes.com/science/heres-how-artificial-intelligence-helping-astronomers-learn-about-the-universe-101625382199966.html</em></p><p><strong>Intelligent systems for aerospace engineering: An Overview</strong></p><p><em>https://ntrs.nasa.gov/citations/20030105746</em></p><p><strong>Artificial intelligence in aerospace</strong></p><p><em>https://www.intechopen.com/chapters/6832</em></p><p><strong>Artificial intelligence in space</strong><br><em>https://www.esa.int/Enabling_Support/Preparing_for_the_Future/Discovery_and_Preparation/Artificial_intelligence_in_space</em></p><p><strong>Tem ways to apply machine learning in Earth and space sciences</strong></p><p><em>https://eos.org/opinions/ten-ways-to-apply-machine-learning-in-earth-and-space-sciences</em></p><p><strong>Harvard Center for Astrophysics: Machine Learning</strong></p><p><a href="https://cfa.harvard.edu/research/topic/machine-learning"><em>https://cfa.harvard.edu/research/topic/machine-learning</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac80d68a662" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>