Covid-Svelte-Sciencey

covid-svelte-sciencey

Find the GitHub code here. See the completed covid-svelte-sciencey dashboard here.

After doing the covid-dash-sciencey post a while back, my desire to learn front end web coding to make cool interactive dashboards had just begun! Python and Dash were cool, and were relatively easy, but I had a desire to go straight to the source – Javascript! I had completed several certifications in front end programming (html/css/javascript) through Free Code Camp.

After completing the course projects, I spent some time building out a Covid Dashboard using API data from https://covidactnow.org/, a very good website with a free and open API. The code is really an extension of the D3.js (data visualization course on free code camp), which is a powerful graphics library for creating interactive visualizations within web browsers from data. See some examples above. I was also able to use several svelte components (sveltestrap, svelte-multiselect, gridjs-svelte), which were easy to implement and not too difficult to track down on Google.

 

 

Free Code Camp – HTML/CSS/Java Script

So I have been going through some code tutorials to learn front end web development. I was familiar with HTML back in middle/high school, but I have not kept on on modern web development at all! Nonetheless, I feel like all the great coding that I have done for computations, etc is cool and all – but having the skills to create a nice front end user-facing tool is really needed to bring that great work to broader audience. I had experience doing wxPython applications back in grad school, and recently I have learned R-Shiny which is quite powerful. Now I’d really like to get to the basics with some JavaScript!

