Home > Uncategorized > MoshTemp 202

MoshTemp 202

In this installation we will ad a few bits of code here and there checking our work as we go along. I will dump a new Zip tomorrow. First, lets hit the biggest change. I’ll ship the package with a couple more files, V2Anomalies.Rdata and V2mean.Rdata. All the work from here on out uses V2anomalies.

a quick note. Every object now comes with a self documenting feature

InputParameters<-list(Title=”BASELAND1900-2009″,

Cellsize=CELL.DEFAULT,

Years=yearRange,

Cam=camCriteria,

Landmask=LAND.MASK,

SourceData=GhcnV2_Zipped,

SourceDate=lastModified(GhcnV2_Zipped),

AnomalyData=V2ANOMALIES.RDATA,

AnomalyDate=lastModified(V2ANOMALIES.RDATA),

Stations=NULL,

Time=Sys.time(),

Author=”Steven Mosher”)

This gets appended to every file. Basically giving you tracibility.

I also added some code to the geography section: We read in a land mask:There are two things here of note: the CELL.SIZE which I fixed at 3 degrees and the base resolution which is 1 degree. I could use ,25 degree data. Look at the aggregate term. If I start with 1 degree data I can select 2 degree squares, 2.5, 3 degree data or 5 degree data. factor<-cellsize/basesize is a key line. Input .25 degree data and you can aggregate differently. “factor” controls how many grids i average to make my final resolution. Execute this and you get a Land mask of size ‘cellsize’. The data is then turned into a fraction and you have the fractional area covered by land 0 to 1

getLandMask<-function(cellsize=CELL.DEFAULT,file=Mask_File){

basesize<-LAND.RESOLUTION

factor<-cellsize/basesize

land<-read.table(file,sep=” “)

world<-raster(as.matrix(land),xmn=-180, xmx=180, ymn=-90, ymx=90,

crs=”+proj=longlat +datum=WGS84″)

if(factor>1)world<-aggregate(world,fact=factor)

return(world/100)

}

The I defined a bunch of helper functions. basic stuff

getCellArea<-function(cells,globe){

cellArea<-area(globe)

areaValues<-cellValues(cellArea,cells)

return(areaValues)

}

getLandArea<-function(cells,globe){

cellArea<-area(globe)

landArea<-globe*cellArea

landValues<-cellValues(landArea,cells)

return(landValues)

}

landCells<-function(globe){

v<-cellValues(globe,seq(1,ncell(globe)))

return(which(v>0))

}

waterCells<-function(globe){

all<-seq(1,ncell(globe))

land<-landCells(globe)

water<-setdiff(all,land)

return(water)

}

And I added some analysis code.

stationCount<-function(anomalies){

output<-zoo(rowSums(!is.na(anomalies)), order.by=time(anomalies))

return(output)

}

Here is Moshtemp202. Loads your Anomalies and does a few simple tests:

source(“Global.R”)

load(V2ANOMALIES.RDATA)

o<-obj

InputParameters<-o$Parameters

print(InputParameters)

V2Anomalies<-o$Data

StationStats<-stationCount(V2Anomalies)

print(StationStats)

plot(StationStats)

temps<-rowMeans(V2Anomalies,na.rm=T)

plot(zoo(temps,order.by=timeline))

Code at the drop. later cause I’m beat

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: