Solar Farm Calculator

During my final year of electrical engineering I opted to take a sustainable energy paper in order to get out of having to take a brutal computer hardware paper. For this paper we were required to take a real world site and design a sustainable energy system based on that site.

After a few false starts with sites that turned out to not have much opportunity for improvement, time was running out for our team to complete our design! My two team members had experience in solar systems and during our discussions I gathered that most solar installations followed a very similar architecture (see below)

Image

In light of this I proposed that instead of developing a specific design for a given site, why not take all the parameters from a site and use them to develop a generic tool which would allow you to check if installing solar on a site was even feasible. Not only did this solve the requirements for the paper but it also would help others get past the annoying stage we kept hitting where after a significant amount of time had been invested the site turned out to be a poor candidate for a sustainable upgrade.

The result of all this was the Solar Farm Calculator, an open source solar simulation tool written in Python. The tool takes parameters about a site and a given time frame, then runs a simulation to calculate the expected power output of the site and the related financials.

Image

The calculator takes a latitude and longitude for a site, and uses the Google Maps Reverse GeoCoding API to find out where that location actually is. Then using PySolar the program is able to simulate the solar energy the site receives across the given timeframe. This is coupled with a bunch of solar models to calculate the energy generated at 20 minute intervals across a day, which is then averaged down to a one day resolution. Using the location we can also access average temperature data from the World Bank Climate Data API to figure out how much power we’re losing through the cables, which is altered by ambient temperature.

Taking all this with a bunch of other losses from stuff like inverters and transformers we can then figure out how much power the site is generating per day, and given a price that we can sell the power for we can then figure out how much money the solar farm generates in a day.

To keep things generic we used the Open Exchange Rates API to gather currency information. This allows all the components to be specified in their own currency, and the factored in when calculating the financial results. To make this easier I ended up writing a little module in Python called PyExchangeRates to handle all the exchange rates stuff and offline caching.

The financials even factor in the depreciation of the equipment and the interest on the loan needed to start the solar farm. After running a simulation the results end up looking like this:

Image

The calculator can be downloaded as a pre-built binary for Windows and Mac OSX from SourceForge, and as always the source is available on GitHub if you want to contribute.

Special thanks to Darren O’Neill and Jarrad Raumati who worked on this project with me 0 specifically all the nasty power flow analysis and excellent late night banter as the assignment deadline crept up.

Using Open Exchange Rates with Python

I recently found myself in need of the ability to work with multiple currencies within Python and came across Open Exchange Rates – a JSON feed with multiple currencies updated hourly. Best of all there is a free plan which allows you to hit the API up to 1,000 times a month! For my purposes hourly rates were not needed – daily rates were fine and should be for most commerce applications where the rates are only being used to estimate a price.

Unfortunately as of now there is no official Python wrapper to get rates from the API, however as they are delivered in JSON they are simple enough to grab and decode. I wrote a little wrapper, PyExchangeRates, which simplifies access to different currencies and allows you to work with money of different currencies just like you would with regular numbers in Python.

Here’s a little example of how the module works. Firstly the module is imported and an ‘Exchange’ is created using your API key from Open Exchange Rates. This will download the latest rates and save them to a local file. Next time the module is loaded, if the file can be found the rates will be loaded from the local version. If the local version is older than one day old and there is an internet connection is available, the rates will be updated automatically, however the old rates can be used if there isn’t any internet connection available. This saves you from overrunning your free limit of API hits.

import PyExchangeRates

# Create an 'Exchange' object, this holds all the information about  the currencies and exchange rates
# Get a free API key from https://openexchangerates.org/signup/free

exchange = PyExchangeRates.Exchange('YOUR API KEY HERE')         

Now the exchange is created we can withdraw some currencies. There are over 100 currencies available, all accessible via their standard three letter identifier – the full list is available here.

# Withdraw a few different currencies from the exchange
a = exchange.withdraw(1000, 'USD')
b = exchange.withdraw(1000, 'EUR')

Now that we have a few different currencies, we can play with them like they are regular numbers in Python. The currencies need not be the same to be added together etc but the result will always be in USD for consistency.

# Money can be added together, the result will be in USD
print a + b
2352.363797 USD

# Money can be subtracted...
print a - b
-352.363797 USD

# Multiplied...
print a * b
1352363.796680 USD

# Scaled up...
print a * 2
2000.000000 USD

# and divided by a constant
print b / 2
500.000000 USD

Now that we have a few different currencies, we can play with them like they are regular numbers in Python. The currencies need not be the same to be added together etc but the result will always be in USD for consistency. No need to worry, money can be converted from one currency to another with one li

# Money can also be converted to other currencies 
print a.convert('AUD')
1061.079000 AUD

Feel free to fork the project on Github if you can think of any improvements, happy coding!

Getting Started with LaTeX

I see people constantly frustrated with MS Word, especially with bigger more involved documents. The good news its that there is a better way!

LaTeX is a program used to make documents using code. This lets you worry about what your writing instead of how it looks, plus you get the added bonus of awesome automatic citations, cross-referencing and table of contents (just to name a few).

If it sounds a little hard don’t panic! Once you see how easy it is and how good your documents look you’ll wonder how you lived without it.

I’ve created a little tutorial report template which covers a lot of the really common things you’ll end up using in LaTeX with plenty of comments to help explain whats going on. You can download it here from my GitHub.

The best bit is that you don’t even need to worry about installing anything! Sign up for an account with ShareLaTeX here for free and upload the .zip from GitHub as your first project.

Enjoy!