<?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 Rafael Ferreira on Medium]]></title>
        <description><![CDATA[Stories by Rafael Ferreira on Medium]]></description>
        <link>https://medium.com/@astroraf?source=rss-4195943c0c35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uv9cr2qaYWCbtzGHfq_1FQ.jpeg</url>
            <title>Stories by Rafael Ferreira on Medium</title>
            <link>https://medium.com/@astroraf?source=rss-4195943c0c35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:12:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@astroraf/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[Utilizing Custom Code within Sisense]]></title>
            <link>https://astroraf.medium.com/utilizing-custom-code-within-sisense-53312e172f76?source=rss-4195943c0c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/53312e172f76</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[custom-code]]></category>
            <category><![CDATA[sisense]]></category>
            <category><![CDATA[sisense-training]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rafael Ferreira]]></dc:creator>
            <pubDate>Wed, 12 Jun 2024 18:15:23 GMT</pubDate>
            <atom:updated>2024-06-12T18:15:23.271Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiGE6lt9O0nFEgl5zf2UIw.png" /></figure><p>One of the great aspects of Sisense is the ability to customize and embed the dashboards/visuals you have created off the platform. Many aspects allow you, the user, to completely customize the experience that you bring to your users, but one specific tool that I love so much about Sisense is the utilization of Custom Code. In this article, I am going to be discussing how to use this tool, an example, and how it can lead to better insights into your data.</p><ol><li>How to use this tool</li></ol><p>Our first order of business is to go into Sisense and click on the Data tab. Once there click on the model you want to create the custom code in. (This assumes you have already made a model from your CSV, JSON, or Connector i.e. Snowflake, BigQuery, etc.) Once you are in your data model click on the Custom button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cz7C0Okm2SaDsO4kubcEag.png" /><figcaption>Where you can find the custom code button.</figcaption></figure><p>Then you will click on the Add Custom table button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DDJnRm3GfCDrYybG28neA.png" /></figure><p>From there, a pop-up window shows us the next steps of creating a custom code. This pop-up can either always be displayed or by clicking the “Do not show again” action we can skip this display every time we want to do a custom code. Hit Next to get to our next window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6w-LtrmhidqV1Xi0BmQ-Q.png" /></figure><p>The next window displays the type of custom code we can use. We can create a completely new custom code table, import one from a source code editor like Visual Studio Code, showcase a custom code notebook tutorial, or import a custom code editor that has already been created via Sisense. For this example, we will create a completely new custom code notebook. Click on the Create Your Own Notebook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*98SBKi3ylrXAbqNZLRZCHA.png" /></figure><p>The next window shows us the steps for creating a new custom code. Click next to Configure Manifest. The next pop-up is the manifest to our Custom Code Notebook. We need to give it a name, and a description describing what our custom code is doing for us in case another user or tenant has access to our data model and can see what the custom code does. Give access to a Group can access this custom notebook or you can create a new group by simply inputting a new group name. An Icon that can be associated with this custom notebook in Base64 string, and a Timeout option allows for the build time to be stopped if the build time takes longer than a time specified in seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*tYcSxDlgpCKwhHU2M5qhvQ.png" /><figcaption>Custom Code Manifest</figcaption></figure><p>With the Input Parameters option pops-up, we can decide our input parameters. The first option we have is the Input type. We can choose from one of the following options: a column in a table, a table from our model, a number, a list, text, or a boolean. After choosing our Input Type we have an option for the Input Title, describing the Input Type, and the Input ID used in the Notebook for the specific input type. Our next set of options is where to send the input ID created to the Notebook on the build. DependsOn, if the custom code table depends on the results of another table or column, and lastly the Primary which determines if the table or column is the primary element on which all the results are based. After deciding on these input parameters, you have one last option: add a column, which allows you to select a column that will be the output column for the custom code. You can choose the column type and the column name for which the output would be. After you click Next, you can click the table you want to work with.</p><p>2. My Example</p><p>In my example, I use data from US Colleges stored as an Elasticube in Sisense. Once I have done the above steps, I am then connected to the data in a Jupyternotebook. First I want to import all the packages I need to run my analysis. The most important package to run is the sisense_conn.</p><pre>import json<br>import pandas as pd<br>import numpy as np<br>from init_sisense import sisense_conn<br>from numpy import mean<br>from numpy import std<br>from sklearn.datasets import make_regression<br>from sklearn.linear_model import LinearRegression<br>from sklearn.model_selection import cross_val_score<br>from sklearn.model_selection import RepeatedKFold<br>from sklearn.feature_selection import SelectKBest, f_regression<br>from sklearn.linear_model import Lasso<br>from sklearn.feature_selection import RFE<br>from sklearn.tree import DecisionTreeRegressor<br>from sklearn.pipeline import Pipeline</pre><p>After you have imported the necessary packages you then can connect to your data. In my example, I have created a function to import that data from Elasticube within Sisense and connect it to the data, check if there is an error within the connection to Sisense, pull the table into a dataframe so that I can run a linear regression model on it, replace any NAN values with zeros, call on the columns I want to run the linear regression on against the column that I showing the correlation with then run my linear regression model, sort and output as a table. This last step is extremely crucial for the custom code because you need to have your results outputted as a table for Sisense to recognize your code.</p><pre>cube_name = &quot;NCES_Colleges&quot;</pre><p>Created the variable so Sisense knows which table to get the data from.</p><pre>def feat_selection_lasso(cube_name):<br>    #SQL Statement <br>    logical_sql = (f&#39;SELECT C.*\n&#39;<br>    f&#39;FROM [Colleges] as C&#39;)<br><br>    #Run SQL statement to grab data <br>    logical_sql_res = sisense_conn.get_logical_sql(query=logical_sql,<br>    cube_name=cube_name, # passed to notebook from build / Test Cell<br>    count=None)<br><br>    #Check if there is an error retrieving data<br>    if &quot;error&quot; in logical_sql_res:<br>        raise err.CustomCodeException(*err.ERROR_IN_LOGICAL_SQL, description=logical_sql_res.get(&quot;details&quot;))<br><br>    #Put values from Elasticub into a dataframe<br>    df_ed = pd.DataFrame(data=logical_sql_res[&#39;values&#39;], columns=logical_sql_res[&#39;headers&#39;])<br><br>    #Replace NAN values that came in as &quot;N\\A&quot; and replace with 0 for feature selection<br>    df_ed.replace(&#39;N\\A&#39;, 0, inplace=True)<br><br>    #Choose only numerical attributes from the College Dataframe<br>    corr_feat = [&#39;Acceptance Rate (Freshman Overall)&#39;,<br>       &#39;Admissions Yield&#39;, &#39;ACT Composite (25th %tile)&#39;,<br>       &#39;ACT Composite (75th %tile)&#39;, &#39;SAT Math (25th %tile)&#39;,<br>       &#39;SAT Math (75th %tile)&#39;, &#39;SAT Reading/Writing (25th %tile)&#39;,<br>       &#39;SAT Reading/Writing (75th %tile)&#39;, &#39;Cost of Attendance (In-State)&#39;,<br>       &#39;Cost of Attendance (Out-of-State)&#39;, &#39;Tuition (In-State)&#39;,<br>       &#39;Tuition (Out-of-State)&#39;, &#39;Percentage of Need Met (Average)&#39;,<br>       &#39;Average Need-Based Grant/Scholarship&#39;,<br>       &#39;% Receiving Merit (Non-Need-Based) Aid (Freshmen w/o Need)&#39;,<br>       &#39;Average Merit (Non-Need-Based) Award (Freshmen w/o Need)&#39;,<br>       &#39;Undergraduate Enrollment&#39;, &#39;% Full-Time (Undergraduate)&#39;, &#39;% Female&#39;,<br>       &#39;% Male&#39;, &#39;% African-American&#39;, &#39;% Asian&#39;, &#39;% Hispanic/Latino&#39;,<br>       &#39;% White&#39;, &#39;% International&#39;, &#39;% American Indian or Alaska Native&#39;,<br>       &#39;% Two or more races&#39;, &#39;% Out-of-State&#39;, &#39;% Other&#39;,<br>       &#39;Student-to-Faculty Ratio&#39;, &#39;Class Size (% Classes Under 20)&#39;,<br>       &#39;Class Size (% Classes 20-49)&#39;, &#39;Class Size (% Classes 50 or more)&#39;,<br>       &#39;% Full-Time Faculty&#39;, &#39;Average Salary (Full Professor)&#39;, &#39;4-Year Graduation Rate&#39;,<br>       &#39;6-Year Graduation Rate&#39;, &#39;Institution Size&#39;, &#39;Institution Setting&#39;,<br>       &#39;Institution Locale&#39;, &#39;Fraternities (Yes/No)&#39;, &#39;Sororities (Yes/No)&#39;,<br>       &#39;Athletic Division, Football&#39;, &#39;Endowment Value&#39;,<br>       &#39;Instructional Expenses (per FTE)&#39;, &#39;Research Expenses (per FTE)&#39;,<br>       &#39;Academic Support Expenses (per FTE)&#39;,<br>       &#39;Student Services Expenses (per FTE)&#39;,&#39;RANK&#39;]<br><br>    #Assign numerical features you want to pull from College Elasticube as well as your Target variable<br>    df_X = df_ed[corr_feat]<br>    y = df_ed[&#39;Freshmen Retention Rate&#39;]<br><br><br>    # Fit Lasso regression model<br>    lasso = Lasso(alpha=0.1)<br>    lasso.fit(df_X, y)<br>    <br>    # Get coefficients<br>    coefficients = pd.Series(lasso.coef_, index=df_X.columns)<br>    coef_sorted = coefficients.sort_values(ascending=False)<br><br>    # Put the series into a dataframe <br>    df_result = coef_sorted.to_frame()<br><br>    #renames axis and resets it a column<br>    df_result = df_result.rename_axis(&#39;Features&#39;).reset_index()<br>    df_result = df_result.rename(columns={0: &#39;Coefficients&#39;})<br><br>    return df_result</pre><p>In the code below, this runs an SQL statement to grab all the columns needed from your statement. If you have a line break in your SQL statement you need to add the f’ for Sisense to understand there is a string literal in the SQL statement to read the statement as an SQL statement. As well, \n shows that Sisense there is a line break within the SQL statement. This is just like a regular SQL statement except for the f’…. and the \n which allows Sisense to make sense of the connection being created.</p><pre>logical_sql = (f&#39;SELECT C.*\n&#39;<br>    f&#39;FROM [Colleges] as C&#39;)</pre><p>In the next line of code, we then create the connection to the Sisense table, giving the SQL statement we want to execute, the variable cube name, which we created above, and the count, which can limit the number of rows we fetch. We then run a check to see if the connection being made within Sisense is working and if not we can throw an “Error” to see where the connection is going wrong.</p><pre>#Run SQL statement to grab data <br>    logical_sql_res = sisense_conn.get_logical_sql(query=logical_sql,<br>    cube_name=cube_name, # passed to notebook from build / Test Cell<br>    count=None)<br><br>#Check if there is an error retrieving data<br>    if &quot;error&quot; in logical_sql_res:<br>        raise err.CustomCodeException(*err.ERROR_IN_LOGICAL_SQL, description=logical_sql_res.get(&quot;details&quot;))</pre><p>Our next line of code puts the SQL statement that we have fetched from Sisense from the specific cube name we assigned into a pandas dataframe. This will allow us to utilize the Python code to run an ML model on our data in this example. If you are utilizing custom code in Sisense, you can use Custom Code to manipulate your data in many various ways, and not just to run an ML model. We assign the values from our SQL statement into our data for the dataframe and headers for our columns.</p><pre>#Put values from Elasticub into a dataframe<br>    df_ed = pd.DataFrame(data=logical_sql_res[&#39;values&#39;], columns=logical_sql_res[&#39;headers&#39;])</pre><p>In my example, I had to deal with NAN values and replace them with 0s for me to run a linear regression model for feature selection. The code below replaces “NAN” values with “0&#39;s”.</p><pre> #Replace NAN values that came in as &quot;N\\A&quot; and replace with 0 for feature selection<br>    df_ed.replace(&#39;N\\A&#39;, 0, inplace=True)</pre><p>Now for my linear regression model, I can only choose numerical values to show what features have the highest correlation with the “Freshman Retention Rate”. This is a simple model to express what is the major contributors to the Freshman Retention Rate within colleges in the US.</p><pre>#Choose only numerical attributes from the College Dataframe<br>    corr_feat = [&#39;Acceptance Rate (Freshman Overall)&#39;,<br>       &#39;Admissions Yield&#39;, &#39;ACT Composite (25th %tile)&#39;,<br>       &#39;ACT Composite (75th %tile)&#39;, &#39;SAT Math (25th %tile)&#39;,<br>       &#39;SAT Math (75th %tile)&#39;, &#39;SAT Reading/Writing (25th %tile)&#39;,<br>       &#39;SAT Reading/Writing (75th %tile)&#39;, &#39;Cost of Attendance (In-State)&#39;,<br>       &#39;Cost of Attendance (Out-of-State)&#39;, &#39;Tuition (In-State)&#39;,<br>       &#39;Tuition (Out-of-State)&#39;, &#39;Percentage of Need Met (Average)&#39;,<br>       &#39;Average Need-Based Grant/Scholarship&#39;,<br>       &#39;% Receiving Merit (Non-Need-Based) Aid (Freshmen w/o Need)&#39;,<br>       &#39;Average Merit (Non-Need-Based) Award (Freshmen w/o Need)&#39;,<br>       &#39;Undergraduate Enrollment&#39;, &#39;% Full-Time (Undergraduate)&#39;, &#39;% Female&#39;,<br>       &#39;% Male&#39;, &#39;% African-American&#39;, &#39;% Asian&#39;, &#39;% Hispanic/Latino&#39;,<br>       &#39;% White&#39;, &#39;% International&#39;, &#39;% American Indian or Alaska Native&#39;,<br>       &#39;% Two or more races&#39;, &#39;% Out-of-State&#39;, &#39;% Other&#39;,<br>       &#39;Student-to-Faculty Ratio&#39;, &#39;Class Size (% Classes Under 20)&#39;,<br>       &#39;Class Size (% Classes 20-49)&#39;, &#39;Class Size (% Classes 50 or more)&#39;,<br>       &#39;% Full-Time Faculty&#39;, &#39;Average Salary (Full Professor)&#39;, &#39;4-Year Graduation Rate&#39;,<br>       &#39;6-Year Graduation Rate&#39;, &#39;Institution Size&#39;, &#39;Institution Setting&#39;,<br>       &#39;Institution Locale&#39;, &#39;Fraternities (Yes/No)&#39;, &#39;Sororities (Yes/No)&#39;,<br>       &#39;Athletic Division, Football&#39;, &#39;Endowment Value&#39;,<br>       &#39;Instructional Expenses (per FTE)&#39;, &#39;Research Expenses (per FTE)&#39;,<br>       &#39;Academic Support Expenses (per FTE)&#39;,<br>       &#39;Student Services Expenses (per FTE)&#39;,&#39;RANK&#39;]</pre><p>After I have decided upon what features are numerical and what features will play an impact on the Freshman Retention Rate I will then perform a Lasso Linear Regression model with an alpha of 0.1. I chose an alpha of 0.1 to allow for a moderate amount of regularization and show what features contribute less to predicting the target variable. We then fit the features and target variable to the Lasso Regression Model, put the values into a series, and sort. Then we put these values back into a dataframe as this is crucial for Sisense to output this Custom Code into the Elasticube model, do a little cleanup, and voila, we have our custom code table.</p><pre> #Assign numerical features you want to pull from College Elasticube as well as your Target variable<br>    df_X = df_ed[corr_feat]<br>    y = df_ed[&#39;Freshmen Retention Rate&#39;]<br><br><br>    # Fit Lasso regression model<br>    lasso = Lasso(alpha=0.1)<br>    lasso.fit(df_X, y)<br>    <br>    # Get coefficients<br>    coefficients = pd.Series(lasso.coef_, index=df_X.columns)<br>    coef_sorted = coefficients.sort_values(ascending=False)<br><br>    # Put the series into a dataframe <br>    df_result = coef_sorted.to_frame()<br><br>    #renames axis and resets it a column<br>    df_result = df_result.rename_axis(&#39;Features&#39;).reset_index()<br>    df_result = df_result.rename(columns={0: &#39;Coefficients&#39;})<br><br>    return df_result</pre><p>We run our last bit of code in running the function and having our output a pandas dataframe.</p><pre>df_result = feat_selection_lasso(cube_name)</pre><p>3. Leading to Insights</p><p>The whole reason behind running a custom code table within Sisense is that it can lead to many different insights. In my example, I was able to express the table I created in the form of a graph that will lead to certain KPIs for college students and the parents of college students. We understand that from this graph the Percentage of needs met, Cost of Attendance, SAT Math (25th % tile), and SAT Math (75th % tile) are some of the major contributors to the Freshman Retention Rate. Parents who a concerned about their child staying in college can look to these key contributors and focus on these attributes that will lead to a successful college career for their student.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*9n1V-lnWyUyzeqGNqa_Q0A.png" /></figure><p>Many more insights can be drawn using custom code, and this showcases just one of the many insights that we can draw from our data using Sisense.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53312e172f76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Power of SQL]]></title>
            <link>https://towardsdev.com/the-power-of-sql-ca8cbc32849a?source=rss-4195943c0c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca8cbc32849a</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rafael Ferreira]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 18:30:28 GMT</pubDate>
            <atom:updated>2021-12-18T15:05:14.919Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*7XO5bl94g5hYzeokWlV7tA.png" /></figure><p>If you are in any field that requires data and especially large data sets, then you have most likely have heard of Structured Query Language or SQL for short. SQL was created by Edgard Codd in 1970 at IBM in order to deal with the large amounts of data that was coming to the world on a regular basis. By the end the 70’s, SQL has made its way onto the scene as one of the main programming languages to learn, utilize, and access relational databases to help business of all types understand their customers, clients, and the world for the better or worse. Throughout this article we will dive deep into:</p><ol><li>SQL in the workforce</li><li>SQL with other languages</li><li>Resources for learning SQL</li></ol><h3><strong>SQL in the workforce</strong></h3><p>Now, you maybe asking yourself if I wrote the correct year that SQL came into existence, and I asked myself that exact same question. It has been over 50 years since SQL has come to be and yet it still one of the most widely utilized programming languages today. In fact, it is top programming languages utilized today amongst Data Scientist, Data Analyst, and Data Engineers. A recent analysis from <a href="https://www.dataquest.io/blog/why-sql-is-the-most-important-language-to-learn/">dataquest.io</a> done by Celeste Grupman showed that out of 32,000 jobs that mention the key word ‘data’ in it, SQL is one of the top programming languages to have as a skill set when applying to jobs with this key phrase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*L3UdEpLJTEiDXR__hG7FBA.png" /><figcaption>SQL being the top skill to have according to Indeed data base: 1/29/2021</figcaption></figure><p>Now this is quite general of an analysis dealing with the word ‘data’, but again according to Celeste Grupman, in her analysis, even in more technical heavy jobs, SQL comes close to first in mandatory skills in roles posted of that of a Data Scientist and Data Engineer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZEB9MsJ6x9xsoXH80yyU5g.jpeg" /><figcaption>SQL skills being among the top skills to have as a Data Scientist (Left) and Data Engineer (right)</figcaption></figure><p>And if that didn’t drive the point home, then maybe this will. Even among all the skills needed in developers according to StackOverflow developer survey in 2020, SQL comes in third as the most imperative skill to have for successfully completing your job as a data developer, even surpassing Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*JTeliKAIuTzNWADSAfa_SA.png" /><figcaption>StackOverflow 2020 developer survey</figcaption></figure><h3><strong>SQL with other languages</strong></h3><p>As mention above, SQL is a querying language structured to give a universal way to pull and manipulate large data sets. SQL is mainly used for automated reporting for databases, visualizing datasets, and to create machine learning models. SQL works with a plethora of other data languages such as Python, R, Java, and C#. I will just go into a couple of these partnerships and their uses.</p><h4>SQL and Python</h4><p>As mention above, if you are considering a life in data science then SQL and Python go hand and hand. Working almost perfectly together. SQL is not a language used for higher manipulation, and that is where Python comes into play.</p><p>Python is great for regression, time-series data, and statistical analysis where SQL is not. This powerful partnership will lead to more concise understanding of your data when performing regression analysis, along with easier visualizations of what is going on with your data.</p><h4>SQL with R</h4><p>R is another language that is widely used in the data science world, and the partnership of SQL and R go way back. R is specifically used in the academic settings being utilized for statistical analysis and graphics.</p><p>The one aspect that R has on Python is that you can create and query datasets while at the same time processing and analyzing data. Using the RSQLite package that helps you work with accessible data without setting up an external database.</p><p>Even better, sqldf allows you allows you to use SQL without needing to setup a data frame, doing away without any database.</p><p>I can go further into other languages and how SQL works with them, but I think at this moment you get the point of the usefulness of SQL. Now lets talk about where to learn this impactful data language.</p><h3>Resources for SQL</h3><p>Now that we have a basic understanding the importance of SQL as a skill and the languages that work with SQL, we now want to know where can we dive head in into learning the fundamentals of SQL. As well, even going further so that when it comes to applying these skills, we will have full confidence in utilizing these SQL in the workplace.</p><p>My first recommendation would be with <a href="https://app.datacamp.com/learn">Datacamp</a> or <a href="https://www.codecademy.com/">Codeacademy</a> for the basic fundamentals of SQL. Once you have decided and feel that you have your basics of SQL down, I would suggest going to <a href="https://www.dataquest.io/">dataquest</a>. This is where the heavier and technical skills of SQL will come into play. The skills that will be needed to be successful in your next job!</p><p>Best of luck to all the future ‘data’ scientist, analysis, engineers, and really any data drive job that may come your way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca8cbc32849a" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/the-power-of-sql-ca8cbc32849a">The Power of SQL</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[N-body Orbit Simulation]]></title>
            <link>https://medium.com/swlh/n-body-orbit-simulation-6c88267f281e?source=rss-4195943c0c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c88267f281e</guid>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[astrophysics]]></category>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[Rafael Ferreira]]></dc:creator>
            <pubDate>Wed, 24 Feb 2021 18:54:42 GMT</pubDate>
            <atom:updated>2021-12-14T16:49:09.553Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning the Steps to the Orbital Dance</h3><h4>Showing a Visualization of the Orbits of the Inner Planets</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*gBZ0jLMU1nifLY_su3gCcg.gif" /><figcaption>Actual orbits of our solar system, sped up to show the difference in orbits in terms of time.</figcaption></figure><p>When it comes to properly visualizing our solar system, astrophysicist realize there are many interactions among the different planets that affect the orbit of each body. When simulating just one body and its path, there are many interactions that go along with figuring out its trajectory.</p><p>In order to display the actual orbits of the planets, we must first bring this matter to simple mechanics. Newton discovered three distinct laws that govern our universe, with the second law being the one of importance for our simulation. The second law states that an object with mass <strong>m</strong>, and an acceleration <strong>a</strong> has a resulting force.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*S2_MSLCYg2OHuZe2jIgkjA.png" /></figure><p>The above equation also shows that an object of mass <strong>m</strong>, with any given force <strong>F</strong>, that will produce some resulting acceleration <strong>a</strong> . In this simulation we want to calculate the acting acceleration given by all acting bodies. The equation for acceleration of a single body, <em>i,</em> in a three coordinate system is in the x direction is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*kNutekgL_G5gdac65Av9BA.gif" /><figcaption>acting acceleration in the x direction given by multiple bodies.</figcaption></figure><p>The equation takes into account,<strong> G, </strong>the gravitational constant, <strong>m</strong> the mass of thee body, and the location of the body in the coordinate system of x, y, and z. Summing all values over all coordinates to get the resulting acceleration in one direction. In order to determine the y and z directional accelerations you change (x<em>ⱼ-</em> x<em>ᵢ</em>) to the dimension you want to calculate in. Now if we are given the bodies velocity and its position then by taking the derivative we are able to calculate the bodies acceleration.</p><ul><li>m<em>ᵢ</em> = mass of the object</li><li><em>rᵢ</em> = [x<em>ᵢ, yᵢ, zᵢ</em>] position of the object</li><li>v<em>ᵢ =</em> [vx<em>ᵢ, </em>vy<em>ᵢ, </em>vz<em>ᵢ</em>] the velocity of the body in all three coordinates</li></ul><p>Now we can start creating our classes and proper functions to create the simulation. First we need to import our packages needed to plot and create our classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4feafed566c94466c726aa8add06f7ee/href">https://medium.com/media/4feafed566c94466c726aa8add06f7ee/href</a></iframe><p>The first class we create is the point class that initializes the object state in all three coordinates, in which we will provide when we set up the body we want to simulate. Now, we need to set up the body class where we feed in the location, mass, velocity, and name of that body. Once we have these classes setup we can calculate the acceleration of a single body due to the forces acting on that object from external forces.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ae611d5cd719f5e0ab29c1070b577ed/href">https://medium.com/media/4ae611d5cd719f5e0ab29c1070b577ed/href</a></iframe><p>We first start with the gravitational constant , <strong>G</strong>, where that is the force felt between two bodies, and it is a weak force at that. This is why, in order to feel a strong resulting force, our objects need to have very large masses, in the order of billions of kgs. Then we initialize the acceleration to be zero, which then will be updated as we calculate the acceleration at various points in the orbit of the object. We then need to specify what our target body is when we calculate its acceleration based on the affect of the other objects. Next we need to grab the key, value pair for each target object and calculate its location and acceleration at that location based on its mass and velocity. Once we have the location of the object we can input this location into Kepler’s Third Law, T = Gm/ r³. Using this information we can then determine the orbit of our target body. Next, we find the acceleration in each coordinate system, then summing them up to one acceleration which will then used to update the previous orbit. As the target object moves throughout its orbit its velocity changes relative to the other objects gravitational affects on the target body.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4b486d20bebbbb68f41e4d011b26c65/href">https://medium.com/media/a4b486d20bebbbb68f41e4d011b26c65/href</a></iframe><p>Having calculated the initial orbits of each of the bodies in the system we again reiterate through each body to update their orbits at each different location. We use the previously calculated acceleration to update their velocity in each coordinate system overtime. With our velocity of each object now updated, we then can update the location of the object within its orbit of the given body based on the new velocity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/570cf86278ce3c544dc1091b9df37461/href">https://medium.com/media/570cf86278ce3c544dc1091b9df37461/href</a></iframe><p>We now iterate again for a third time to adjust for the new velocities. Then we can put these two functions together to refine the orbit at each gravitational step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/743cd4879456a7d45000f8fe94af7c53/href">https://medium.com/media/743cd4879456a7d45000f8fe94af7c53/href</a></iframe><p>Now for the fun part. Once all are pieces are together, we can simulate our bodies or objects around a single point mass, in this case the Sun.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d85759a27bfc0487ae180ab8d9220ac0/href">https://medium.com/media/d85759a27bfc0487ae180ab8d9220ac0/href</a></iframe><p>The first part of running our simulation is creating an empty list of the historical locations of each body in order to plot. Then we iterate through each body to update its locational history every time a new gravitational step occurs. We chose the size of the steps which will determine the new location and velocity. We then confirm that the gravitational step is an even number to check if we have an elliptical orbit.</p><p>Our final step, plotting the bodies. In this example, we will plot the Sun with Mercury, Venus, Earth, and Mars aka all the terrestrial planets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8ee1fafec98eaeeadc0d10ae5944010/href">https://medium.com/media/e8ee1fafec98eaeeadc0d10ae5944010/href</a></iframe><p>We first take in two parameters, all of are chosen planets, and whether or not we want to save the plot. We then create our figure, designate each planets to a color for differentiation of planets, and output the max dimension of each of the planets based on the gravitational step size we choose. Then plot!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*QW_WLZYsEqj2gxnIl20BAw.png" /><figcaption>Time Step equal to a 1000, number of steps equal to 100,000, and report frequency of 1000.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*jP9EUpADXkHReIM6N3WA0w.png" /><figcaption>Time Step equal to a 1000, number of steps equal to 10,000, and report frequency of 1000.</figcaption></figure><p>Each visual shows the difference of the orbits of all 4 planets at different gravitational step orbiting the Sun. The Sun is not displayed as the orbits are relative to the Sun, with the Sun being the center of our solar system. This is how you show the orbits of the planets or any given object using its mass, velocity, and location.</p><p>Side note: Shout out to <a href="https://www.blogger.com/profile/10690323237933067699">Ben Eagen</a> for showing this tutorial, and creating passion among many python programmers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c88267f281e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/n-body-orbit-simulation-6c88267f281e">N-body Orbit Simulation</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Following the Light to Discover New Worlds!]]></title>
            <link>https://medium.com/swlh/following-the-light-to-discover-new-worlds-1cd0b06c4951?source=rss-4195943c0c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cd0b06c4951</guid>
            <category><![CDATA[habitable-planets]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[astrophysics]]></category>
            <category><![CDATA[kepler]]></category>
            <dc:creator><![CDATA[Rafael Ferreira]]></dc:creator>
            <pubDate>Wed, 10 Feb 2021 23:34:41 GMT</pubDate>
            <atom:updated>2021-02-11T21:14:06.701Z</atom:updated>
            <content:encoded><![CDATA[<p>Using machine learning to detect planets orbiting stars in our local galaxy using the Kepler dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*wNPgoGHt0iZgHpcWzAZKzA.jpeg" /><figcaption>Kepler-186f is the first exoplanet found to orbit its local star in the habitable zone.</figcaption></figure><p><strong>Background</strong></p><p>On April 17, 2014 the Kepler satellite, found one of the most crucial finds in modern day astronomy. It detected a planet that orbited its local host star in the habitable zone, also called the Goldilock zone. A find that lead to speculation about how many planets out there are like our own. You may be wondering how the Kepler spacecraft detected such a planet if the stars that we observe are so far away, and the planets that orbit these stars are so much smaller than their host stars.</p><p>Kepler uses a technique widely used among astrophysicist and astronomers alike called the transit method. This is when the star being observed is detected to have a dip in brightness during the period of time that it is being observed. If the the perceived dip in brightness is observed to happen cyclically, then astronomers can say with confidence that a planet is orbiting said star.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2plVNXPMfnO1xMV2GYRRtA.gif" /><figcaption>The animated picture shows what the Kepler spacecraft observes. Showing three planets orbiting this star and how the dip in brightness reflects their presence.</figcaption></figure><p>The above image shows just how Kepler detected these various stars. Kepler detects the FLUX or brightness of the star. If the brightness of the star suddenly drops during the observation then the assumption here is that an object is orbiting that star, with this object most likely being a planet. In order to make interpret the differences in FLUX, we first need to understand what it means to have a detection of a planet. This is where machine learning comes into play.</p><p>Machine learning provides us with many tools in detecting phenomena within large datasets, including models. In order to use them affectively, machine learning models break our observations into four separate categories. For our purposes these four separate categories are:</p><ul><li>True Positives (TP): The number of observations where the model predicts there is a planet(1), and there actually is a planet (1).</li><li>True Negatives (TN): The number of observations where the model predicts there is not a planet (0), and there, in fact, is not a planet present (0).</li><li>False Positives (FP): The number of observations where the model predicts that there is a planet (1), but there actually is not a planet (0).</li><li>False Negatives (FN): The number of observations where the model predicts there is not a planet(0), but there actually is a planet (1).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*g5zpskPaxO8uSl0OWT4NTQ.png" /><figcaption>Confusion Matrix to show how precise our machine learning model actually is</figcaption></figure><p>Using <a href="https://www.kaggle.com/keplersmachines/kepler-labelled-time-series-data">Exoplanet Hunting in Deep Space</a> dataset I was able to explore this occurrence on my own. This labeled dataset catalogues fluxes for over 5,500 known stars without and with planets. I will now show you how to train a model that can be used on future observations using Python.</p><p>First, I need to import all the necessary packages:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7163dbdfeb105a356bf24db91d1521f/href">https://medium.com/media/d7163dbdfeb105a356bf24db91d1521f/href</a></iframe><p>This dataset is already split into a training and test set to check for cross-validation. I then want to explore the data to see how flux differs for stars with and without presences of planets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnKvJqDXeW7VJfiZbq4m1w.png" /><figcaption>Stars fluxes with the presence of planets</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRTpqOi-76f7uQwQNo2DpA.png" /><figcaption>Stars fluxes without the presence of planets</figcaption></figure><p>What we see is the fluxes of stars with planets when graphed show a more sinusoidal wave shape, where as the stars without planets show a constant shape. From the image below, there is a drastic difference on the amount of flux observed with or without a planet. This tells us that the scaling for each of the two classes are drastically different due to the light being blocked from a planet in comparison to a star that does not have any planet in orbit. I did not scale for this project but in future works, scaling would be required to get both classes on the same scale and see how the difference in flux compares to the two classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*mfQ35xDKXHt8LUhkeXB1Zg.png" /><figcaption>Stars without planets show I higher value brightness in comparison to stars that do have a planet</figcaption></figure><p>Now that I have explored the data, I can begin using the different models to see how they well perform on the dataset.</p><p><strong>Logistic Regression:</strong></p><p>The first model I want to look at is logistic regression model since this is a binary classification problem. Logistic regression uses the sigmoid function to put each observation into a class of 1 or 0. Running the code below we see that our logistic regression model has an base accuracy of 56%, but we can see from our confusion matrix that we have low precision.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/250081926f2bb58462daec79182dc0ff/href">https://medium.com/media/250081926f2bb58462daec79182dc0ff/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*O97FyvKCUdS-dAUGpMeh_A.png" /><figcaption>Confusion matrix for logistic regression</figcaption></figure><p><strong>KNN</strong>:</p><p>The next model I will be using is K nearest neighbors (KNN). KNN is a model that predicts our target value by looking at the observations that are nearest in distance graphically to observation we are trying to predict. I used Manhattan, Euclidean, and Minkowski distances to see how they differ in their predictions in finding the presence of a planet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f23770b760270e0015555856d6dce166/href">https://medium.com/media/f23770b760270e0015555856d6dce166/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*ZX44tJQar1FkP7a2Fpb7PA.png" /><figcaption>Confusion Matrix based on KNN</figcaption></figure><p>Each of KNN models give an accuracy score of 99%. This is a huge improvement in comparison to my logistic regression model, but one consideration to take into account is that our KNN models did not predict any of our stars with planets in the the testing set, but it predicted all the stars without a planet. This is because of the class imbalance. The majority of the stars are associated with the class 0, no presence of a planet. This creates a bias in the results for the majority class.</p><p><strong>Decision Tree</strong>:</p><p>Now I am going to run the data through a decision tree model. Decision tree uses recursive splitting in the feature space to group similar observations into regions. When creating predictions, it does so by associating the observation with class region it is most similar to.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26eaa0cffabece673c0b926866dcd007/href">https://medium.com/media/26eaa0cffabece673c0b926866dcd007/href</a></iframe><p>After running the decision tree model I get an accuracy score of 98%. However, the logistic regression model found more TP’s. Meanwhile, KNN picks up all TNs, where Decision Tree was only able to pick out 98% of all TN. Now, lets see if resampling our datasets will change the accuracy of each model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*gE2jTiNwA2qjDUg1YDkLJw.png" /></figure><p><strong>SMOTE:</strong></p><p>Due to how drastic our class imbalance is, I will be using a resampling technique to create better symmetry. SMOTE creates false data using the minority class. In this case the minority class is the stars with planets, as mentioned above. Here we create a class of balance of 1 to 2, meaning the number of observations that have planets is now 2025 individual observations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/643f43096044bb07f614520f0ae85718/href">https://medium.com/media/643f43096044bb07f614520f0ae85718/href</a></iframe><p>After re-running all three models, specifically using Euclidean distance in KNN, logistic regression became 54% accurate and detected 3 TP, KNN became 98% accurate but now detected 1 TP, and decision tree became 97% accurate, with 0 TP.</p><p><strong>Conclusion</strong>:</p><p>After running all three models and seeing how the accuracy scores compare, I wanted to compare precision, recall, and f1 scores to based on the resampling of the data. The reason for doing so is because I made a mistake with using accuracy as my primary metric of how well each model performed on my dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef716b3751baa0bb865975120aa5f5c6/href">https://medium.com/media/ef716b3751baa0bb865975120aa5f5c6/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*WW-FKbnMXVhL4TlsdieWew.png" /><figcaption>Precision, recall, and F1 score for all three models.</figcaption></figure><p>We can clearly see that accuracy is not the best indicator of making predictions on whether a planet exist or not. We need to take it a step further by looking at the recall metric. The recall measures the sensitivity of each model, and specifically in the context of this problem of detecting the stars with planets. Our models need to be more sensitive in detecting FN, predicting no planets when there actually is no planet present. From the recall metric, I can say that KNN was the best model in detecting stars with planets.</p><p><strong>Further Steps:</strong></p><p>I want to further improve this research by considering recall as metric as to how sensitive each model picks up FN. As well as, creating time stamps of each campaign that Kepler made which lasted, on average 80 days, along with taking into account the spectrum of each star to cancel out noise to output the best flux for each observation.</p><p><a href="https://github.com/Astroraf/exoplanet">Repo Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cd0b06c4951" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/following-the-light-to-discover-new-worlds-1cd0b06c4951">Following the Light to Discover New Worlds!</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stacking FITS photos]]></title>
            <link>https://astroraf.medium.com/stacking-fits-photos-a25e7c002ed3?source=rss-4195943c0c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/a25e7c002ed3</guid>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[stacking]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[fit]]></category>
            <category><![CDATA[astrophysics]]></category>
            <dc:creator><![CDATA[Rafael Ferreira]]></dc:creator>
            <pubDate>Wed, 27 Jan 2021 15:05:02 GMT</pubDate>
            <atom:updated>2022-04-01T14:20:13.431Z</atom:updated>
            <content:encoded><![CDATA[<p>Whether you are an amateur astronomer taking images of the night sky for pure amusement, or an astrophysicist sieving over large amounts of data to research star formation from various nebulas or examining young stellar objects (YSO’s), you will use one technique that is key to creating an image that is usable. This technique is called stacking.</p><ol><li>Background</li><li>Using it in python</li><li>Future works</li></ol><p><strong>Background</strong></p><p>You maybe asking, what exactly is stacking. Stacking is what it sounds like. You take the amount of photos you have taken of your object, in this case it will be the Horsehead Nebula, and overlay these images on top of one another. The reason we do this is to reduce as much noise as possible from the image. By doing so, the image of our object becomes crisper with every stack we overlay , allowing for the benefit of enhanced signal-to-noise ratio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*Y7rSZKsTPlUhOd9XSOeWdg.jpeg" /><figcaption>M31 also known as the HorseHead Nebula.</figcaption></figure><p>Astronomers, astrophysicists, amateur astronomers, and hobbyists alike all use one specific sensor that enables for present image takers to photograph the night so well. A CCD or charge-coupled device, takes in an electrical signal and outputs an image or video. This is due to various wavelengths of the spectrum given off by our electromagnetic spectrum. Astronomers and astrophysicists use the same device in most, if not all of the current satellites, depending on what part of the electromagnetic spectrum you are trying to capture. However, these beautifully designed machines are not without their flaws. The flaw, in this case, is the amount of noise present in each photo of the celestial object. That is where stacking becomes key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*hso-TBVRjATqxytLt8k3nw.jpeg" /><figcaption>A stacked image of Jupiter showing how noise is being cancelled out. Each image iteration showing the improvement of the image via stacking.</figcaption></figure><p><strong>Utilization of Python and Astropy:</strong></p><p>In today’s age, astronomers and astrophysicists alike use data science as a tool to improve models, interpret data, and analyze our universe with even greater confidence. Using a tutorial from AstroPython on viewing and manipulating FITS images. A FITS image, as defined by Wikipedia, is an open standard for defining a digital file format which is useful for storage, transmission, and processing of data formatted as multi-dimensional arrays. Astronomers use these files to take in the information taken from their object of interest. In this case, we will be looking at the Horsehead nebula.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_C8ZQwK7agfgLKPCzY3KmA.png" /><figcaption>FITS image of the sombrero galaxy.</figcaption></figure><p>First, task your necessary packages to process the image. To do this you need to import the packages numpy, astropy, plyplt, fits, and LogNorm as I have down below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96bc3a70289e511eceb17f6dbaa583b9/href">https://medium.com/media/96bc3a70289e511eceb17f6dbaa583b9/href</a></iframe><p>Then, we intake the image we want to process either from your local computer or, as in this case, an outside source. We call it to a variable to make it easier for calling this image. Once we have our image we need to open up our image being able to grab the array that is contained in the PRIMARY part of the file. Once we have an array of the image we can plot the array using <strong>imshow. Imshow</strong> takes a 2D array and outputs a 2D image. The image below shows the gradient of the Horsehead Nebula.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ff32f73ceba4abae27faf322e1f701d/href">https://medium.com/media/0ff32f73ceba4abae27faf322e1f701d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6713a8dace500175268b51e693ed13f/href">https://medium.com/media/c6713a8dace500175268b51e693ed13f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58e90b51812c2fe63c218f6bcceaee5b/href">https://medium.com/media/58e90b51812c2fe63c218f6bcceaee5b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*X6QtMZhqyWRGfbOCHEBrxw.png" /><figcaption>The HorseHead Nebula produced from a FITS file. d</figcaption></figure><p>This image gives us a lot of detail about the Horsehead nebula including how the transition of the cloud of dust, gas that is forming the stars, and where the dust cloud stops. This image is great for analyzing what is occurring within this specific nebula, but noise is still present within this image. Now, we can stack the image to further reduce noise. Next, by using the power of a for loop, we can begin to stack the image over and over again, overlaying them as many times as we have images ultimately producing one file. In this example, I used 5 images stacked over each other, before, once again, extracting the array data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/779544fb83d5f6e7356f8974c754df17/href">https://medium.com/media/779544fb83d5f6e7356f8974c754df17/href</a></iframe><p>Once I have this concatenated data, I can sum the list of all the arrays from each image and use another for loop to combine all the arrays into one final image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4df6334ec8887cf6f04033a3f3423aad/href">https://medium.com/media/4df6334ec8887cf6f04033a3f3423aad/href</a></iframe><p>Before we plot this image, we need to find out the best stretch, that is how best to fit the image on the page, by plotting a histogram of the final image that has been stacked. I can see that our range is from 2000 to 3000 for our color scaling and will use this data to plot the final image. And there you have it, our final image which denotes many of the characteristics of this nebula in a clear and concise manner.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e38404915f9f68997995270986d83b09/href">https://medium.com/media/e38404915f9f68997995270986d83b09/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*KRa_EMSsGYfhIebJaQXveQ.png" /></figure><p>Now we plot our final image with the parameters from the color scaling of 2000 to 3000.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a306dfc43139e3d1bb07272a81cb41ea/href">https://medium.com/media/a306dfc43139e3d1bb07272a81cb41ea/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*BRnoC1AAdxW-qw-uv9Q6zA.png" /></figure><p><strong>Future Works:</strong></p><p>In an upcoming project I will be using this method to stack images of the Small Magellanic Cloud (SMC) where the several YSO’s live, that I have classified in my thesis. This will assist in significantly reducing the amount of noise to get the best FIT image of the area of interest in the SMC. This will enable me to then extract the necessary information to plot the near infrared spectrum and properly determine the stellar characteristics of each of the YSO’s. To be continued….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a25e7c002ed3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Key: Data Science Value: Astrophysics]]></title>
            <link>https://medium.com/swlh/key-data-science-value-astrophysics-8fb8a3179f66?source=rss-4195943c0c35------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fb8a3179f66</guid>
            <category><![CDATA[astronomy]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[astrophysics]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rafael Ferreira]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 14:47:25 GMT</pubDate>
            <atom:updated>2021-01-13T09:46:32.771Z</atom:updated>
            <content:encoded><![CDATA[<p>Before programming was much of a thing, calculations by hand was how all scientists determined the many solutions to life. Whether it was determining Newton’s laws of gravity, how relativistic laws shorten or lengthen a person’s life depending where they are in respect to an observer, or figuring out the mechanics of a rocket to bypass Earth’s gravitational pull. In science we call this the brute force method. Taking hours upon hours to decide what are the right variables to use, what parameters the situation may have, that will ultimately further humanities’ understanding of this complex world. Our brute force method is a method all scientists know and love, but now with the use of computers and programming, scientists are able to speed up calculations by a tenfold. Scientists, and specifically astrophysicists, intake data from various satellite sources that have terabytes and even petabytes of data. Once the data has been collected, all the data must be gone over and cleaned up to then be readable to the scientist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rn4AQx_c4oTtHH5Ob_FV0w.jpeg" /><figcaption>The first ‘computers’, the women that contributed so much to the field of astronomy and astrophysics, analyzing various spectrums from various sources.</figcaption></figure><p>One such example is, in 1887 to 1927, Harvard employed 80 ‘computers’ to process spectrum onto glass plates to then categorize each star from their specific spectral features. These ‘computers’ were actually women that were employed to take individual plates and determine their effective surface temperatures and categorize them into a specific spectral class. In my thesis, I did something very similar in that I analyzed eight young stellar objects (YSO’s) that needed to be classified into their respective spectral types. The difference between their method and mine was that I had an actual computer to analyze my data. The brute force method took years whereas my analysis took mere months. The power of data science in the field astrophysics has allowed for astrophysicists to do calculations on petabytes of data in mere seconds enabling us to understand our cosmos in an expanding manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*rOh4SEPN3qXZJ1tr5oDDtg.png" /><figcaption>Scatter plotter made by Rasmus Groth showing the ten of thousands of galaxies used to determine the age of the universe.</figcaption></figure><p>These days we take for granted that we have machines to do all the heavy lifting in our calculations but even so there is more to it. In order to understand a calculation being done, you have to understand the procedure of the calculation and what to expect as an outcome. Once you have been able to understand the mechanics of the problem that is where data science plays a key role in expediting the research being done. For example, in the article “Give or Take a Billion Years” amateur data scientist Rasmus Groth determines the age of the universe with the help of astrophysicist, Peter Lauersen, from the University of Oslo. Rasmus uses Hubble’s Law to recalculate the age of the universe using the velocities of thousands of known galaxies. He used several packages like numpy, astropy, matplotlib, and SQL to clean up the data before starting the calculations. With several lines of code, Rasmus, a person who had no knowledge of Astrophysics, has calculated the age of the universe according to this dataset. The calculation stipulated in this article seems like over simplified but would have taken months without the tools data science provides.</p><p>Data science has also given the method of analysis known as machine learning , a method of data analysis that automates analytical model building, which has already had an impact in the field of astrophysics despite only existing in its current incarnation since the 1990s. In an article by Pierro Paialunga “Convolutional Neural Networks for binary classification of Solar Flares” creates a machine learning program that intakes numerous images of the Sun to decide if a solar flare is present or not. If Pierro were to have done this manually, he would have had to individually take each image to analyze the presence of a solar flare, also known as a Coronal Mass Ejection (CME). A process which surely would have delayed his findings by days if not weeks. By using a machine learning method he was able not only expedite his analysis but also find a way to use his findings in real time to determine if a certain solar flare will cause disruption to our everyday lives at a moment’s notice. Another example of data science progressing our understanding of our cosmic universe is the article written by Alper Cakir on “Detecting Habitability of Exoplanets with Machine Learning’’. In the articles Alper takes in two data sets from NASA exoplanet database and PHL data set which both pertain to habitability situations. Alper cleans and merges the data by dropping any null columns with more than 40% and any columns with more than 10 unique values. Having prepared his dataframe, he sets up his machine learning model to test the accuracy of detection of habitable planets. Without the ability to use machine learning capabilities, Alper would have to sift through the data for each exo planet to determine whether or not it fit the criteria for a habitable planet. While this may produce more accurate results, as humans are still better identifiers, it would likely require time and resources that none but the most well funded of universities would have access to and take months or years to produce anything viable or recreatable. Having this new tool, is enabling astronomers and astrophysicists alike to compute the strenuous computations that have riddled us all because of the amount of time necessary to determine just one step of the process.</p><p>I have already found this to be the case in my own research. As previously mentioned, in my undergraduate thesis, I had to intake ten various spectrums of specific YSO’s to determine their ages, masses, lumonsities, and effective surface temperatures. At the time I used IDL and was a novice to the programming world. As a student now at the Flatiron School who has just scratched the tip of the iceberg within data science I can see how my thesis would have been greatly improved. My computations and the fitting of my spectrum to given models of stars would have been much more sophisticated, including spectrum that involved inner and outer accretion disk to my models that created issues in my categorization of these several YSO’s. The processing time is another factor that would have been greatly reduced due to my understanding of data science and astrophysics, being able to conjoin the two seamlessly to produce more accurate results that thus contributed to an overall research paper that I was part of. A project that I will be taking on at a later date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*Odlp1D4WZDP-2ay-IRHMEg.png" /><figcaption>Kurucz models used to overlay on the several YSO spectrums to determine the stellar classification of each star.</figcaption></figure><p>As we have seen from several examples and my own research, that being able to use data science within the field of astrophysics greatly impacts astrophysics as a whole in the terms of computational power and reduction of computing time. The brute force method is needed in the first stages of computing any unknown variable and to be able to understand what an astrophysicist is exactly looking for in terms of a unique value. When an astrophysicist has a dataset that crosses the threshold of hundreds to thousands and beyond, this is where the resource of data science comes into play. Explaining why I am at the Flatiron School learning data science to be able to expedite humanity’s understanding of the phenomenon that occurs within the universe by an exponential time frame.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fb8a3179f66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/key-data-science-value-astrophysics-8fb8a3179f66">Key: Data Science Value: Astrophysics</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>