Category Archives: Nerdy stuff

3 hour forecasts with openweathermap and python

This post is for people who wish to explore the 3 hour forecast features of openweathermap.org

I’ve kind of found the learning process fun so here is it is:

#Documentation is at https://pyowm.readthedocs.org/en/latest/pyowm.html
#github documentation is at https://github.com/csparpa/pyowm/wiki/Usage-examples

#retrieve weather data
forecaster = owm.three_hours_forecast(location_var)
forecast = forecaster.get_forecast()
weather_list = forecast.get_weathers()

#id for the location_name --- the registry doesn't seem to be working ūüė¶
#location_id = owm.city_id_registry().id_for(location_name)
#print(location_id)
#But we can get the location id by the following
fc_JSON=json.loads(forecast.to_JSON())
#print(fc_JSON['Location']['name'],str(fc_JSON['Location']['ID']))
location_name=fc_JSON['Location']['name']
location_id=str(fc_JSON['Location']['ID'])

#Don't forget to add time difference in when displaying dates and times!
strDate =(datetime.datetime.strptime(forecast.get_reception_time('iso'),"%Y-%m-%d %H:%M:%S+00") + datetime.timedelta(hours=10)).strftime("%Y-%m-%d %H:00")

Once you have called a list of weathers, then you can work you way through that list using a FOR LOOP. I personally find loading each weather to JSON makes it just a bit easier to manipulate, but there are other functions available through the pyown api that could be of use too:

#Set up the comparative vars
total_rain =0
temp_min = 999
temp_min_time='sometime'
temp_max_time='sometime'
temp_max = -999
hum_min = 999
hum_max = -999
hum_min_time='sometime'
hum_max_time='sometime'
cloud_min = 999
cloud_max = -999
cloud_min_time='sometime'
cloud_max_time='sometime'
for x in weather_list:
	#Dont forget to put the date and time calculations in your timezone!
	ref_date = datetime.datetime.strptime(x.get_reference_time('iso'),"%Y-%m-%d %H:%M:%S+00") + datetime.timedelta(hours=10)
	if (ref_date.strftime("%Y-%m-%d")==time.strftime("%Y-%m-%d")) :
		x_data = json.loads(x.to_JSON())
		#print(str(x_data['humidity']))
		#print(str(datetime.datetime.strptime(x.get_reference_time('iso').split( )[1],"%H:%M:%S+00")))
		#print(str(ref_date.strftime("%Y-%m-%d")) + ' - ' +  x_data['detailed_status'] + ' at ' + str(datetime.datetime.strptime(x.get_reference_time('iso').split( )[1],"%H:%M:%S+00").strftime("%I%p").lstrip('0')) + ' -- ' + str(x.get_temperature('celsius')['temp']) + 'C')
		#Record if it is a max or min temperature, humidity, cloud and the time it occurs
		if (x.get_temperature('celsius')['temp_min']<temp_min) : 			temp_min =  x.get_temperature('celsius')['temp_max'] 			temp_min_time = int(ref_date.strftime("%H")) #str(ref_date.strftime("%I%p")).lstrip('0').lower() 		if (x.get_temperature('celsius')['temp_max']>temp_max) :
			temp_max =  x.get_temperature('celsius')['temp_max']
			temp_max_time = int(ref_date.strftime("%H")) #  str(ref_date.strftime("%I%p")).lstrip('0').lower()
		if (x_data['humidity']<hum_min) : 			hum_min =  x_data['humidity'] 			hum_min_time = int(ref_date.strftime("%H")) #  str(ref_date.strftime("%I%p")).lstrip('0').lower() 		if (x_data['humidity']>hum_max) :
			hum_max =  x_data['humidity']
			hum_max_time = int(ref_date.strftime("%H")) #  str(ref_date.strftime("%I%p")).lstrip('0').lower()
		if (x_data['clouds']<cloud_min) : 			cloud_min =  x_data['clouds'] 			cloud_min_time = int(ref_date.strftime("%H")) #  str(ref_date.strftime("%I%p")).lstrip('0').lower() 		if (x_data['clouds']>cloud_max) :
			cloud_max =  x_data['clouds']
			cloud_max_time = int(ref_date.strftime("%H")) #  str(ref_date.strftime("%I%p")).lstrip('0').lower()
		if ('3h'in x_data['rain']) :
			#print(str(x_data['rain']['3h']) + 'mm')
			total_rain+=float(x_data['rain']['3h'])

I was particularly interested in the rainfall data. I’ll just point out that the rainfall data is only evident if there is rainfall predicted for that weather. The code to check that is as follows:

if ('3h'in x_data['rain']) :
	#print(str(x_data['rain']['3h']) + 'mm')
	total_rain+=float(x_data['rain']['3h'])

The output that a finished version of the above code produced is as follows:

Port Hacking today= temp 22.8C at 10am & 23.5C at 7pm, humidity 95% at 10am & 88% at 7pm, clouds 0% at 10am & 24% at 7pm; Atmospheric summary is {clear sky from 10am (22.76C) ; few clouds from 7pm (23.54C)}/ tomorrow= temp 29.5C at 1pm & 19.8C at 10pm, humidity 64% at 1pm & 100% at 7pm, clouds 0% at 7am & 100% at 10pm, total rain 18.24mm; Atmospheric summary is {few clouds from 1am (23.6C) ; clear sky from 4am (23.85C) ; few clouds from 10am (27.57C) ; light rain from 4pm (23.34C) 1.33mm; moderate rain from 7pm (21.59C) 16.91mm} … http://openweathermap.org/city/2152674

Advertisements

Getting weather forecasts via openweathermap and python

This is a nerdy post. So unless you’re interested in python programming and getting weather information then this post is *not* for you.

Well here we go! I’m going to assume that you have python installed on your computer (or raspberry pi).

Firstly, you will need to install pyowm package.  You can do this with the command:

pip install pyowm
or
sudo pip install powm (if you are using a rpi)

Secondly,  in your python code, make sure you import the correct bits and pieces:

import pyowm
import json

Thirdly, what I was interested in was sending an email/text which aggregated the current weather conditions and added what to expect three hours later to that message.

owm = pyowm.OWM('INSERT-YOUR-API-KEY')
#Documentation is at https://pyowm.readthedocs.org/en/latest/pyowm.html
#Get you api key by signing up at http://openweathermap.org

#establish time constant
in3hours = pyowm.timeutils.next_three_hours()

#Retreive daily forecast
forecast = owm.daily_forecast('Castle Hill,au')

#Retrieve forecast at location in 3 hours
latertoday = forecast.get_weather_at(in3hours)
decoded_later = json.loads(latertoday.to_JSON()) #its easier to load it into JSON and decode it!
detailed_status_later = decoded_later['detailed_status'] #detailed status in 3 hours

# Search for current weather
observation = owm.weather_at_place('Castle Hill,au')
#observation = owm.weather_at_coords(-33.73, 150.998)
w = observation.get_weather()
decoded_w = json.loads(w.to_JSON())
detailed_status = decoded_w['detailed_status']

#Create String to Print
strMsg = 'Castle Hill: ' + detailed_status.title() + ' (later expect ' + detailed_status_later.title() + ') from ' + str(w.get_temperature('celsius')['temp_min']) + 'C to ' + str(w.get_temperature('celsius')['temp_max']) + 'C, ' + str(decoded_w['humidity']) + '% humidity &amp;amp;amp; ' + str(decoded_w['clouds']) + '% cloud'
print(strMsg)

The output will look as follows:

Castle Hill: Broken Clouds (later expect Clear Sky) from 18.89C to 20.0C, 68% humidity & 75% cloud

It’s worth keeping in mind the documentation of pyowm and you can find that here

Should I buy and all-in-one or an integrated church management system?

IntegrateI thought I might write a couple of blogs to help churches get their heads around some of the issues and questions one should ask when choosing a church management solution.  I’m no expert but here are my credentials: In my years following university, I worked for two software companies.  Both were start-ups.  Both made significant headway into their industries and against their competition. One was an all-in-one solution and the other was a best-in-its-field single function solution. The former was eventually creamed by the competition; the latter is now in a strong position to dominate its’ part of the world-wide market.  In my last years before going into ministry, I was their systems integration consultant for the latter company.  Now, even though that is my experience, I will try to be fair.  So here goes …

