Eppy – EnergyPlus scripting with Python

It’s a long time since there was any new content here, but this is fantastic and well worth a post.

Having spent more hours than I care to imagine wading through EnergyPlus IDF files and writing custom Python scripts to do specific tasks, the work that has gone into writing Eppy is an absolute godsend at this stage of my EngD. Little tweaks to IDF files that last week took half an hour to complete, today took five minutes. And that’s including looking how to use Eppy as I went along!

From the project’s tutorial page:

Eppy is a scripting language for E+ idf files, and E+ output files. Eppy is written in the programming language Python. As a result it takes full advantage of the rich data structure and idioms that are avaliable in python. You can programmatically navigate, search, and modify E+ idf files using eppy. The power of using a scripting language allows you to do the following:

  • Make a large number of changes in an idf file with a few lines of eppy code.
  • Use conditions and filters when making changes to an idf file
  • Make changes to multiple idf files.
  • Read data from the output files of a E+ simulation run.
  • Based to the results of a E+ simulation run, generate the input file for the next simulation run.
  • So what does this matter? Here are some of the things you can do with eppy:

  • Change construction for all north facing walls.
  • Change the glass type for all windows larger than 2 square meters.
  • Change the number of people in all the interior zones.
  • Change the lighting power in all south facing zones.
  • Change the efficiency and fan power of all rooftop units.
  • Find the energy use of all the models in a folder (or of models that were run after a certain date)
  • If a model is using more energy than expected, keep increasing the R-value of the roof until you get to the expected energy use.
  • That’s certainly got me excited. If it has you worked up too, then go check it out.

    Quickly transfer your search to Google Scholar

    This is one for the academics and researchers out there. It’s a solution to a minor annoyance that I find while searching as part of my EngD research.

    The problem is that as Google became more populist and less focused on their roots in research and academia they dropped one of the handy links to specialised search areas like Scholar. That makes it a little less smooth to go from a search on the main Google Search page to a search on Google Scholar. This post gives you a bookmarklet to take your search straight to Scholar. It cuts down the keystrokes, mouse-clicks, and/or re-typing required navigate to Scholar and re-enter the query. Now you can do it in just one click.

    I’ve also added Bing, Yahoo, Baidu and Yandex – and for the secretive, Duck Duck Go. If there are any others you’d like to see added, please let me know in the comments.

    The human-friendly code is below, but you can to get the bookmarklet you can just drag this GoScholar link to your bookmark bar.

    WiFi geolocation in Python

    I came across a service called Wigle recently and since so many of you who come here are interested in geolocation tools and software I thought I’d pass this little Python code snippet along.

    It takes WiFi MAC addresses and looks up the latitude and longitude from a collection of 100,000,000 known networks that have been submitted. It’s essentially an open version of what Google Maps do to improve the accuracy of your GPS on Android.

    You can use it to look up your own MAC address, or you can pass in a MAC address you want to locate.

    To use it you need to sign up with wigle.net, and make a note of your username and password.

    Then to set up the agent call: mac_locater = WigleAgent(, )

    To look up the system MAC address use: print mac_locater.get_lat_lng()

    And if you want to look up a specific MAC address use: print mac_locater.get_lat_lng('0A:2C:EF:3D:25:1B')

    Let me know in the comments if you’d like to see an Excel VBA version of this.

    DuckDuckGo, !bang, and javascript bookmarklets

    Recently I’ve become something of a fan of Duck Duck Go, the anonymous search engine that doesn’t log all your searches. As big a fan as I am of Google’s products, they don’t need to know everything! I like DuckDuckGo not just because of the anonymity though – it also comes up with some really great answers. And as well as being it’s own thing, it also lets you link through to other search engines using “!bang” operators.

    A few examples:

    !g takes you to Google search
    !b takes you to Google search
    !gi takes you to Google Images
    !xls filters the result to .xls files
    !sx searches Stack Exchange
    !python searches the Python docs

    There’s a full list of the options on their site.

    It’s actually seems a cleaner way of doing things than Google’s filetype:xls, site:stackexchange.com, etc. Though I can also see the potential for overlap between !bang operators.

    Sadly, I didn’t know about the !bang categories earlier today when certain things were starting to bug me about having DuckDuckGo as my default search in Chrome. To solve the occasional problem without giving up the benefits of having DuckDuckGo as my default I decided to put together this quick javascript bookmarklet to take the query from the URL and pass it on to Google.

    var url=window.location.href;
    var query=url.split("=")[1];
    var google_link = "https://www.google.com/#q="+query;
    this.location.href = google_link;

    So should you decide that typing is too much like hard work, you can add the bookmarklet to your browser by dragging this link -DDG to Google- to your bookmarks bar. To use it, whenever you see that DuckDuckGo doesn’t have the answer you want, just click the bookmarklet and you’ll be spirited away to the land of Google.

    Convert HOBO U12 data logger dates to Excel serial dates

    The data loggers which I use when doing building performance evaluations are great (Onset HOBO U12-012), but they have one little quirk that makes working with the data really irritating – dates come out in a variety of formats when imported into Excel.

    It seems like it’s an actually an Excel problem. The data in the CSV file exported from the HoboWare software are stored in one format – 07/02/12 06:00:00 PM – but the data in Excel are sometimes translated into Excel serial dates (which is what we want) and sometimes remain in this Hobo format.

    There may be a quicker way of handling this foible, but (as ever) my first thought was to throw some VBA at it. Here’s the code for a UDF which will knock that data into shape.

    As ever, hope this helps someone else out.

    Visualising the wind

    You can’t see the wind, but just like other intangible things you can visualise it using charts. This post introduces you to a couple of ways of visualising the wind resource for a particular location. It’s an important early step in deciding whether or not a wind turbine is a good idea.

    Wind rose charts

    Do you have a home weather station and you’d like to interpret the outputs? Are you writing a renewable energy report and want to add a graphic to represent the wind resource? A structural report and you’d like to visualise the wind loading?
    Then you might just need a wind rose.


    Wind speeds chart

    And while you’re about it, why not add in a chart of wind speeds. This is sometimes called a Weibull chart because wind speeds tend to follow a Weibull distribution.


    Knowing where the wind comes from and how fast it is can tell you a lot about whether the site is suitable for a wind turbine. The faster the average wind speed the better return you’ll generate. A common rule of thumb is that if the average wind speed is less than 5 meters per second then you won’t get much benefit from a wind turbine.

    This post will take you through creating charts like these.

    1: Getting your wind data

    Obviously the most important part of creating your wind speed graphic is the data. How you get hold of this will vary depending on what you’re using it for. These are a few typical places you might find wind speed data to use:

    Weather stations

    All over the world weather stations are set up recording every passing gust of wind, floating cloud, drop of rain and ray of sunshine. You can download data from thousands of Weather Underground stations around the world using our Weather Access web form.

    Energy modelling weather files

    You can often extract the data you need from the weather files used by building simulation engineers. These aren’t as well distributed across the world as weather stations, but they do represent a typical year rather than just a year chosen random so are likely to give a more accurate idea of wind conditions than a weather station. You can find your nearest weather files using the Weather File Finder tool from this site.

    Your own weather station

    If you have your own personal weather station or anemometer then you will probably have a ready source of data. If not, you can get hold of one, through one of the links at Weather Underground, or through Better Generation who produce the Power Predictor which is specifically designed to assess renewable energy potential.

    2: Download and open the wind chart creator

    This is an easy step. The download link is here. Just save the file to your computer, unzip the zip file and open it up in Excel.

    3: Import the wind data

    This step depends on the source of your data.
    If it’s from our Weather Access page then you will probably have downloaded it in two six-month chunks. There’s a button on the front page of the wind charts maker to import them for you.

    If it’s from an energy simulation weather file then the process may be a bit more involved. We’ll work towards making a simple import button like we have for Weather Access/Weather Underground data but for now you’ll probably have to wrangle the data yourself in Excel and paste it into the Windspeed m/sec column.

    If it’s from your own weather station then the simplest route might be to join the Weather Underground network and import it from there, otherwise again it’s a case of formatting the data yourself in Excel and pasting it into the Wind Charts tool.

    4: Check your charts

    Your charts should now be ready in the Charts tab of the workbook. Just copy and paste them into your document and away you go!

    This is a brand new tool so please do give us your feedback, either by email or in the comments here.

    For lots more information on wind energy, wind turbines, and calculating the return you can expect in your location, Small Scale Wind Power Generation: A Practical Guide is available now!

    Regional settings in Excel – research

    Passing on a request from a couple of researchers trying to collect a comprehensive list of Excel versions and regional settings (things like decimal separators, types of brackets, etc.). If you have a couple of minutes spare and use Excel, head over to their site and download their workbook (the link is a bit awkward to find so I’ve linked it here too). When you click the button it writes the regional settings onto the worksheet then you can then save and email it back to them.

    There’s a load of other weird and wonderful things knocking around on the site. Have a look in the Wet Bread section. I particularly like the look of Pong in Excel!

    Building Energy Performance Simulation Q&A site

    Stack Exchange Q&A site proposal: Building Performance Simulation & Analysis

    If there’s one single site on the internet that I couldn’t live without (perhaps with the exception of Google), it would be StackOverflow from StackExchange. It’s an absolute life-saver for programmers, and as a fairly recent convert to programming, I struggle to think what it must have been like in the days before it existed. It’s on a par with how people ever found information before Google.

    The amount it increases a lone coder’s productivity is just staggering.

    So when I see that there is a suggestion to create a StackExchange site for building energy performance simulation I can barely control my excitement. A place where researchers can share best practice, iron out little niggles in their models, show prospective employers that they know their stuff [1], and all the other good things that StackExchange brings to the coding community.

    Apologies for the evangelising but this is a really great opportunity to make a difference to researchers’ and engineers’ day-to-day lives. Please do head on over and get involved. You can help move the fledgling site out of “Area 51″ and on to the next stage of development before it can become a fully-developed StackExchange site.

    Thanks to Clayton Miller at OpenRevit for the heads-up.

    [1] Via the reputation system. Here’s my profile on StackOverflow. I look forward to adding building energy performance simulation to this badge.

    profile for Jamie Bull on Stack Exchange, a network of free, community-driven Q&A sites

    Weather data from Weather Underground

    Go straight to the web form.

    If you want to know how to design your building you to need to know what the local weather is like. If you want to understand how your building is performing you need to know what weather it was coping with. If you want to install renewable energy – solar panels, wind turbines – you need to know what kind of weather conditions you’ll be able to harness. Weather Underground is a great source of free weather data, aggregating a multitude of independent weather stations all around the world.

    I first needed to pull some data from Weather Underground after I found out that the weather station on a university campus down in Cornwall where I’m monitoring a building had been damaged during the construction of another building on the campus. And then I found out the same thing had happened to another building I’m monitoring down there. The problem was I needed months and months of data for two sites, but Weather Underground only seemed to serve up one day at a time. And so was born wunderscraper.py.

    You can do some pretty cool things with weather data. This one plots temperature against heating energy use.

    Temperature trace

    And this one plots the wind conditions for a location. Very useful if you’re considering installing a wind turbine. If you or someone you know are interested, Small-Scale Wind Power: A Practical Guide would make a great present – and it’s on offer this Christmas!

    Wind data

    After that as a bit of a challenge to improve my non-VBA coding, I thought it might be a nice idea to try and put together a proper web-based API to simplify things a bit [1]. If it gets too much traffic I’ll have to take it down, hobble it, or password protect it – so be gentle!. I don’t want to take real business away from the Wunderground people, but I don’t think there’ll be enough traffic to this site to really worry them.

    So, how does it work?

    It’s really a very simple API. There are three URL parameters, stationID, startdate and enddate. Basically you build your URL as follows:


    Give it a try.

    That downloads you a CSV file containing all the data between the two dates specified. For this example the file will be called ICORNWAL14_2012-10-09_2012-10-10.

    Since my site is currently hosted in the United States (if you’re looking for hosting, check out my affiliate link [2]), the resulting file comes back with temperatures in Farenheit, rainfall in inches, wind speeds in miles per hour, etc. by default. I’ll add a parameter to specify whether you want imperial/US or metric data in the future but this will do for now. For metric data just tick the checkbox option.

    As well as the API, I’ve also put together a web form that you can use to do the downloading if you’re not minded to use the API directly. It’s as easy as putting in the weather station ID which you can find from here, and the start and end date of the period you want.


    [1] I know, I know. They have a proper API. But in the words of a blog post I just read, “I don’t need no stinking API”, and I enjoyed the learning process.

    [2] Disclosure: Apparently iPage will pay me for referrals, but I’d recommend them anyway. My partner’s site, Another Voice Translations is also hosted through iPage on my recommendation and that was before I knew about the affiliate programme. They made making the transition from a WordPress blog to a self-hosted site really very simple, and adding the scripting that powers this API was also pretty easy. This site is independently owned and the opinions expressed here are my own.

    Times and time zones in Excel – now with added Google

    Max, a visitor here, recently left a comment asking about accessing the public transit travel time option in the Google Directions API. Up until then I hadn’t used it and assumed it worked the same as the walking and driving time options, but that turned out not to be the case.

    The key difference is that you have to supply a time parameter as well as the start and end location. This can either be a departure or an arrival time.

    The format required for the time parameter is seconds since midnight on 1/1/1970 (the start of the UNIX epoch), while Excel times are in days since midnight on 1/1/1900. This difference meant it seemed worth writing a function to do the conversions.

    So far so good. So what next?

    A day of coding an interface for Google’s experimental Time Zone API, that’s what. This is because I can’t assume that everyone’s in the UK – Max is interested in public transport in Singapore for example.

    The results are the following functions for your spreadsheeting delight. They’re also fine for VBA for Excel.

    =LOCALTIME(Location As String)
    Returns the current local time for a given location, including daylight saving

    =DST_OFFSET(Location As String)
    Returns any daylight saving time offset to the time at a given given location

    =UTC_OFFSET(Location As String)
    Returns the time difference between UCT and the time at a given given location

    =TIMEZONE_ID(Location As String)
    Returns the ID of the timezone for a given location

    =TIMEZONE(Location As String)
    Returns the name of the timezone for a given location

    These functions all ought to be pretty stable. They don’t cache results, obviously – since they’re to do with current time. But they do use recursion to keep extending a wait between repeated calls if you have reached Google’s soft limits for the API. These soft limits are where Google throttles the service if you appear to be accessing it too often in a short period of time. The module also includes a fallback to spot if you seem to have hit the hard limit for the day of 25,000 calls. In that case it will return the error message OVER_HARD_QUERY_LIMIT. If that happens then you need to go away for a while and try again the next day (or change your IP address if you’re feeling particularly sneaky).

    You can download a workbook here with all of these functions.

    This was all something of a distraction from the main purpose of figuring out how to access travel times for public transport. That’s the next task on the horizon in the ever-expanding set of Google API interfaces for Excel that I’m building up here. It’s actually pretty simple, it just needs tidying up so if that’s what you’re waiting for, keep checking back here over the next week or so.