Posts Tagged ‘program’

Increasing earthquakes?

Saturday, May 14th, 2011

Are earthquakes increasing in strength or frequency?

Just found myself in a debate where the opposition claims earthquakes is on the rise (judgement day, wrath of god, etc..), being a skeptic I of course needed evidence, and where better to get it than to analyse it for myself from raw data?

How many earthquakes are there?
I went to the United States Geological Survey for the raw data, they have a pretty big list of “selected earthquakes of general historic interest” (6.0+) earthquakes recorded (ordered by magnitude, strongest quake first)
http://earthquake.usgs.gov/earthquakes/world/historical_mag_big.php

I then made a little computer program to parse the text, and output it in csv format:
java program: Test.java
data text file: quakes.txt (program input)
csv result file: quakes.csv (program output)

The output from the data was opened in a spreadsheet for further analysis. There are 722 quakes in the input data file. I used the data from the period 1900 to 2010 in the statistics below (660 of the 722 total data entries).

The data in table form

6+ 7+ 8+
1900 9 5 1
1905 14 12 5
1910 14 9 1
1915 9 6 0
1920 10 8 3
1925 15 10 0
1930 20 13 4
1935 12 7 2
1940 16 15 4
1945 21 18 5
1950 21 11 3
1955 20 18 3
1960 12 10 3
1965 34 18 3
1970 21 13 2
1975 18 12 0
1980 15 4 0
1985 17 6 1
1990 17 11 1
1995 31 21 1
2000 110 50 5
2005 194 67 8

The first column is the date of the quakes, the next 3 are number of earthquakes with a magnitude of at least 6, 7 and 8 respectively.
Data is grouped into 5 years.. so the first row with year 1900, is data from 1900 to 1904, followed by 1905 to 1909, etc..

Graph
Earhquake frequency last 110 years

Click for larger version

Conclusion
This graph makes it look like earthquakes are running rampant, and you might have seen a very similar graph on the Internet (YouTube and other places), used by conspiracy cranks as an argument that earthquakes are increasing. But fortunately this graph is very misleading.

The data used to make it is complete rubbish, to quote the page they are collected from: “selected earthquakes of general historic interest”.. These quakes have been hand picked as the most interesting ones, and the data has a HUGE bias towards newer earthquakes, so you can’t make any meaningful statistics out of it (except if you are making statistics of which years the guy who compiled the data finds “interesting”).

Maybe we should try and remake the graphs using some good solid data..

== Real Data ==

A scientist at the USGS was kind enough to send me a datafile with all the 7.0+ earthquakes from 1900 to 2010 (all the registered quakes, not filtered in any way).

Making some graphs from those data yields results consistent with what the experts on earthquakes are saying.. They are totally random and unpredictable, and there has been no increase of earthquakes since we started recording them:

Frequency of earthquakes from 1900 to 2010. Click for bigger version:
Earthquake frequency, 1900 to 2010

Distribution of earthquakes by month:
Earthquakes by month

Distribution of earthquakes by day of month, (day 31 omitted for obvious reasons):
Earthquakes by day of  month

Distribution of earthquakes by hour of day:
Earthquakes by hour of day

Trekwar Fog Of War

Sunday, October 3rd, 2010

It’s been too long since I got any programming done on my Star Trek game Trekwar, but today I managed to implement animation support on the main map, as well as get the sensor system and fog of war working (still needs a bit of tweaking):

I’ve gotten a new job, and been working on another paying project as well (Comicon does not pay for itself you know). But this other project is almost done, and then I should be able to get back to doing regular Trekwar updates.

I’ve also switched over to Toodledo for maintaining the list of features to be implemented, so hopefully you can see the issues under “0.4.0 (Alpha)” shrinking over the next few months :)

Coloring stuff

Wednesday, August 18th, 2010

Seeing that I got nothing better to do, I finished up a half done project of mine the other day.

I wrote this program mostly just because I was messing around with different pathing/filling algorithms and the Java PixelGrabber class.

The program lets you color different motives (animals, people, vehicles, etc..) and I’ve probably spent more time coloring dogs and bunnies than actual programming :)

Kolor with Kribsy

Download Kolor with Kribsy

Kribsy BTW is a poorly drawn imaginary bunny with self esteem issues and a knack for painting stuff :)

Video editing software

Thursday, November 26th, 2009

I enjoy the occasional editing and creation of videos. Recently I’ve been making a cinema commercial for the WSPA organization here in Trondheim (“Dyrebeskyttelsen”), but choosing the right video editing software is not trivial. For me it needed to have good tools for panning, zooming, cropping, masking and support lots of video tracks. Also the ability to work with HD, color correction, text effects, exporting to a sensible video format is a must. I tried out 4 different video editing software products and wrote a small review of them:

Sony Vegas
I really like Sony Vegas, but it’s limit of 4 video tracks is extremely annoying! I could get an unlimited number of tracks if I could afford 700$ for the Professional edition, however as my video editing is mostly on a hobby basis that’s not an option.

I think the 4 track limit is moronic, you just need to have 2 videos + some text and a picture and you’re maxed out.. There are ways around this by rendering your 4 tracks into a movie, then importing that movie in a new project but then it’s a nightmare to change stuff which you do all the time while editing. Great software, but way to expensive for 4+ tracks.