There is no doubt that many churches struggle when choosing a church management software solution. Should it be an all-in-one solution, or should it be an integration of (sometimes existing) compatible functions?

The short answer is it depends on what the church needs. That sounds like a cop-out, but there is no substitute for understanding what a church is really trying to achieve and, hence, what tools are needed as a result. If a church is about making disciples for Christ then that should form the basis of choose the software that best meets current needs while allowing the greatest flexibility in the future.

This means that one church may choose an off-the-shelf, all-in-one solution.¬† Another church might build its software infrastructure by purchasing the best individual tools and linking them all together. Neither solution is a going to solve all problems or meet every requirement ‚Äď for each solution will require a compromise of some sort. Again, there is no ‚Äúright‚ÄĚ answer to which way a church should go!

At the very least, it is very important for churches to weigh the benefits of all-in-one versus integrated service software solutions.

  1. All-in-one.¬†An all-in-one package offers a quick, cost-effective solution. Working with a single vendor and software suite can provide significant savings, and the contractor does not need to worry about integrating your new system to existing systems ‚Äď ie no costly consultants are needed!¬† However, one of the significant drawbacks with this option is that although the solution is often a ‚Äújack of all trades‚ÄĚ, it is also not particularly good at anything.¬† For by being a fit-as-many-solutions-possible package, this may require your organisation to worked within its‚Äô generic quasi-flexible options.
  2. Integrated.¬†An integrated solution makes sense when a church is wiling to add specific functionality to an existing system – say a financial package. ¬†In many ways, if the church manages to combine the best-in-field systems then this could result in a better solution than an all-in-one platform.¬† However, the cost of integrating your solution with other functions will most likely be costly in both consulting fees and/or bridging services between your different functions ‚Äď having once worked in this area, this could double or triple (or quadruple) the initial cost of installation.

After selecting a member management software solution, churches often run into trouble with a laundry list of modifications they would like to make. Giving end users any special features they want will snowball your consulting costs. [And my experience is that the larger the vendor, the less likely they will respond to your feature requests. Also just remember that all vendors want to get large!]  I also find that churches with limited resources often miss opportunities to integrate the pieces that could dramatically increase efficiency (which in the long run will decrease your costs!)

It’s easy to spend time on integration without creating anything useful, just as it is easy to avoid integration and end up with something not particularly useful.

So what kind of solution should your church purchase?  Well here are a few questions that may help you decide:

  1. What’s the desired outcome? Make sure the required outcome is clear ahead of time, including what form and format the output will take, who is going to use it and what they plan to achieve with it. (Remember, you will probably never satisfy every requirement, so you will need to be willing to compromise somewhere). The church should identify these factors up front during the project scoping phase, making sure vital elements are included for any future solution.
  2. What’s the return on investment? In the end, any cost outlaid has to be justified. If integrated system pays for itself in six months, it’s probably worth it. If not, seriously think about what the church stands to gain. Or on the other hand, at the expense of some functionality, you may get a particular function that interests you in an all-in-one solution, but if you are only using that function 5% of the time, then is it worth it?
  3. Who can be trusted with this decision? Be wary of having only one person manage (and prioritise) the requirements and decision making in this area.  A small group of objective and qualified people who are invested in the outcome of what this tool will help the church accomplish is crucial.  All too often, the minister is left with this job and in many situations the minister may not be best suited to this task without some others helping normalise their thoughts and direction.

Automating our chicken coop (Introduction)

One of the fun things about holidays is tinkering around on projects that you never get around to normally during the year.¬† These last few years, I have had fun (and much frustration) tinkering around with Arduino.¬† The task for the Summer 2013 holidays was to automate our newly built chicken coop.¬† Whilst chickens actually need tending pretty much every day (to get their eggs and check water) wouldn’t it be good if your coop would regularly measure the humidity and air temperature and tweet you the feed levels?¬† Well I thought it might be good if it did, so I found some old parts and created a chicken coop bot!

