/* ========================================================================= /* @(#)MoWinReg.aml 3.0 08/10/2001 15:33:41 /* ------------------------------------------------------------------------- /* Lab for synthetic dynamic eco-phenomenology, WSL /* ------------------------------------------------------------------------- /* Program: MOWINREG.AML /* Purpose: Calculate downscaled climate maps using a fine-resolution /* elevation grid and regression values from climate variables /* (to elevation). This procedure is based on regionally para- /* metrized downscaling of existing PRISM- or DAYMET maps, using /* the 'mowing window'-regression technique. The following /* coverages have to be prepared first: /* - a fine-scale DEM (e.g.30m) that covers the area of interest /* - a coarse-scale DEM of the same origin as the climate grids /* - a lattice that matches the DAYMET/PRISM-grids for this area /* - a lattice that matches the reprojected coarse grid size /* - the program 'mowinreg' /* Additionally, you have to prepare the LL/UR corrdinates of /* the reprojected coarse DEM, an associated projection file, /* the associated number of rows/cols, the window size of the /* mowing window for the regression runs, the cell size of the /* fine-scale DEM, and the grid dimension XY-min/max of the /* fine-scale DEM. /* ------------------------------------------------------------------------- /* Usage: &r mowinreg clim /* ------------------------------------------------------------------------- /* Notes: The AML needs to be adjusted for the exact cooordinates of /* the LL-corner of the DEM-grid and of the #rows/cols, respec- /* tively. It also assumes, that the PRISM-maps are in geogra- /* phical projection, and the DEM in UTM. The lattice is repro- /* jected to UTM, and adjusted to the DEM in the AML-run. /* ------------------------------------------------------------------------ /* Input: DAYMET-maps, DEM, lattice /* Output: monthly climate maps /* ------------------------------------------------------------------------- /* History: Niklaus E. Zimmermann - 09/18/1997 - Original coding /* Niklaus E. Zimmermann - 01/26/1998 - Modifications /* Niklaus E. Zimmermann - 08/10/2001 - New generalized version /* Niklaus E. Zimmermann - 09/21/2001 - Split into subroutines /* Niklaus E. Zimmermann - 11/30/2001 - Some Tuning /* ========================================================================= &args .clim /* The base name of the climate cover (type) &s .ipth := /modis/mlp/%.clim% /*In-path &s .opth := /modis/mlp/%.clim%_30m /*Out-path &s .wins := 25 /*Width of window &s .minp := 160 /*Min # points for regr. &s .celc := 1000.0 /*Size of reprojected coarse DEM &s .xymn := 535500.0, 4303500.0 /*Reprojected coarse DEM XYmin &s .xymx := 811500.0, 4703500.0 /*Reprojected coarse DEM XYmax &s .nrow := 400 /*New # rows &s .ncol := 276 /*New # cols &s .cdem := cdem /*Coarse-scale DEM &s .fdem := fdem /*Fine-scale DEM &s .lin := latt_laz /*Coarse Lattice &s .lout := latt_utm /*Reprojected-Lattice &s .proj := mlp.prj /*New projection file &s .cell := 30.0 /*New IDW cellsize &s .idww := 549444.4,4354254.5,791424.4,4695744.5 /*New DEM IDW window /* ------------------------------------------------------------------------- /* Main of MoWinReg program, calling a set of subroutines /* ------------------------------------------------------------------------- &if [show program] ne ARC &then quit copy %.ipth%/%.lin% %.ipth%/tmp /* Generate copy from latt &CALL overlay1 /* Overlay LAZ-grids with latt_laz &CALL reproj /* Reproject latt to UTM (new dir) &CALL gengrids /* Generate grids out of temporary latt &CALL export /* unload to AscIIgrid-format (*.dat) &CALL mowin /* Perform MoWin regression & grids gzip %.clim%*dat /* Zip climate AscIIgrid files gzip dem.dat /* Zip DEM AscIIgrid-file (dem.dat) /**>mv %.clim%*.gz _archive/. /* Move climate files to archive /**>mv dem.dat.gz _archive/. /* Move DEM file to archive /**>"rm" dem.dat.gz /* Remove zipped files (optional switch) &CALL overlay2 /* Overlay lapse rates and intercepts &CALL blowup /* Interpolate to fine-scale and blow up &return &ROUTINE overlay1 /* ------------------------------------------------------------------------- /* Overlay the lattice with corase climate/dem grids [..ovl_p.aml] /* ------------------------------------------------------------------------- &do I := 1 &to 12 &if %I% lt 10 &then &goto loop11 &else &goto loop12 &end &label loop11 latticespot %.ipth%/%.clim%0%I%_laz %.ipth%/tmp %.clim%%I% &goto jump1 &label loop12 latticespot %.ipth%/%.clim%%I%_laz %.ipth%/tmp %.clim%%I% &goto jump1 &label jump1 &end latticespot %.ipth%/%.cdem% %.ipth%/tmp dem &RETURN &ROUTINE reproj /* ------------------------------------------------------------------------- /* Reproject lattice to new projection [..ovl_p.aml] /* ------------------------------------------------------------------------- project COVER %.ipth%/tmp %.opth%/tmpnew %.opth%/%.proj% kill %.ipth%/tmp all &RETURN &ROUTINE gengrids /* ------------------------------------------------------------------------- /* Generate grids from re-projected lattice [..p2g_p.aml] /* ------------------------------------------------------------------------- &do I := 1 &to 12 &if %I% lt 10 &then &goto loop21 &else &goto loop22 &end &label loop21 pointgrid %.opth%/tmpnew tmpp %.clim%%I% %.celc% N %.xymn% %.nrow%, %.ncol% NODATA grid tmpi = idw(%.opth%/tmpnew,%.clim%%I%,#,2,sample,4,#,%.celc%,%.xymn%,%.xymx%) %.opth%/%.clim%0%I% = con(isnull(tmpp),tmpi,tmpp) kill tmpp all kill tmpi all quit &goto jump2 &label loop22 pointgrid %.opth%/tmpnew tmpp %.clim%%I% %.celc% N %.xymn% %.nrow%, %.ncol% NODATA grid tmpi = idw(%.opth%/tmpnew,%.clim%%I%,#,2,sample,4,#,%.celc%,%.xymn%,%.xymx%) %.opth%/%.clim%%I% = con(isnull(tmpp),tmpi,tmpp) kill tmpp all kill tmpi all quit &goto jump2 &label jump2 &end pointgrid %.opth%/tmpnew tmpp dem %.celc% N %.xymn% %.nrow%, %.ncol% NODATA grid tmpi = idw(%.opth%/tmpnew,dem,#,2,sample,4,#,1000.0,%.xymn%,%.xymx%) %.opth%/cdemnew = con(isnull(tmpp),tmpi,tmpp) kill tmpp all kill tmpi all quit &RETURN &ROUTINE export /* ------------------------------------------------------------------------- /* Exports grids from re-projected lattice to AscII [..p2g_p.aml] /* ------------------------------------------------------------------------- &do I := 1 &to 12 &if %I% lt 10 &then &goto loop31 &else &goto loop32 &end &label loop31 gridascii %.opth%/%.clim%0%I% %.clim%%I%.dat &goto jump3 &label loop32 gridascii %.opth%/%.clim%%I% %.clim%%I%.dat &goto jump3 &label jump3 &end gridascii %.opth%/cdemnew dem.dat "rm" %.clim%*prj "rm" dem.prj &RETURN &ROUTINE mowin /* ------------------------------------------------------------------------- /* Calculates the regression-based downscaling (lpsrt/icept) [..mowin_p.aml] /* ------------------------------------------------------------------------- &do I := 1 &to 12 mowinreg dem.dat %.clim%%I%.dat %.wins% %.wins% %.minp% 2 y asciigrid lpsrt.out %.opth%/lpsrt%I% FLOAT asciigrid icept.out %.opth%/icept%I% FLOAT &end "rm" *.out &RETURN &ROUTINE overlay2 /* ------------------------------------------------------------------------- /* Overlays the new ICECPT/LPSRT grids with UTM lattice [..mowin_prep.aml] /* ------------------------------------------------------------------------- &do I := 1 &to 12 latticespot %.opth%/lpsrt%I% %.opth%/%.lout% lpsrt%I% latticespot %.opth%/icept%I% %.opth%/%.lout% icept%I% kill %.opth%/lpsrt%I% all kill %.opth%/icept%I% all &end &RETURN &ROUTINE blowup /* ------------------------------------------------------------------------- /* Generates IDW-based interp. fine-scale climate maps [..prec_calc.aml] /* ------------------------------------------------------------------------- grid &sv .f := %.opth%/%.lout% &do I := 1 &to 12 &if %I% lt 10 &then &goto loop41 &else &goto loop42 &end &label loop41 %.opth%/ils%I% = idw(%.f%,icept%I%,#,2,sample,4,#,%.cell%,%.idww%) %.opth%/lls%I% = idw(%.f%,lpsrt%I%,#,2,sample,4,#,%.cell%,%.idww%) %.opth%/%.clim%0%I% = int( (%.opth%/ils%I% + (%.opth%/lls%I% * %.opth%/%.fdem%)) * 100.0) &goto jump4 &label loop42 %.opth%/ils%I% = idw(%.f%,icept%I%,#,2,sample,4,#,%.cell%,%.idww%) %.opth%/lls%I% = idw(%.f%,lpsrt%I%,#,2,sample,4,#,%.cell%,%.idww%) %.opth%/%.clim%%I% = int( (%.opth%/ils%I% + (%.opth%/lls%I% * %.opth%/%.fdem%)) * 100.0) &goto jump4 &label jump4 &end quit &RETURN