Monday, October 3, 2011

Tornadoes in South Africa

Recently I had to estimate the probability of a tornado damaging a school in South Africa. The issue was made all the more topical by the appearance of two destructive tornadoes on 2 October. The one occurred in Duduza in the east rand and the other half way across the country in Ficksburg.  Was this a freak incident or are tornadoes a greater danger than we suppose? Drawing on a study by Milford and Goliger 1997 it would appear that approximately 15 destructive (greater than force F0) tornadoes occur each year on average.

The graphic below shows the Milford and Goliger's estimates of the likelihood a tornado occurs (in a given year) in any 1km square area of the country. The likelihood ranges from an effective 0 in the Western and Northern Cape, through one in 100 000 in the Eastern Cape and Free State (including Ficksburg). The likelihood increases to one in 10 000 in parts of Gauteng and the KwaZulu Natal midlands (including Duduza).


The vast majority of Tornadoes  go unreported as they occur in the sparsely populated areas - like large tracts of the Eastern Cape and Free State. Given that only about 15 destructive tornadoes occur each year  the occurrence of two tornadoes in populated areas on the same day would be highly unusual. However there is some doubt as to whether  the two could be classified as F1 or higher. F0 tornadoes are unlikely to damage permanent structures. Usually the  damage associated with F0 tornadoes are the result of peripheral damage - like tree branches falling onto houses. Unfortunately if a F0 tornado is able to topple an old tree or break  branches off they are more than likely to be able to level shacks in Duduza or force poorly built structures to collapse.

The two incidents may thus say more about the quality of housing than they do about the prevalence of tornadoes.

Saturday, October 1, 2011

Service delivery protests: a new trend?

In early September two violent "service delivery" protests took place in Gauteng. The first was in Thembalihle informal settlement outside Lenasia, the second was in Tembisa on the east Rand. Although media coverage treated the two protests as similar, dubbing them "service protests", they have very different origins and profoundly different implications for the political future of the province.

Thembalihle

The Thembalihle protests were the latest resurgence of a dispute that started at least two decades ago. This is an informal housing  settlement located adjacent to Lenasia. However the settlement is located on land unsuited for habitation or development. Much of the ground in the region is dolomitic and prone to developing sinkholes which pose an ongoing threat to life and property. However sinkholes occur infrequently and thus do not appear, at least to Thembalihle residents, to present an imminent danger. Subsequently when Thembalihle residents  contrast their service levels and the level of investment in infrastructure to that of their middle class Lenasia neighbours they feel aggrieved. It is these grievance that are at the root case of the periodic protests.

The Johannesburg Metro Council, which is responsible for failing to prevent the repeated resettlement of the area now seeks, once again, to relocate the residents to geologically stable land about 10km away. As the the proposed resettlement area is far from shops, amenities, employment opportunities and the social connections offered by Lenasia few Thembalihle residents are happy to be resettled. Unfortunately the geological conditions preclude significant investment in the Thembalihle and it is improbable that grievances about service levels and investment levels will be addressed. The capital investment required to assuage grievances can well be considered as wasted investment or, even worse, a means of encouraging the settlement on unstable land.

Thembalihle residents are thus faced with the option of relocating or to continue occupying the unstable ground. If the council does make a serious attempt to relocate residents a breakdown in the relationships between council and residents may ensue. If residents wish to remain in the area in the face of such a resettlement drive they will possible make the area a no-go zone as far as the council is concerned.

However residents creating a no-go area for the council and, possibly,  rendering the area ungovernable is not he worst case scenario being faced. The latter is represented by accelerated sinkhole activity. Although the informal settlement has been geographically stable for some time the  decline of  mining activity in the larger region has resulted in a rapidly rising water table. Moreover the water now entering the dolomitic deposits is highly acidic - it is the infamous "acid mine water" about which several  apocalyptic  predictions centre. These two factors (the rising water table and its acidity) promise a marked increase in sinkhole activity - and there is little doubt that Thembalihle residents now face increased risks.

The protests in Thembalihle represent one heritage of poor urban management as Johannesburg Metro Council has never demonstrated the political will to ensure that the area is not used for housing. Resettlements that took place in the past were all accompanied by an immediate resettlement of the land. The failure of adequate urban land management gives rise to the current impasse as grievances cannot be addressed (at least not safely).

Fortunately the disputes in Thembalihle are sure to remain localized, however the same can not be said of the protests at Tembisa.

Tembisa

Tembisa  represents a dramatically different situation and has far more wide ranging implications.  In Tembisa protests were sparked less by the absence of services than by the poor quality of the services and the cost of those services. Residents  cited many grievances but most prominent among their grievances was the rapidly rising cost of electricity. This was blamed, variously, on "overcharging" by the council and the installation of pre-paid meters. The impact of electricity prices and suspicions about Ekhuruleni metro Councils efficacy was most vividly expressed by calls that ESKOM be made the service electricity provider.