The “proof of concept” bot has the following bill of materials:

  • Freetronics Etherten
  • Grove Base Board
  • Grove RTC
  • Grove Humidity and Temperature Sensor Pro
  • Parallax Ultrasonic Range finder

If you want your bot to tweet information then you will also need to get a https://thingspeak.com/ account and link it to your twitter account.

The great thing is that you can get code to get each of these components working.  However, I struggled to get them all working together at once.  Maybe it was part dodgy programming, part rushing and part quirkiness of arduino.

In the mean time, before my next post, why not get the components, follow the links to the respective component wikis to try out the code in order to familiarise you with how each actually works?

Surviving your smart phone

I’m writing this as a survivor of smart phone addiction. ¬†In days gone by, I could spend all day and all night playing with my phone. ¬†This was dreadful for my sleep patterns, my work patterns and my relationships! But, by the grace of God and after incessant pressure from my beloved wife to change, I have turned over a new leaf!

You can actually program your phone to do basic tasks¬†automatically¬†so that it becomes what it ought to be – a useful tool and not your digital overlord! The principles I’ve adopted are:

  1. Make the phone automatically invisible when it should be and
  2. Take the phone off the network when I should be invisible from the connected world.

I have a Samsung Galaxy Note, but I presume you could do this on your Android or iPhone too (I don’t have an iPhone so I can’t confirm it!). ¬†On my phone, I installed an app called Tasker. ¬†Tasker allows you to write triggers for events and states and locations on your phone. Here are the some profiles I’ve written (and I’ve posted the recipes so you can do it to your phone too!)

A. Night Flight Mode

This turns the phone to Flight Mode between 11pm and 5:50am each night.  Yes it is awesome because no one can email, call or text you in that time!

How to make a “Night Flight Mode” Profile:

  1. Select “New” Profile
    New -> Time -> From: 2300 To: 550
  2. Select “New Task”, then select the plus sign in the left bottom corner,
    Net -> Airplane Mode -> Set to “On”

This should turn the phone to Flight Mode during the hours you set. ¬†It should revert to non-Flightmode outside these hours. ¬†If your version of Tasker has a problem doing the latter, then put an “Exit Task” of turning flight mode off.

B. Automatic Mute Phone in Meetings

This¬†automatically¬†turns the phone to vibrate (or silent depending on what you want) during calendar event which mark you as “Busy”. ¬†There are stacks of examples of this one, such as on the Tasker Wiki. ¬†My tips for the stock example are:

  1. If you want the phone to “un-mute” when the event is over, you may need to add an “Exit Task” which toggles the Vibrate mode to “Off”.
  2. Be selective in which calendars that you wish to trigger off.  This means that not every even needs to mute your phone.  Instead, I only mute the phone during church and work meetings.

Tasker is a really useful tool to help get your Android smartphone working better for you.  I recommend that you go to their wiki for more recipe examples.

 

 

Rock Paper Scissor Spock Lizard

For all those who keep finding the inherent limitations of “Rock paper scissors”. All hail Sam Kass and thankyou to The Big Bang Theory.

Rock Paper Scissor Spock Lizard

For something completely nerdy

I finished an engineering degree at UNSW in 1996.  One of my big regrets over the past 15 years is not keeping up with my fascination with electronics Рfunnily enough it was one of my majors (such a waste of a uni education!)

Maybe it is pre-mid-life-crisis jitters, but that is all changing because¬†over the past few years I have started tinkering with microcontrollers again (I still have flashback nightmares to our transputer labs in 2nd year uni.) ¬†But anyway, the one’s I’ve been playing with are the arduino variety. ¬†Can I just say that electronics have sure come a long way since the old Dick Smith Funway kits of my youth and my kids will definitely be playing with stuff way cooler than I did as a kid!

Any my first real life project is to create a solar powered GPS datalogger.

Components are:

  • Seeduino Stalker v2.1
  • 2A Li-po battery
  • 0.5W solar cell
  • GPS Bee with enhance ucl antennae
  • Water proof enclosure (but it won’t really be if I drill holes in it to mount it to the bike)
  • 2gb MicroSD Card

I’m starting to ride with some guys from church next week. ¬†I’ll tell you how it goes!!!