Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created June 2, 2011 21:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/1005368 to your computer and use it in GitHub Desktop.
Save sritchie/1005368 to your computer and use it in GitHub Desktop.
(def
^{:doc "Predicate macro aggregator that extracts a timeseries, given
`?chunk`, `?temporal-resolution` and `?date`. Currently only
functions when `?chunk` is an instance of `forma.schema.IntArray`."}
extract-tseries
(<- [?temporal-res ?date ?chunk :> ?pix-idx ?t-start ?t-end ?tseries]
(datetime->period ?temporal-res ?date :> ?tperiod)
(:sort ?tperiod)
(timeseries ?tperiod ?chunk :> ?pix-idx ?t-start ?t-end ?tseries)))
(def
^{:doc "Predicate macro; extracts relevant spatial data
from the supplied chunk fields."}
extract-attrs
(<- [?tilestring ?spatial-res ?chunk-size ?chunkid ?pix-idx :> ?tile-h ?tile-v ?sample ?line]
(tilestring->hv ?tilestring :> ?tile-h ?tile-v)
(tile-position ?spatial-res ?chunk-size ?chunkid ?pix-idx :> ?sample ?line)))
(defn process-tseries
"Given a source of chunks, this subquery generates timeseries with
all relevant accompanying information."
[chunk-source]
(<- [?dataset ?spatial-res ?temporal-res ?tile-h ?tile-v ?sample ?line ?t-start ?t-end ?tseries]
(chunk-source ?dataset ?spatial-res ?temporal-res ?tilestring ?date ?chunkid ?int-chunk)
(io/num-ints ?int-chunk :> ?chunk-size)
(extract-tseries ?temporal-res ?date ?int-chunk :> ?pix-idx ?t-start ?t-end ?tseries)
(extract-attrs ?tilestring ?spatial-res
?chunk-size ?chunkid ?pix-idx :> ?tile-h ?tile-v ?sample ?line)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment