         total-pixels (pixels-at-res res)]
     (/ pixel-span total-pixels)))
 
-(defn distance
-  "Calculates distance of magnitude from the starting point in a given direction."
-  [dir start magnitude]
-  (dir start magnitude))
-
-(defn scale
-  "Scales each element in a collection of numbers by the supplied factor."
-  [fact seq]
-  (for [x seq] (* x fact)))
+;; ## Main Conversion Functions
 
 (defn pixel-coords
   "returns the row and dimension of the pixel on the global MODIS grid."

   :500 2400
   :1000 1200})

(defn cos
  "Takes the cosine of the supplied angle. Angle must be in degrees."
  [angle]
  (Math/cos (Math/toRadians angle)))

(defn degs-by-rho
  "Multiplies the argument by rho and converts the answer to radians."
  [arg]
  (* arg *rho* (/ *pi* 180)))

(defn sinusoidal-x
  "Returns the sinusoidal projection's x coordinate in meters for a given lat and long (in degrees)."
  [lat lon]
  (degs-by-rho (* (cos lat) lon)))

(defn sinusoidal-y
  "Returns the sinusoidal projection's y coordinate in meters for a given lat and long (in degrees)."
  [lat lon]
  (degs-by-rho lat))

(defn lat-long
  "Computes the latitude and longitude for a given set of sinusoidal map coordinates (in meters)."
  [x y]
  (let [lat (/ y *rho*)
        lon (/ x (* *rho* (Math/cos lat)))]
    (map #(Math/toDegrees %) [lat lon])))

(def min-x (sinusoidal-x 0 -180))
(def min-y (sinusoidal-y -90 0))
(def max-y (sinusoidal-y 90 0))

(defn pixel-length
  "The length, in meters, of the edge of a pixel at a given resolution."

;; 38,800 chunks for the 1km data means that to do a straight lookup for everything on the rain table is going to take,
;; roughly, 90 minutes (distributed across machines). Gotta be a faster way to do this!

(ns forma.sinu
  (:use [clojure.contrib.generic.math-functions :only (cos)]))


;; ## Constants

(def *rho* 6371007.181)
(def *x-tiles* 36)
(def *y-tiles* 18)

