Sep 10 2007

Code Release

Published under Climate Change, Off Topic

Since Hansen has released his code I thought I’d release a portion of my code as well. This is not in any way important, but it’ll show how terrible a programmer I am. I’m not sure if the NASA code is anywhere near as horrible as this, I haven’t looked at it.

The purpose of this procedure is obvious by its name ‘variable_compare’. I’ve replaced which variable is being compared with the word ‘variable’ to protect the innocent. A little background - I want to compute variable from a dataset that includes things such as altitude (alt), liquid water content (lwc), temperature (ta), dew point temperature (td), water vapor mixing ratio (qg), and atmospheric pressure (ps). Why I want to do this is a mystery (to you, not to me). That’s enough of a preamble, here’s the code.

PRO variable_compare, leg, x, alt, lwc, ta, td, qg, ps, whichlegs, print=print, fname=fname, linfit=linfit
; first element of whichlegs is below cloud, all others are in cloud

if not keyword_set(print) then print = 0 else print = 1
if print eq 1 then color = 10 else color = 1000
if not keyword_set(fname) then fname = 'a.eps'
if not keyword_set(linfit) then linfit = 0 else linfit = 1

s_below = where(leg eq whichlegs[0] and lwc ge 0)
lifting_condensation_level = mean( (compute_lcl(s_below, alt, ta, qg, ps))(s_below) )

plotx = dblarr(N_ELEMENTS(whichlegs)-1)
ploty = dblarr(N_ELEMENTS(whichlegs)-1)
errx = dblarr(N_ELEMENTS(whichlegs)-1)
erry = dblarr(N_ELEMENTS(whichlegs)-1)

FOR i=0, N_ELEMENTS(whichlegs)-2 DO BEGIN
s = where(leg eq whichlegs[i+1] and lwc ge 0)
variable = compute_variable_simple(s_below, s, x, alt, lwc, ta, td, qg, ps)

plotx[i] = mean(variable)
ploty[i] = mean(alt(s)-lifting_condensation_level)

errx[i] = stddev(variable)
erry[i] = stddev(alt(s))

ENDFOR

if linfit eq 0 then $
fit = comfit(ploty, plotx, [20.0,-0.9,0.0], /geometric) $
else $
fit = linfit(ploty, plotx)

if print eq 1 then begin
set_ps
tvlct, [[256l-lindgen(128)*2,lonarr(128)], [lindgen(128)*2,256l-2*lindgen(128)], [lonarr(128),2*lindgen(128)]]
device, filename = ‘~/plots/’+fname, /color, xsize = 6, ysize = 5, /inches, /times, /bold
endif

ploterror, plotx, ploty, errx, erry
if linfit eq 0 then $
oplot, fit[0]*(indgen(380)+20)^fit[1]+fit[2], indgen(380)+20, color=color $
else $
oplot, fit[0]+(indgen(380)+20)*fit[1], indgen(380)+20, color=color
if print eq 1 then device, /close
END

The first few lines are just initializing the optional keywords. Then we come to a function called compute_lcl. This fuction outputs an array of values corresponding to the lifting condensation levels assuming a vertical adiabatic ascent. The mean value of this array is assigned to a variable called lifting_condensation_level.

After initializing some arrays, we come to a FOR statement. This loops through the other legs in the ‘whichlegs’ variable. As the first, and only, comment states “first element of whichlegs is below cloud, all others are in cloud”. So for instance if whichlegs = [0,1,2,3,4] when leg equaled 0 would be below the cloud base and legs 1, 2, 3, and 4 would be in the cloud. This FOR statement just loops the in cloud legs. It calls compute_variable_simple() and assigns the mean and standard deviation to the proper variables. There is a compute_variable(), but it doesn’t change the answer much and takes much more time to compute.

The rest of the procedure is just fitting the data and plotting it. Woohoo. Aren’t you glad I released my code?

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Related Posts:

  • Showing simple contouring in IDL
  • Gavin Schmidt on Imperfect Data
  • World Population, Carbon Dioxide, and Eugenics
  • Icky Weather
  • Today’s Nominee for Worst Person in the World!
  • Comments are closed at this time.

    Trackback URI |

    To reduce spam, comments are automatically closed 30 days after the last comment. If you would like to comment on any closed thread, please use the contact form at the top of this page.