This latter demand seems to have been particularly misguided. City councils merely resell electricity bought in bulk from ESKOM. The prices of many services provided by the state (electricity, gas, water, road tolls, license fees) are determined administratively i.e. they are determined by the interaction of supply and demand in a competitive setting but on consideration of other issues. The other considerations include the need to provide free basic services, redress of inequities in service levels, affordability and the need to recoup costs. In other words prices are set by political consideration rather than by markets. Be this as it may the costs of services still have to be recouped from either the fiscus or from other taxes or charges.

In recent years administrative charges have been rising more rapidly than market-related prices. In March this year Business Day gave the example:

"... (in the) last month administered prices rose twice as much as general services and three times as much as the average price of consumer goods".

As ESKOM seeks to fund massive new capital projects increases in the price of electricity has been particularly pronounced. These price increase of approximately 25% each year for four years in a row is not exclusively due to capitalisation costs. They have been prompted by the need to (temporarily at least) reduce electrify consumption and pay very lucrative salaries in the parastatal. Recent reports indicate that the average salary in ESKOM  is well in excess of R500 000 per annum. This is more than ten times the value of South Africa' per capita GDP (which, in turn, is higher than average wages).  ESKOM is not alone in presenting massive wage bills. In the three years leading to 2010 the total municipal wage bill rose by 54%. Over this period the total number of municipal employees rose by only 5% indicating that average remuneration in municipalities is rising rapidly . All these costs - capitalisation costs, wage bills etc. have to recouped from consumers - hence the pressure of administered prices. These factors ensure that the cost of municipal services like electricity will continue to increase at above the rate of inflation - irrespective of whether the services are provided by the council or another service provider (like ESKOM).

The Tembisa protests indicate that those setting administrative prices have misread the willingness of township residents to bear the ever increasing remuneration and other costs.

Ultimately this is a political misjudgement by the elected representatives and by those appointed to oversee the provision of essential services. If the political representatives have indeed misread the willingness of consumers to absorb ever-increasing costs, as the Tembisa protests imply, then the latest protests  may just be the first of many against the price of services.  Perhaps we have entered a phase where an increasing proportion of public protests will centre not on the failure to deliver services but on the costs of those services.


What unites the Tembisa and Themblihle protests is the underlying lack of faith residents have in the metropolitan councils. In Thembalihle residents distrust the argument about the impact of dolomite as they witness better services and  infrastructure across the road in Lenasia. Moreover they have not recently been affected by sinkholes. Much of the anger in Tembisa has been brought on by the belief that the council is overcharging them for electricity (hence he call for ESKOM to take over). Ultimately the combination of misjudgement by those setting prices and reservations about the integrity of elected representatives suggest that the issue of public order policing will become even more prominent in the years to come.

Sunday, August 29, 2010

SA police, the media and defeating the ends of justice

Media attention has recently been focussed on proposals to exert greater control over it. The proposals include a “media tribunal” and the new Protection of Information bill. In contrast to this concern government agents have defended the proposals as necessary for state security and fairness . Chief spokesman Themba Maseko recently declared that "there is no intention or plan to muzzle the media in any shape or form”, However with attention directed on the explicit attempts to control the “fourth estate” media representative have seemingly been blind to more in insidious moves by the state.

These moves include using existing legislation to achieve the effects envisaged, for example, by the new Protection of Information bill. This bill seeks to criminalise journalists for being in possession of “sensitive” documents that may have been leaked to them. However the recent arrest of Sunday Times journalist Mzilikazi Wa Afrika for, it seems, being in possession of a “fraudulent letter of resignation” suggests that the SA Police Force is already treating the mere possession of sensitive documents as criminal. The initial charges against Afrika were “fraud” and “defeating the ends of justice”.

Although the charge of “defeating the ends of justice” was later dropped in favour of one of “utterance” the fact that this charge was used at all is of concern. “Defeating the ends of justice” is a somewhat vague charge relating to efforts to subvert the judicial process by intimidating witnesses or destroying evidence. If media coverage is anything to go by until recently those charged with the offence were invariably police staff. Examples include Jackie Selebi, the station commissioner who tampered with the drunk driving evidence against Tony Yengeni, former crime intelligence boss Mulangi Mphego and the then head of the Scorpions Gerrie Nel. By contrast it is difficult to find, prior to the appointment of Bheki Cele, reference to the charge being lodged against people outside of the criminal justice system.

