Home > Uncategorized > A gWidgets GUI for climate data

A gWidgets GUI for climate data

If you haven’t worked with the gWidgets package it’s worth some time exploring it which is what I’ve been doing for a little paleo project I’ve been working on. After struggling with the few demos and tutorials I could find I went ahead and bought the book: Programming Graphical User Interfaces in R. Luckily the book was a little better than the tutorials which just scratch the surface. GUI programming, in my mind, is unlike other programming and I had many false starts, primarily struggling with lexical scoping issues and getting widgets to update based on changes made to other widgets and the underlying data. The only reliable method I could find was <<-   Yikes. I’m sure over time I’d figure away around making these type of “globals” it ended up looking pretty but being ugly under the hood.

Lets Start with the Top Window

Pretty basic but it took a while to get this to work. Part of the problem was mixing the window on the left  a ggraphics() widget with the panel on the right and having it operate correctly with resizing. I tried ggroups(), gframe(), combinations of those two and in all cases the windows would not draw properly upon resizing. Text got left all over the place. That problem was solved with a gpanedgroup(). So the left pane is a gframe() that contains a  gcheckboxgroup() and then a ggrpahics() widget and the right group is also a gframe containing other widgets. The purpose of the GI is pretty simple: take a huge climate data file and station inventory and “crop” it with respect to a climate proxy file, in this case pollen data. The idea is to create some custom climate files without requiring programming. The process starts by loading a climate file ( from Berkeley Earth datasets) which uses my BerkeleyEarth Package. Then you load a pollen database and plot the two:

