Skip to content

Importing Climex files

Joel Pitt edited this page Feb 6, 2014 · 1 revision

Climex files have the following format:

  CLIMEX - Compare Locations (1 species)
Cytisus scoparius 21 July 07
Run on Apr 18 2008 13:04
CRU_HD_61-90_obs_NZ
No Climate Change / Irrigation: Not Set


"Continent","Country","State","Location","Latitude","Longitude","EI","GI","TI"
CRU_World,No_countries,,66679,-46.250,166.750,12,16,16
...

Import as a vector to a lat long location (with an ellipsoid specified - I used nzgd49 to create a lat-long location called climex-import):

  INFILE=~/network/projects/bw-comparison/Scotch_broom_CRU_HD_61-90_NZ.csv
  MAPNAME=scotch_broom
  cut -d, -f4,5,6,7,8,9 $INFILE \
  | v.in.ascii skip=8 fs=, x=3 y=2 cat=1 output=$MAPNAME
  v.db.renamecol map=$MAPNAME column=int_2,ei
  v.db.renamecol map=$MAPNAME column=int_3,gi
  v.db.renamecol map=$MAPNAME column=int_4,ti

Project to new location:

  v.proj input=$MAPNAME location=climex-import mapset=PERMANENT output=$MAPNAME

Interpolate to raster using v.surf.rst and v.surf.idw with a variety of nearby points (Note that you may want to decrease the region resolution since the CLIMEX vector is usually pretty sparse):

  for x in ei gi ti; do
    v.surf.rst input=$MAPNAME zcolumn=$x maskmap=nz_DEM_jacques npmin=41 smooth=0 elev=${x}_surf --o
    for i in 1 2 3 4; do
      v.surf.idw input=$MAPNAME column=$x npoints=$i output=${x}_idw${i} --o
      r.mapcalc "${x}_idw${i}_masked=if(nz_DEM_jacques,${x}_idw${i},null())"
      g.remove rast=${x}_idw${i}
      g.rename rast=${x}_idw${i}_masked,${x}_idw${i}
    done
  done