In a dramatic departure from this tradition this law is increasingly being used against journalists. In the past two months at least two journalists have been arrested and brought to court for “defeating the ends of justice”. The most recent instance is that of Afrika. In the previous month english journalist Simon Wright faced the charge. The charges against Wright stem from his cloistering of soccer fan Pavlos Joseph in a hotel. During the world cup Josephs entered the English football teams' dressing room to reprimand them for their poor performance. Wright, in his enthusiasm for securing an exclusive interview, booked Josephs into a hotel under a false name. This gave rise to the accusation of him attempting thwart justice from prevailing in Josephs' case. In these instances the veracity the “defeating the ends of justice” charge was justified largely by the vagueness of the allegation. The severity of the charge was aggravated by SAPS intimating, in both instances, that the offences constituted part of a wider conspiracy. The alleged conspiracy, coupled to the vagueness of the charge, invited wild speculation as to what the actual misdeed was.

In court the merits of the “defeating the ends of justice” charges were illustrated by the rapidity with which they were dismissed. The dropping of this charge reflect, on the one hand, the historical difficulty in securing such a conviciton – as was demonstrated in the cases against Selebi , Nel and Mphego. On the other hand the message to journalists remains clear - the police are increasingly prepared to use this charge against them precisely because of the opportunities afforded by its vagueness.

The common theme in both these cases is that the journalists had recently embarrassed the SAPS. Afrika had just accused police head Beki Cele of signing a R500-million lease without observing the required procedures. Wright had pointed out the ease with which a fan could wander into a key area secured by the SAPS. Could it be that the arrests were to punish this behaviour rather than any overt criminal act?

In a short period “defeating the ends of justice” has come to be associated less with tampering with evidence or bribing witnesses and more with journalists publishing the true face of the police.

The extent to which the police hereby undermine the fourth estate is the extent to which they may not need the full measure of the Protection of Information bill. What their action does show is that, assurance that "there is no intention or plan to muzzle the media in any shape or form” aside, the state seeks to cow the media irrespective of whether or not the Protection of Information bill is passed in its current form. Those who view the proponents of the protection of information bill as naïve but well intentioned people operating a bit out of their depth should wake up. In this one regard the writing (on the wall) is getting clearer.


WOL (wake-on-lan) over the Internet

You learn about internet sites that allow you to use wake-on-lan (WOL) over the Internet and have a wake-on-lan (WOL) enabled PC. You now reckon you can wake your home PC from a remote internet location. From that location you can then use SSH, telnet, or tightvnc to access your  PC subject, of course,  to the limitations of internet speed.  When you try this you will soon discover that it does not work.

Unfortunately WOL requires that at least part of a  LAN must be awake.  If you put your PC off it, to all intents and purposes, ceases to exist on the web. Under these circumstances the WOL-over-internet providers like www.depicus.com and www.wakeonlan.me will work for up to 30 minutes after you powered off. This is obviously not what is needed.

However your ADSL router is part of your home LAN and it remains on all the time. So to use WOL over the internet you need to set things up so that  your ADSL router can send a "magic packet" to  the PC. This magic packet will then wake the PC. To do this the following must happen.

1) Your motherboard and the relevant network card needs to support WOL.

2)  You must be able to "http" into your ADSL router from a remote location.

3) You must be able to administer remotely (in order to send the WOL packet)

 4) You must be able to tell the router what the IP and MAC addresses of the network card are.

4) Your router must be able to send a WOL "magic packet" to that address.


In detail:

1) is a no-brainer. Either your PC does WOL or it doesn't.  If it does use the BIOS setting to enable WOL. This usullay requires you pressing some key (usually DEL) before the computer boots.

2) The usual way of changing router settings is via your browser. For example, my Linksys WAG2000 requires that I go to http://192.168.1.1 and enter the username and password written on the underside of the router. However this address only works if the PC is linked directly to that router.

To be able to link to the router remotely (i.e. form elsewhere on the internet) you need to subscribe to a service like "DynDNS.com" or "no-ip.com". These two services are free and provide you with a domain name that you can use to http into your router from anywhere. After obtaining your address make the appropriate changes on your router and reboot it.

There are two changes that need to be made.

1) The router must be told that you are using a DNS system like DynDNS. On the Linksys this is under Setup - DDNS. This links your router to a fixed ip address like mine (maodonovxxx.yyy.zz).
2) The router must be enabled for remote adminstration. On the Linksys this is under Administration - Management - Remote Gateway Access. All you have to do is enable the facility and record the port number.

Once you have saved the settings and rebooted your router  you can access it via secure http. In my instance is go to

https://maodonovxxx.yyy.zz:8080

NOTE there is a "s" in the address above.

Remember to change your router password to something different from the default. If I had not done that  you could http into my router and change my settings.

3) To access the WOL network card from the router you have to be able to identify it by IP and Hardware address (MAC). On a linus (Debian) system you would (as superuser) run ifconfig. My system says for network card eth0:

eth0
Link encap:Ethernet  HWaddr 00:21:85:61:da:9e
inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0

inet6 addr: fe80::221:85ff:fe61:da9e/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:11415 errors:0 dropped:0 overruns:0 frame:0
TX packets:9971 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000
RX bytes:9922062 (9.4 MiB)  TX bytes:1663804 (1.5 MiB)
Interrupt:250 Base address:0x4000



(On Windows run ipconfig.)

Note your inet addr (the IP), Bcast (Broadcast),  HWadd (i.e. the MAC) and Mask.

If you are using a dynamic addressing system (DHCP) the IP address will change regularly and you will not know what IP address to enter. So use a static address  for the hardware card. On linux (Debian) systems you will do this by editing /etc/network/interfaces. On Windows you will presumably be able to change the settings by right clicking on the network card.

If you do not know what setting to use try those published after running ifconfig (*nix) or ipconfig (Windows). Remember to restart your network (Debian uses "/etc/init.d/networking restart")

 
4) Theoretically you could now http into your router from the internet and issue a wake-on-lan command to the IP and MAC address you just set. However chances are that your router has not provided any WOL facility. This is certainly the case for Cisco and Netgear. Fortunately the OpenSource community has provided the required software for many routers, This software is model specific so do not use software for another brand or model router.

Relevant sources are:
Netgear             http://dgteam.ilbello.com/
Linksys              http://sourceforge.net/projects/openwag200/
Other routers   http://openwrt.org or  http://google.com



The process of installing the software is one of downloading a zipped/ compressed file, uncompressing it and then updating the "firmware" on the router. Your router will already have  update facility. Although flashing your router is simple read the instructions (and warnings) provided. Although the upgrade preserves settings it does make sense to back them up to your hard drive first.


Once flashed and rebooted you can http into the router. You will now have a new menu item under which various new services are listed. On OpenWAG (used for the LinkSys WAG200) it is - "MySetup".

Negotiate your way to the WOL facility. On OPenWAG it is under:

MySetup - other -  Wake on LAN Interface.

Here you enter the MAC address (from ifconfig/ipconfig) and the IP address. This is the IP address of your LAN  and not the IP provided by no-ip or DynDNS.  In my case it is 192.168.1.4.

Press "save" and a magic packet is sent to the PC powering it on.

..... thats it

Sunday, June 20, 2010

Weighted mean: tapply

To obtain weighted means for categories of a dataframe use has to be made of
a) the tapply function and
b) the weighted.mean function.

The information required for the tapply component is:


"lll" -  a list of the rows to which the function must be applied
"rrr" - the categories over which the function must be aggregated
"function(i, x, w,)...." - the function to apply. In this instance the 'weighted mean'.

The info required for the weighted.mean component are 'x' (the values to be weighted) and 'w' (the weights).

The general form is:

tapply(seq(along=lll), rrr, function(i, x, w) weighted.mean(x[i], w[i]),x=lll, w=ttt)

An example of weighting incomes ("incval") by frequency counts ("worker_wgt") for each "tbvc" category is:


tapply(seq(along=incval),tbvc, function(i, x, w) {weighted.mean(incval[i], worker_wgt[i],na.rm=T)})

Obviously this is done after attaching the relevant dataframe.

Thursday, October 29, 2009

Extract variables from data frame by name

I had to combine a bunch of .csv files into a data frame. As the various files had no column names a side effect of the import were duplicate column names. A similar result could arise when using "cbind". As I was only interested in the eighth variable (called "V8" by default) I needed a way to extract all (and only) the V8's into a new data frame. Unfortunately the "V8"s were not at regular intervals. 

names(april2008) yields:

 [1] "station" "V7"      "V8"      "V4"      "V5"      "V6"      "V7"    
 [8] "V8"      "V5"      "V6"      "V7"      "V8"      "V6"      "V7"    
[15] "V8

I wanted to extract columns 3, 8, 12, 15.

This was achieved by using the "which" command. The initial data frame was called "april2008".

I used:

april2008[,which(names(april2008)=="V8"] -> newapril08

names(newapril08) yields:

[1] "V8"    "V8.1"  "V8.2"  "V8.3"

Monday, October 12, 2009

sorting a dataframe

To order selected variables in a dataframe you need to use the "order" and not the "sort" function. The easiest way to do this is to use the numerical (square bracket) notation system.

Specify the dataframe (lets call it "stations") and in the place where you would usually specify which rows to use place the command....

order(variable to order by).

So ..

station[order(station$V4),2:4]

will produce a data frame composed of the 2nd 3rd and 4th variables of the station dataset. However it will now be ordered by the variable called "V4".