   (?- (stdout)
       (sample-ascii m-res ll-res
                     ascii-path tile-seq)))
+
+
+(def count-agg
+  (<- [?a :> ?count]
+      (c/count ?count)))
+
+(defn count-test []
+  (let [tap (memory-source-tap [[1 2]
+                                [1 3]
+                                [1 4]])]
+    (?<- (stdout)
+         [?a ?count ?max]
+         (tap ?a ?b)
+         (c/max ?b :> ?max)
+         (c/count ?count))))

    (?- (stdout)
        (sample-ascii \"1000\" 0.1 \"/path/to/ascii.csv\" [[8 6] [12 10]]))"
  [m-res ll-res ascii-path tile-seq]
  (let [tile-source (memory-source-tap tile-seq)
        ascii-source (grid-source (hfs-textline ascii-path))]
    (<- [?mod-h ?mod-v ?sample ?line ?val]

  (map (fn [val]
         (try (Float. val)
              (catch Exception _
                val)))
       (split line #",")))

(defn fire-source
  "Takes a source of textlines, and returns 2-tuples with latitude and
  longitude."
  [source]
  (<- [?dataset ?lat ?lon ?kelvin ?datestring]
      (source ?line)
      (identity "fire" :> ?dataset)
      (mangle ?line :> ?lat ?lon ?kelvin _ _ ?datestring _ _ _ _ _ _)))

(defmapop [to-period [t-res]]
  [datestring]
  (let [[month day year] (->> (split datestring #"/")
                              (map #(Integer. %)))]
    (periodize t-res year month day)))
"12/31/2005"

(defn rip-fires
  "Aggregates fire data at the supplied path by modis pixel at the
  supplied resolution."
  [m-res t-res path]
  (let [fires (fire-source (hfs-textline path))]
    (<- [?dataset ?mod-h ?mod-v ?sample ?line ?tperiod ?count ?max-t]
        (fires ?dataset ?lat ?lon ?kelvin ?datestring)
        (to-period [t-res] ?datestring :> ?tperiod)
        (> ?kelvin 330)
        (latlon->modis m-res ?lat ?lon :> ?mod-h ?mod-v ?sample ?line)
        (c/max ?kelvin :> ?max-t)
        (c/count ?count))))

(defn run-rip
  "Rips apart fires!"
  [count m-res t-res path]
  (?- (stdout) (c/first-n (rip-fires m-res t-res path)
                          count)))

;; FOR LATER...
;;
;; ## ASCII Grid Sampling

(defn liberate
