This looks good overall, but I am puzzled by the formula you quote: if I measure cellsize in kilometers, say (or worse, in decimal degrees), then a / tan(beta) can easily be less than 1, leading to a negative CTI. Perhaps your formula assumes cellsize is given in some standard, fixed units such as meters?