As such, I’ve been using FreeCodeCamp‘s online courses to begin to develop my skills (so far I have done the Responsive Web Design Certificate and Javascript Algorithms and Data Structures Certificate in my limited free time after work. Honestly, the website says that it takes 300 hours, but I completed both in much much less than that.

I recently completed Front End Development Libraries certification, and I’d like to use this WordPress Page to link to the JavaScript projects that I’ve been working on as well as to document some of the things that had to be done to get these projects stood up on my own machine (and eventually on coolsciencey.com).

Front End Libraries

  1. Quote Generator (React – GitHub)
  2. Markdown Preview (Svelte – GitHub)
  3. Drum Machine (Svelte – GitHub)
  4. JavaScript Calculator (Svelte – GitHub)
  5. 25+5 Clock (Svelte – GitHub)

Data Visualization

  1. Bar Chart (D3 – GitHub)
  2. Scatter Chart (D3 – GitHub)
  3. Heat Map (D3 – GitHub)
  4. Chloropleth Map (D3 – GitHub)
  5. Tree Map (D3 – Github)

Getting Set Up

Coding on My Own Computer using WSL/Ubuntu

For these projects, i desired to manage my own environment rather than use codepen.io. I used Windows Subsystem for Linux (WSL) which comes pre-installed with Windows 10+ (really a game changer for coding on Windows, in my opinion). After installing WSL; install Ubuntu from the windows store and you’re good to go.

Setting up ubuntu, node package manager (npm), create-react-app, and/or svelte-kit

I was able to get everything set up on my linux environment, and I wrote up these instructions on how to do it. Which were a combination of the sources found in the “References” section.

Consider using pnpm rather than npm, which does not re-install dependencies every time resulting in smaller development disk space usage! I had to manually install some d3 dependencies to get it to work with svelte-kit, but otherwise didn’t have any issues.

Project Comments

Front End Libraries – Project 1 – React

At first, for project 1, I used React/Redux as was taught in the Free Code Camp course. The React front end framework, backed by Facebook is a very popular front end library and it seems like a natural choice for folks who are just getting started. Unfortunately, state management through Redux, I felt, made this approach more complex than was necessary (especially for simple apps like this one).

Front End Libraries – Project 2-5 – Svelte

For projects 2-5 I decided to use Svelte which was recommended to me by a colleague. Relative to React, this new front end framework(not actually a framework, more of a compiler), is supposed to be more lightweight than React and faster to load. It is growing fast, but is not nearly as widely used as React. As I was learning Svelte, I found the Svelte web tutorial very informative and was more than enough for me to get started with the language to complete these projects. I found the syntax of Svelte to be quite appealing and easy to understand and interact with; it also created very lightweight apps and worked will without a huge learning curve.

Data Visualization – Svelte/D3 combo

“Data Driven Documents” or D3 – has always intrigued me as a way of displaying charts and graphs within a web browser. Previously I had used a d3.js product, Plotly, in projects that I had built in Python and R. While the interactivity of Plotly charts is very good out of the box, I felt like learning D3 would be a worthwhile use of my time since it’s the gold standard for data visualization in web browsers. The Free Code Camp Data Visualization Certification is a decent introduction to API calls and using D3. I found the examples themselves not particularly useful – but the projects were a good way to build a decent skillset in setting up simple (and some more complex) d3 charts. I had done this one in Svelte as well, but honestly not many Svelte components were actually used in my projects; however I think that Svelte and using Sveltekit is easy enough that it made sense to start a new project with this every time!

Conclusions

Anyways, this was a nice experience, and I think that my next step will be to redo my Covid dashboard using JavaScript!

References

  1. create-react-app instructions
  2. svelte-kit instructions
  3. svelte adapter-static build instructions (needed for coolsciencey.com since I do not have root access to run sever side rendering)
  4. ‘smui’ Svelte Material UI bundle – used for ‘icon-button’ in project 5

Covid Dash Sciencey

Intro

Obviously with the global pandemic ongoing, a very serious issue, I have been looking at various sources of information for daily cases, etc. especially WorldOMeters.Info – Coronavirus , Johns Hopkins Coronavirus Resource Center, and the New York Times Coronavirus Map.

While these existing dashboards are great, I wanted to learn how to put together my own as a learning exercise. This was a good opportunity to exercise my Python skill using Plotly-Dash using the widely available Covid-19 data that’s available on the internet (I chose the New York Times GitHub data source as my starting point, which is updated daily).

You can access the embedded dashboard below, or you can view the full screen one directly from Heroku: https://covid-dash-sciencey.herokuapp.com/. The code is available at my GitHub zacharygibbs/covid-dash-sciencey. I will include a write-up below on how I went about learning how to build this dashboard and where you can find the code.

The Dashboard

Building this dashboard and deploying to GitHub/Heroku was straightforward after following some online Examples and the Dash Documentation.

If I was starting again from scratch, I would have liked to have found the following all in one place without quite so much googling –

Multiple Columns

This Post on the Plotly Community docs lays out how to arrange your dash app to have multiple columns. It all starts by linking an external stylesheet

(external_stylesheets = [‘https://codepen.io/chriddyp/pen/dZVMbK.css 72’])

Then using the class name and defining as rows or columns nested to suit your needs.

html.Div(className='row', children=[
    html.Div(className='six columns', children=[....])
    ... (repeat as needed)
])

Apparently the ‘six columns’ can be adjusted to suit your desired width (apparently, each page is divided into 12 columns), meaning that ‘six columns’ is what you would use to divide into halves. For my covid-dash-sciencey app, i did a ‘three columns’ and ‘nine columns’ setup to get 1/4 width column for menus and 3/4 width column for charts.

Filter Data Based on User Input

Ultimately, the goal of my simple app was to display the data while allowing for the user to filter based on state/county and to toggle between cases/deaths and linear/log scale. This is something that I had found difficult on other dashboards (either was not done consistently, or was difficult to navigate). I was able to find a great example of filtering based on control dropdowns and radio buttons on the Plotly Community page.

The interactive portion of Dash comes in the Dash-Callbacks. This example allowed me to understand the Input and Output arrangement of the callbacks and how to very easily pass them between objects within the app.

Deployment to Heroku

After tinkering around on my localhost (127.0.0.1) for a while, and eventually deploying within my wireless network (0.0.0.0.0), I was ready to deploy the app more widely. Several great examples explain how to set up your application for deployment to Heroku: (Plotly Docs, TowardsDataScience example, this article). Being a Linux noob, I referred to these articles extensively to set up my virtual environment, install all of the requirements, and eventually deploy to heroku local. It’s amazing how powerful and simple these scripts are (when they work), but sometimes it’s just getting everything set up that takes a while.

Bonus – Raspberry PI 4 Setting Up Dash on Python 3.6

I had recently purchased a Raspberry PI 4 B from Adafruit. This latest version was a step change improvement over my PI Model B that I originally bought in 2013.

In order to get Dash up and running on the Pi’s arm7l processor, I had to install
Raspberry pi BerryConda https://github.com/jjhelmus/berryconda

Conclusion

Great learning experience! I hope to build more apps in the future.

Quantitative Personal Finance – Pay Off the House First?

Introduction

As was the theme of a previous post, the goal of this post is to perform quantitative analyses of several personal finance areas. Previously, I looked into the real cost of paying down debt first, a-la the Dave Ramsey method. In this post I will consider the options of what to do once you have paid off those debts. After contributing 15% of your income to retirement and saving a 20% down payment for a home, additional money can be put into either additional principle payments on your home “Home First”, or placed into a taxable investment account “Investment First”.

The math problem is simple–it will be better for the numbers to invest these funds where the higher rates of return are.  Generally, a taxable investment in such as in mututal funds or ETFs (7%+ returns generally) will be better than paying additional principle on your home mortgage (<5% interest generally). My goal here is to put a dollar value on the upside; this can help to place a value on the higher risk equity investment route.

Results

Pay off the House vs. Investing

Assumptions were made with respect to income, expenses, etc. as described in a previous post. Figure 1 shows the 10 year net worth calculation given that the priority is to pay the house off first (while at the same time saving 15% to retirement). This can be compared to the distribution of net worth shown in Figure 2 where the minimum payment is made on the 15 year mortgage, and additional savings is placed in after-tax investments (assuming 7% annual return). In these calculations, an initial debt load is paid off over the first 4 years. Afterwards, an emergency fund and mortgage down payment (20% of 200k house) is saved. This calculation only accounts for a relatively short timeline of only 4 years of home ownership (home purchased once a down payment was saved at month 77).

Figure 1: House First option where a 15 year mortgage is paid with priority once the house is purchased. Retirement savings of 15% of income also occurs. Figure 2: Investment First option where a 15 year mortgage is paid with priority once the house is purchased. Retirement savings of 15% of income also occurs.

As expected, the “investment first” option comes out ahead by ~$1800 after this 10 year period (after-tax net worth $152,900 vs. $151,100). While this is not a small amount of money, it is not a significant amount in the grand scheme of things (only ~1.2% greater net worth). There are fair arguments on both sides. “House First” folks may prefer this option because they are particularly debt-averse or that they are worried they would spend the extra money if they kept it in cash. The “Investment First” option makes sense for people who are investing for a longer time-frame and may be interested in having the money more accessible (not tied up in the illiquid mortgage).

15 vs. 30 Year Mortgage

One additional calculation was performed to assess the mortgage length of 15 or 30 years. Previous calculations were performed with a 15 year mortgage, but some people may prefer leveraging their debt load and re-investing the saved money. However, because the interest rates on 15 year mortgages tend to be lower (I used 2.5% interest rate for the 15 year rather than a 3.375% for the 30 year loan), the interest payments will be quite a bit larger when a 30 year loan is taken. Figure 3 shows the 10 year, after-tax net worth for the 15 year mortgage where the “House First” option is chosen vs. the 30 year mortgage where the extra money is paid to investments using the “Investment First” option.

Interestingly, the 15 year “House First” net worth still increases with investment rate of return because of the retirement contribution. However, it is clear that for investment returns greater than ~10%, the 30 year “Investment First” option is more attractive. Now over its lifetime, the S&P 500 has >10% average annual rate of return (for long term investments), and so generally the 30 year “investment first” option will be better. However, in the short term, the variability of the returns make this far from a guarantee and highly dependent on market conditions. Because of the “personal” aspect of personal finance, the decision to choose one option vs. another should be made by each individual.

Figure 3: Comparing a 15 year (House First) and 30 year mortgage  (Investment First) with investment preference as a function of the investment return.

Conclusions

Even though the “Investment First” option leads in these simulations, the difference is less than $2000 (out of ~$150k for this 10 year period). A large portion of this 10 year period was spent paying off debt and saving for a down payment, so the differences will become larger over longer time periods. Ultimately, this decisions should come down to whether you would prefer a guaranteed, illiquid return by investing in your mortgage, or a riskier (certainly in the short term) but more easily accessible investment in the stock market.

Dave Ramsey Method – Quantitative Analysis

Introduction

As I’ve exited school and begun in the working world, I have developed an interest in personal finance. In particular, I’ve been interested in the best way to pay off debts (student loan, credit cards, auto loans) in order to put yourself on a path to building wealth for retirement, etc.

In my pursuit of knowledge, I’ve came across a variety of strategies. One of the biggest Personal Finance personalities that I discovered through podcasts is Dave Ramsey. Dave Ramsey provides a series of steps that he promises will help you to get out of debt and become wealthy and generous. “Live like no one else, so you can live and give like no one else”. He stresses becoming debt free through hard work (picking up extra hours or additional jobs) and trimming down your expenses during this process (beans and rice!). After paying your debt down with “Gazelle” intensity, your payment-free budget can be used to quickly build up a larger emergency fund, save for a home purchase, invest towards retirement, and pay additional mortgage principle.

However, the Dave Ramsey method is not without controversy. Because debts are to be paid down with gazelle intensity, other savings goals are to be ignored until “Baby Step 2 – pay off all debts” is complete. Some people disagree with this, and don’t see an advantage to paying off low interest rate debts when the money could achieve mathematically more through retirement investing/etc. One of the more inflammatory things he suggests is not going for the company matching retirement contributions. Many people outside of the Ramsey circle see these matching contributions as free money (guaranteed 50-100% return!) and additional income that you’re passing up (www.reddit.com/r/personalfinance is another good resource). Ultimately, after listening to dozens of hours of Dave’s podcast, it’s clear that he doesn’t expect a “gazelle” intense baby step 2, i.e., a barebones sacrificial budget with extra work if possible,  to take more than 2-3 years. If it does take longer than that, either you’ve got a ridiculously large amount of debt, a very low income, or you are not living on beans and rice (and your budget could be cut further).

The goal of this blog post is to quantify the Dave Ramsey method, in particular with respect to leaving out the 401K match. I will compare long term wealth building potential when following Dave’s steps versus other recommendations.  Ultimately, it will come down to how deep you are willing to cut to give up the 401K contributions, and whether the psychological win of paying off debt exceeds that of saving for retirement.

401K Matching vs. Paying Down Debt

Introducing The Software

First, I built a financial calculator that was probably overkill for solving this particular problem. I built in lots of little extras for computing your net worth and wealth distribution over time along with plotting features, etc. This code is available for free use/editing/contributing on the DaveRamseyFinCalc page on GitHub. I’d like to build a web-interface (Plot.ly?) at some point, but for now I’d like to get this post up. Future posts may follow with additional considerations with respect to the Dave Ramsey budget (one in particular is whether paying off your house early makes sense).

Stating The Assumptions

While it is possible to enter in a variety of values for your income, starting debt, assets, etc, I’m going to take a simple base case where you fit the following:

  • $50k salary
  • $63k in debt ($14k auto, $2k credit card, $49k student loans)
  • 5% 401K Matching (100% vested immediately)
  • 25% tax bracket
  • 25% of (after tax) income paid to rent = $781/month while paying off debt
  • Once debt paid, purchase a $200k house w/ 20% down
  • Contribute 15% of pre-tax income to retirement once debts paid off
  • Inflation rate of 1.5%
  • 7% investment return
  • 10% capital gains tax

I’ve made further assumptions about how much you spend on food and utilities ($650 + $200 = $850/month); Including rent, this totals $1631 (on month zero, before inflation has kicked in). Further, a $1000 emergency fund is used in both cases until debt is paid off, after which 4 months of expenses are used. Other assumptions and additional calculation details can be viewed in the DaveRamseyFinCalc GitHub code.

Results

Dave Ramsey vs. 401K Match

First, I’d like to show the overall calculation results with expected net worth accumulated over time.  Figure 1 shows the results of a 10 year calculation using the Dave Ramsey method (left) and the 401K Match preference (right).

Figure 1: Top) Wealth over a 10 year period using the “Dave Ramsey” method of preferring debt payoff. Bottom) 5% 401K Match, where retirement savings is preferred over debt payoff in the initial years. Wealth is given in $, Net worth computed is pre tax.

 

In this calculation, 401K contributions are assumed to be made “before tax”. For this reason, the “taxed” wealth should be used as a comparison between the two methods (dashed line) as shown in Figure 2. It is clear that when comparing the after-tax (dashed lines), the results are closer together. This is because retirement contributions are assumed to go in before-tax, which inflates the “net worth” calculation (solid line). When considering the Dave Ramsey calculation, you can see that there is no difference between the before and after tax net worth until ~80 months. This is because of Baby Step 3b, which states that you should save for a house down-payment prior to contributing towards retirement as well. This extends the length of time that you’re not receiving the match even past the time to debt-free.

Figure 2: Net worth over a 10 year period assuming the 5% 401K match or the “Dave Ramsey” method of paying off debt first. The dashed lines in their corresponding colors represent the “after tax” amounts.Wealth is given in $.

Effect of Varying 401K Match Amount

An additional calculation were performed varying the amount of the 401K match contribution offered by your employer. We can see that as the 401K match approaches zero, the 10 year net worth approaches $138k. The Dave Ramsey method does increase slightly with employer matching amount, however the rate is not as quick as when you’ve prioritized the 401K match. This is primarily due to the fact that it takes more than 3 years to pay off the debt, and missing out on this initial loading of your 401K causes a diversion of the 10 year net worth by as much as ~$50k for 401K Match of 10%. Table I also details the result as a function of match amount.

Figure 3: Net worth over a 10 year period assuming the 5% 401K match or the “Dave Ramsey” method of paying off debt first as a function of the offered 401K Match from your employer. Wealth is given in $.

Table I: 10 year taxed net worth as a function of 401K match amount (%).

The Caveat

So the previous plots show the real value of the 401K match, and how they can put you in a pretty good position relative to if you had prioritized debt payoff via the Dave Ramsey method. As an avid listener of Dave Ramsey’s, this isn’t something that he tries to hide. He receives the question often, and I’ll try to explain his justification. He sells the “gazelle intensity” where you cut your expenses back so much to attack the debt. As a result, the amount of ground lost on retirement would not be as large. Until now, this isn’t something that I considered, because both methods used the same monthly expenses. Further, this gazelle intensity combined with the “Snowball” Method of paying off your smallest debts first leads to the psychological wins necessary to keep lots of people going in this rough, beans and rice time.

I aimed to quantify Dave’s definition of “Gazelle intensity” by determining how much one would have to cut back their budget in order to attain a net zero taxed net worth in the same month as if you had been contributing to the match on your 401K.

Figure 4: Expense reduction required to attain zero taxed net worth at the same month using the Dave Ramsey method (cyan) as the 401K match method (black).

An additional consideration is how long you’re living on the edge with a bare-bones emergency fund ($1000). In this simple calculator, I’ve taken as a given that until the debt is gone, the emergency fund will stay that size. This may or may not be a reasonable thing to assume, but it’s what Dave Ramsey teaches. Either way, you end up having less time living on the brink if you’re paying off your debt faster.

Figure 5: Number of months that it takes to become debt free using the 401K Match method and the Dave Ramsey method (open black and solid cyan symbols, respectively). Also, the time that you reach zero taxed net worth using the 401K method (solid black symbols)

Conclusions

At the end of the day, I love Dave’s podcast. It’s entertaining and inspirational to listen to people who strive to become debt free. His baby steps do make a lot of sense, and I don’t think that there’s anything wrong with encouraging frugality and hard work. Dave aims to target the widest possible audience, which includes those who haven’t really ever thought about personal finance, and may not even have a reasonable budget estimate. At the end of the day, if you spend more than you make and you’re not intentional with your $$ it will be difficult to get ahead. Regarding the 401K Match, it’s something that’s definitely going to put you ahead in the long run and as long as you understand it (and are intentional with it!), it’s extra income and will be helpful.

Statistics while Driving To Work

Interesting science and data is all around us in our everyday lives. It sometimes just takes a paper and pen (or notepad app on your phone) in order to capture and analyze it. Having recently moved to a new city and new house, I decided that I wanted to statistically solve the age-old problem: which route is fastest for my drive to/from work? I narrowed the test down to 3 separate routes. When determining which one is the best, though, it’s not as simple as driving them each a single time. I wanted to determine which one was statistically better over many trips to account for the changing road conditions, stop lights, time of day, etc. After all, saving 2 minutes from your daily commute can add up to over 8 hours per year (2 minutes per day * 5 days/week * 50 weeks of work/yr= 500 minutes!)!! 

Results Summary

Data Source Stats

We have two different cars (Passat and Explorer); I also collected data in both the morning and evening. I’ve included the statistics for how much each car and route were driven. I recorded data for a total of 35 trips (over a period of a few months): 
Here we can see that route 2 had more overall trips, but overall the trips were mostly evenly spread. Regarding car, trips were recorded nearly evenly between the two. It did seem that I preferred to record data after my evening drive more than my morning. This may have been as a result of my haste to get into the office, I forgot to write down the drive time on several occasions.

Data Representation

I have been listening to an NPR podast called “Note to Self” that analyzes our relationship to data, social media, and technology. One interesting episode described two data scientists who recorded small details about their lives every week, drew sketches compiling this data in interesting ways, and sent it to each other on a postcard – NPR Note To Self – Facing our Weirdest Selves (see pictures of examples and audio of the episode). This episode inspired me to make a drawing that represented the data that I collected during this process as shown below:
I’ve represented the different routes by the three different colors (Route 1 – Grey, Route 2 – Orange, Route 3 – Blue). Morning and evening were drawn as circle or square respectively. Which vehicle was used (Explorer or Passat) was also represented, with trips in the explorer having a smaller shape inside, and Passat ones using the open symbol. The size of the shape represents the time that each trip took. The fastest trips are smallest, and the slowest trips use the largest symbols.

Dataset Statistics

On with the statistics: Tables that represented the statistic for trips along the three different routes are represented below:
I’ve included the average, standard deviation, max/min, and quartile 1/quartile 3 for the dataset along the different routes.
I also generated a Box Plot (using Excel’s Stock Chart – which was tricky to learn), shown below.
From the table and Box Plot, we can see the differences more clearly. The average trip length for Route 1 was a bit higher than Route 2 and 3. However, Route 2 had the largest standard deviation and both the longest and shortest trip lengths. This may have been partially related to the fact that Route 2 also had the largest number of trips (40% of the total as shown in the Pie chart above). While one could with some certainty say that Route 1 seems longer than Route 2 and 3, a simple hypothesis test can show this.

Hypothesis Testing

Hypothesis testing can be used to determine whether two data distributions have the same mean values or not, known as T-testing in this case. This article from NIST.gov illustrates how to perform this test.
First, the T-statistic needs to be computed for the three cases (Route 1 vs Route 2, Route 2 vs. Route 3, and Route 1 vs. Route 3). The T statistic can be computed using:
Where YBar1 is the average for route 1, s1 is the standard deviation, and N1 is the number of times driven.
Then the hypothesis should be rejected if the t-test gives a significance of less than 5%.
This was computed using the excel function =T.dist(-1*T, DOF, True); Where DOF (degrees of freedom) was computed using v- given in the reference [or just N1+N2 -2 if equal variances are assumed]. Of course, this process can be skipped if the number of replicates is equal for the different cases.
The results are summarized in the following table:
Alpha is related to whether the two means are statistically different. Conventionally, if Alpha is greater than 5%, then the two cannot be said to be statistically different. On the other hand, if alpha is less than 5%, then the two can be said to be different. In this case, it is clear that Route 1 is different from 2 and 3. Route 2 and 3 are very nearly equal, and therefore can be presumed to be the same within error (although the hypothesis testing can never fully prove this since they may be similar, but not exactly the same).

Conclusions

Over the course of several months of data collection, I have determined that Route 1 is statistically slower than the others. Having been the one to collect this data, I believe that this may be for two primary reasons: 1. This route goes right by a high school, causing the morning commute to be delayed somewhat, and 2. This route was undergoing some construction, causing detours (that I, for the most part, left out of the dataset). Recently, I have been driving Route 2 almost exclusively, as it does seem to consistently take the least amount of time. Future studies might look at the number of miles for each route (gas mileage?), the number of stop lights, or possibly whether we can resolve a difference in time of day/the car that was used. 

Arduino Powered Sous Vide

Hi all,
 I have been playing around a lot w/ electronics, in particular the Arduino. For those that don’t know, Arduino is basically an open-source microcontroller (coded in C) that can be used for reading sensors and controlling electronic devices as a result. In this particular post, I decided to do a food-related project called “Sous Vide” that consists of a constant temperature water bath that you can cook various meats in to a perfect, uniform temperature that makes them taste amazing. While there are many commercial products on the market (Amazon affiliate link: Anova Culinary PCB-120US-K1 Bluetooth Precision Cooker, 800 Watts, Black), I wanted to make my own as a fun project.
I started by putting together a power box. This consisted of a solid state relay, a wall outlet (GFCI is probably best), a fused/switched  power input line, a project enclosure box, and an external power source (wall voltage, 120V). The relay was triggered on/off by a 5V signal from the Arduino. I used an Arduino with a buttoned LCD display, and a thermistor temperature sensor. Using these, I was able to build a setup that I could set the temperature I wanted to run at, plug in my crock pot, and control using my power box. (Feel free to purchase components through my Amazon affiliate links)
lz1lko5
Unfortunately, the crock pot heated very slowly, taking 1.5 hours to get to temperature. I decided to augment the system using a standard coffee pot heater. Here is a picture of the setup:
ubn1ocgHere, I used a wall powered GFCI outlet (for safety), with the powerbox/arduino setup, a slow cooker pot, water pump, and a coffee machine water heater.
qd8xt7n
The coffee pot heater that I salvaged from an old hot water heater, I used in conjunction with some food safe, high temperature compatible tubing (I had to buy the 1/2″ to 1/4″ adapter hose barbed pieces on E-bay). The heater  took 120V AC power directly, which I hooked up directly through the solid state relay in the power box.
jp1m3gc
I purchased a 9V submersible pump that could handle up to 180°F from E-bay, and pumped water through the coffee pot heater at a rate of ~400 mL/min. After hooking up the thermistor and Arudino to complete the control loop. I was able to maintain reasonable control of the temperature. In order to implement my chemical engineering controls knowledge, I built a PID temperature controller that viewed each of the integral, derivative, and proportional controls in Python (wxpython, matplotlib; used Arduino serial communication to send data to laptop):
aase9om
The first graph: Black is the set point, and red is the temperature (see that it overshoots by ~1.5 degreesF at first, then dampens out). The second graph shows the controller parameters: black is the p (proportional), red is the integral (builds up over time the longer that the system is away from the setpoint), blue is the derivative (accounts for how quickly the temperature is changing), and green is the overall %on (the sum of the others, except for the derivative which is subtracted).
The finished product after I had set the crock pot at 135°F (medium rare temp) for about an hour w/ a nice Ribeye:
2aokg6w
After a quick sear (a minute or so) on each side (cast-iron pan with a little bit of oil, quite hot), the steak looked amazing (and tasted the same). The texture was uniform all the way through, and was extremely juicy!
Overall a fun project, let me know if you’ve got any questions!
Zach

Frost On My Car

Frost On My Car

So, with the brunt of winter upon us I thought that I would share some of my experiences. Living in Oklahoma, our winter hovers on the edge of freezing quite often. One thing that I noticed right away was that on many nights that were near freezing (35°F or so), I would have to scrape ice off of one side of my car, but not the other. A few questions came to mind, First: Why is my car frosting when the low temperature was not below freezing (32°F)?, Second: Why was the ice only forming on one side of my car and not the other?

So this is approximately the setup of my car sitting in the drive way (garage door in front of it):



First, the initial question: Why would ice form when the temperature wasn’t freezing yet? The answer is simple, but probably not something that most people think about. It boils down to radiation. If we think about what temperature the car is in absolute terms (i.e., with the vacuum of space defining a temperature of absolute zero–Zero degrees Kelvin), your car sits at let’s say 35°F=1.7°C=275 °K. This is significantly higher temperature than the vacuum of space, which is readily accepting the radiated heat from your vehicle. Of course if the sky is cloudy, the clouds will be significantly hotter than outer space and the chance of frosting over will be much lower.

Question 1: Temperature at Which the Window Should Frost

Now, to do a quick thought experiment to determine lowest approximate ambient temperature (T∞) that might lead to the window frosting over.

Radiation

The amount of heat radiated from your car window to space can be described using the Stephan Boltzmann Law (assuming your car window is a black body):

 q = σ (Twindow – Tspace)^4


Where q is the heat flux (per unit area), σ is the Stefan Boltzmann constant (5.67E-8 W/m^2/K^4), Twindow is the temperature of your car in Kelvin, and Tspace is the temperature of outer space. 


However, the story is not so simple because the car window is actually receiving radiation from all around (the adjacent buildings, walls, etc). Here is a schematic (and actually picture) from the car of the adjacent building that shows the “view factor” of the window to space.


And the actual picture from the car:


In this case, the “view factor”, accounts for what percentage of the window surface can radiate to another object (in this case, we’ll consider outer space and the adjacent house). From this picture, I’ll estimate the view factor of the window to space as ~0.1 (i.e., 10% of the radiation from the window is radiated to space while 90% is radiated to the adjacent house/ground/etc.). Also, the window is at a slightly lower temperature (let’s say the freezing temperature of water, Twindow=32°F=0°C=273.15°K) than the adjacent house (which is warmer–possibly around or slightly higher than the ambient temperature, T∞).

The net  heat loss from the window due to radiation can be computed by:



Where we’ve assumed that space is approximately 0°K and that the adjacent house temperature is slightly higher than the ambient temperature (Thouse = T∞+ΔT). With this, we’ve developed a function for the amount of radiative heat transfer out of the window given the ambient temperature (T∞) and an assumption for the house temperature relative to ambient (say ΔT = 4°C or so–as in the house hasn’t quite cooled down to ambient yet–which is reasonable).


Natural Convection

Now that we’ve considered the radiative component of heat transfer, let’s consider the counteracting force of convective heat transfer. In this case, because the window is at the frosting temperature (Twindow=0°C=273.15K) and the ambient air is possibly a higher temperature, the ambient air will actually act to warm the window. This will be what is known as natural convection (i.e., cooling by air that moves over a surface due to the fact that  it’s being heated or cooling, as opposed to force convection which might happen if it is windy). 

The relevant equations that allow us to compute the convective heat transfer coefficient, h is that for the Nusselt number (Nu):


Where kair is the thermal conductivity of air at 0°C (http://www.engineeringtoolbox.com/air-properties-d_156.html) and Lwindow is the characteristic dimension of the window (assumed to be ~1 meter). The remaining parameter is the Rayleigh number (Ra), which is given by:


The Rayleigh number is a dimensionless number that is the product of two other dimensionless numbers: the Grashof number (Gr) and the Prandtl number.

 

The Grashoff number takes the ratio of the fluid buoyancy to the viscous driving forces. Here, we use the thermal expansivity (β = 1/T for an ideal gas) and the kinematic viscosity of air (νair).

We can compute the Ra number for a given ambient temperature (T∞).

Which can be used to compute the convective heat transfer coefficient (h) as a function of T∞.

By balancing the convective (qconv = h*(T∞-Twindow)) and radiative heat fluxes, we can come up with a final answer to the question of what temperature might the window on that side of the car freeze:


The ambient temperature (T∞) which gives a net heat flux of zero (i.e., which can sustain the window at Twindow = 273.15K), for the given assumptions is about 275°K (~35.3°F). This seems like a reasonable estimate, and explains why your car window will frost at above 32°F.


Question 2: Why doesn’t the other side of the car frost over? 


So to answer question two: why didn’t the window on the side of my house ice over? The answer is simple: those windows didn’t radiate directly out to space. Their view factor to the adjacent house was too high, and therefore we had significantly less radiative heat loss (the house was actually radiating its heat to the car as well since they are close). The neighbors house, on the other hand, was too far away to provide the same effect (as it had a lower view factor). 

In the case of the smaller view factor to space (in the limit of zero), the window will not freeze until the ambient temperature reaches freezing (in reality, it will have to be below freezing to cool the window). This is why it’s much more difficult for a car to frost when sitting in a garage or under a car port.

Interestingly, previous questions have been asked before:


References:


First Post

First Post

Hey all, this is my first post. The purpose for this blog is to serve as an outlet for my scientific interests, and to document some of my thoughts on a variety of subjects. An engineer by training, I plan on focusing on quantitative calculations and analyses of things of little importance. I’ll apply my skills in statistics, programming, data analysis, electronics and instrumentation, etc. to anything and everything! 

I thought that I would share a bit about myself and my scientific background.

I’m a PhD, chemical engineering, currently working in R&D for the oil and gas industry. 

Quickly, I’ll detail a bit about my research from my PhD. I studied thermoelectric materials with Jeff Snyder (who recently transferred to a professor position at Northwestern University). My PhD focused on improving thermoelectric materials, which convert waste heat into electricity. These solid-state devices perform these conversions with no moving parts, and provide reliable transformation for decades at a time. As a result, these materials are often used in conjunction with nuclear power sources for space missions, basically creating a nuclear battery (known as a radioisotope thermoelectric generator, RTG).

Looking forward to it!
Zach