The  glabel(0 widgets on the right show you how many stations are loaded and the min and max time. They also show the lat /lon which defaults to the whole world. Next we select our region of interest by using the graphics crosshairs. Selecting that “extent” will automatically crop the climate data to the extent selected:

 

We see the station count adjust and the lat/lon adjust. And the times at which we have temperatures is displayed. Then hit update plot:

 

And the plot updates. Here I’ve selected an even smaller region. Unfortunately if you make a region too small, the ONLY way to undo that mistake is to “reset data”  which brings you back to square one with all the data present. The last step is to adjust the time window: Here I want to build a dataset from 1961 to 1990. So I move the gsliders() and hit update plot.

 

The last step I have to write is the “save file”.  I also had plans to add more plots, like stations versus time, but at one point I hit a nasty gWidgets error about hitting the limits on the stack. Probably my programming.  For now, this will do.  For future projects I think I’m going downstream to do toolkit programming. The layout restrictions in gWidgets did cramp my style and I really haven’t mastered the whole “signaling” handler, updating widgets.. perhaps I should use an observer model.. more reading.

I usually post code. In this case its so ugly that it would probably teach you bad things. When I get better at this I’ll do some tutorials.

 

Categories: Uncategorized
  1. stefano schiavon
    July 10, 2012 at 6:06 PM

    where did you find the Pollen station data? How can I get them in R? Thanks

    • Steven Mosher
      July 10, 2012 at 10:39 PM

      Hi stefano,

      I’m working with a researcher in Canada. The source I am using is Whitmoore 2005.

      many links here

      http://www.ncdc.noaa.gov/paleo/pollen.html

      later will come a tool ( almost done ) for a climate reconstruction package for pollen.
      Kinda fun. work in progress.

      Getting data in R is easy but depends on the file format. too many options to describe. I can help with specifics if you need that

      • stefano schiavon
        July 11, 2012 at 11:14 AM

        thank you!

  2. j verzani
    July 11, 2012 at 7:56 AM

    Hi Steven, nice post. I’d be happy to try and answer questions about the code if you want to see if the stack limits are due to gWidgets limitations.

    • Steven Mosher
      July 11, 2012 at 8:07 AM

      Hi John! I really enjoyed your book and am plowing through the RGTK2+ chapter now.
      This window is really a smaller part of a much larger project that I’m using gnotebook()
      for. I have a bunch of questions that I will get back to you with. It would be great if you had a web page for the book so that I could ask the questions there and that way other people could learn from my stupidity. Something akin to the R help list which is a great resource.

      When I’m done with the whole project I will be sharing the code as it will be included in a new package I am helping somebody write ( his first! )

      I wish now I had save the code and the errors that the created, It was basically a error saying I was too close to the C stack limits.

      • j verzani
        July 11, 2012 at 10:49 PM

        Good idea about a mailing list of some sort. I’ll look into it. –J

  3. July 11, 2012 at 2:08 PM

    Thanks for the nice example. It would be great if you can post R codes later.

    Cheers
    Yanchang
    RDataMining: http://www.rdatamining.com

    • Steven Mosher
      July 12, 2012 at 9:17 PM

      Zhao, I will try to get something up in a few days.

  4. David Gould
    July 18, 2012 at 10:28 AM

    Steven,

    I know that this is nothing to do with the topic, but I have been thinking about a question for luke warmers for a while now.

    It seems to me that climate sensitivity is not really the question or point of difference between alarmists like me and luke warmers. What is really the point of difference is the expected damage. As an example, someone who believed in low sensitivity but who believed that the earth responded dramatically to small change would for practical purposes have the same view as someone with views like mine (high sensitivity, relatively dramatic response).

    I would be interested in your views on this point. If you want to move this post or delete it and respond privately, that would be fine.

    David Gould

    • Steven Mosher
      July 18, 2012 at 10:32 AM

      Hi david,

      Well, its best to discuss this stuff in a setting where other people can chime in.

      But

      ” low sensitivity but who believed that the earth responded dramatically to small change ”

      is an oxymoron. low sensitivity implies a small change: doubling C02 gives us 3.7Watts.

      low sensitivity implies a response of say 1C. luke warmer would say, >50% probablity
      of <3C.

      • David Gould
        July 30, 2012 at 6:40 AM

        Steven,

        Not quite what I meant.

        Say that you believed that sensitivity was ridiculously high – 10 degrees per doubling. But say you also believed that the impact on the earth of 20 degrees of warming would be minimal.

        Then say I believed that sensitivity was low – .1 degrees per doubling. But I believed that a .2 degree rise in temperatures would have a catastrophic effect.

        Disagreements on sensitivity are not the ballgame when it comes to taking action: it is a combination of sensitivity and our belief about what a given temperature rise will mean for the earth as a whole.

      • Steven Mosher
        July 30, 2012 at 12:04 PM

        say your uncle was your aunt.
        however, in general, yes, I agree.
        That said, uncertainty over RCPs, probably swamps everything.

  5. Pjotr
    July 29, 2012 at 4:49 AM

    Mosher,

    Doing the Best thing you must have noticed someting about land-temperatures.
    If you didn’t, start over again.

    • Steven Mosher
      July 29, 2012 at 5:23 AM

      Good point. I did notice something. Hence, no need to start over. Thank you for playing

  6. Manfred
    July 31, 2012 at 4:05 AM

    Hi Steven Mosher,

    figure 23 in Anthony’s paper opens in my view an easy new way to select well sited stations globally.

    Click to access watts-et-al-2012-figures-and-tables-final1.pdf

    Well placed stations appear to have very similar tends in tmin, tmax, and tmean. while poorly placed stations don’t, mostly because tmin trends are significantly increased.

    To select proper stations, then in a first step only select those stations with very similar trends of tmin, tmax, tmean, perferably similar over several time scales.

    If the number of such stations is not sufficient, more stations may be added, by extracting only the the time span with similar tmin, tmax, tmean.

  7. Lucas
    June 14, 2015 at 4:55 PM

    Hi Steven Mosher,
    nice work, thanks!
    I work in a Institute where we have tons of climate data. Just a few days ago we started to work trying to organize these data sets. We are using R to compile the information and we plan use it to distribute the result of the compilation in the future.
    Something like you have presented here is exactly what we have in mind.
    It would be really great if you can post some code of your work.

    • June 20, 2015 at 1:27 AM

      I will try Lucas. I need to get back to the project

  8. greg
    September 5, 2015 at 3:44 AM

    Hi, interesting article. Any hint or link on how you code the crosshair, the selection and the zoom part ?
    Thanks !

  9. Steven Mosher
    September 5, 2015 at 9:12 PM

    I think it just shows up

  1. No trackbacks yet.

Leave a comment