Pinnacle Studio Ultimate
So I decided to try another piece of software, Pinnacle studio ultimate, a hefty 1.9 gig download for the trial version. This proved to be the biggest disappointment since Star Trek 11. First of all the software is overly simplistic and lacks lots of features found in Vegas, it is cumbersome (does not allow for fast cross-fading video/audio and other neat functions like Vegas does). But the worst part.. It’s limited to 3 (THREE) video tracks? WTF? I could not uninstall it fast enough, and now my computer feels kinda dirty..

Adobe Premiere / Premiere Elements
Wow, it’s even more expensive than Sony Vegas Professional, 800$ And the fact that their webpage is a mess and I have to register for a trial means I won’t even bother testing it. However! at the time of writing this I see there is also a “Premiere Elements” that according to Wikipedia allows for unlimited tracks for 100$ so I had to give it a try.
1.2 gb download, but it went very fast, installing took a while and required a reboot.. The program itself was not very intuitive and the trial made a HUGE ugly watermark on all the videos AND all images in that video. It was also horribly slow, background rendering running for like a minute with just a background image in one track and a moving image on the other track. The program also locked up twice in the hour I was testing it.. Not impressed.

Cyberlink PowerDirector 8
Another more reasonably priced piece of software (70-100$) which is supposed to be able to handle 16 tracks, and I honestly can’t see myself having more than 16 objects visible at the same time any time soon, so I guess I’ll have to try this one as well. The trial version was on a slow server so took a long time to download the software despite it’s small 235 MB size.
I did however not get to try this software for reasons stated below.

Magix Movie Edit Pro
Unlike the other 3 products mentioned, I hadn’t heard of this one until recently. The trial version was only around 200 MB compared to Premiere and Pinnacle which were 1,2 and 1,9 GB. But the websites promise of unlimited tracks and a fairly low price of 90$ made me check this one out. Like powerDirector it was on a slow server, and took a while to download.
Fast simple install, and user interface is nice and simple. Using keyframes to do changes/motion/scaling, etc.. was very nicely done and easy to use, and the program was a pleasure to work with. My only complaint is that the preview of the video has very bad framerate (maybe it’s just because of my semi transparent video over an image), do detecting subtle changes in the video while editing could be extremely hard.

Conclusion
After being forced to abandon Sony Vegas I found that the best program for me (behaved most like Vegas, lots of functions and lots of tracks) was without a doubt Magix Movie Edit Pro, it’s a very nice piece of software which I will be buying before the trial is up. It’s stupid that when you buy the downloaded version you miss out on getting Vasco De Gama bundled with it, but that I can live without.

Using WeakReference to confirm/find memory leaks in Java

Friday, September 4th, 2009

I recently had a memory leak in my Trekwar game, and to find it (or at least confirm it’s there) I used the WeakReference object in Java..

This is how I proceeded in locating the memory leak, this method could easily be adapted to other programs.

Trekwar is turn based, so each turn the client downloads a Galaxy object from the server. There are many references to this objects inside action listeners, threads, etc..

WeakReference
To make a long story short, a weak reference is like a normal reference, except it will not prevent the object it points to from being garbage collected.

This means that is you  have a normal and a weak reference to object A, the weak reference will be null if you remove the “hard” reference.

1) In the client main executable (the class that holds the method that updates the map from the server). Import, declare and make a list of weak references

import java.lang.ref.WeakReference;
private ArrayList<WeakReference<Galaxy>> weakRefs;
 
weakRefs = new ArrayList<WeakReference<Galaxy>>();

2) Find the place in your program where a new object is being added, in my place this is the localGalaxy object. Create a weak reference to this object, and list all your weak references.

localGalaxy = (Galaxy) objStream.readObject();
weakRefs.add(new WeakReference(localGalaxy));
for(int i = 0; i < weakRefs.size(); i++) {
System.out.print("ref # " + i + " = ");
try {
Galaxy testG = (Galaxy)weakRefs.get(i).get();
System.out.println(testG + ", tick = " + testG.currentTick);
}
catch(NullPointerException npe) {
System.out.println("null");
}
}

And you’re done!

Now when you run the program, you should see something like this each time the method is called

ref # 0 = org.aakretech.trekwar2.common.Galaxy@11ed166, tick = 37
ref # 1 = org.aakretech.trekwar2.common.Galaxy@9801f4, tick = 37
ref # 2 = org.aakretech.trekwar2.common.Galaxy@1c5d81c, tick = 38
ref # 3 = org.aakretech.trekwar2.common.Galaxy@101f8f4, tick = 39
ref # 4 = org.aakretech.trekwar2.common.Galaxy@1ed1e7e, tick = 40
ref # 5 = org.aakretech.trekwar2.common.Galaxy@e0a7ea, tick = 41

Unless you want to wait until your GC decides it’s time to go, use a tool like VisualVM to force the Garbage Collector to run.

After the GC has run, the output should look like this:

ref # 0 = null
ref # 1 = null
ref # 2 = null
ref # 3 = null
ref # 4 = null
ref # 5 = null
ref # 6 = org.aakretech.trekwar2.common.Galaxy@2b3c91, tick = 42

Now, this means that the object IS being garbage collected, and there is no memory leak.. If you run this and the object you are monitoring (in this example the localGalaxy object) is not GC’ed because of stray references, you can tell because none of the references will point to null.

2 IRL achievements unlocked

Friday, January 16th, 2009

Today I finished a program at work, and as a result I got two achievements:

memorycheap

toographic