 
 We'll add a few additional values to make sure extending beyond January works.
 
+Expected outcome for adding twos to the end of the timeseries in a new year:
+
 0 0 => all ones through end of December
 1 1 => all ones then twos through first period of January
 2 3 => all ones then twos through mid-February
 3 5 => all ones then twos through mid-Marchoutput through mid-March
 12 23 => all ones then twos through end of second December
 
-The problem at present: The output timeseries seems to be too short by 1-2 periods. So even if we have monthly data for December (starting on 12/1/2011), the output will only run through 11/16/2011 because the 16-day periods are bounded by 12/1/2011 rather than 12/31/2011.
+This highlights that the expansion works for 32- to 16-day resolution except at the end of the year.
+
 "
    (let [series (concat (repeat 12 1) (repeat ?extra-32 2))
          ts (schema/timeseries-value 360 series)

 3          5
 12         23)



    (ts-expander "32" "16" ts) => output))

(fact
  
  (let [periods-32 12
        periods-16 23
        ts (schema/timeseries-value 360 (take periods-32 data/ndvi))]
    (count (:series (ts-expander "32" "16" ts))) => periods-16))


;; Sam, this is commented out because all the error messages were
;; getting annoying

(tabular
 (fact
   (let [series (concat (repeat 12 1) (repeat ?extra-32 2))
         ts (schema/timeseries-value 360 series)
         expanded-ts (:series (ts-expander "32" "8" ts))
         expected-ts (map float (concat (repeat 45 1) (repeat ?extra-8 2)))]
     expanded-ts => expected-ts))
 ?extra-32 ?extra-8
 0          0
 1          3
 2          7
 3          11
 12         45)

(tabular
 (fact
   "Expanding a year-long monthly timeseries (12 periods) should yield a year's worth of 16-day periods (23). Here we simplify by using the same value for all periods, so `?periods-target-res` is just the number of periods we should see, ignoring the value for those periods.

The correct number of periods for 16- and 8-day timeseries is given by the number of directories in ftp://e4ftl01p.cr.usgs.gov/MOLT/MOD13A1.005 for the range of interest.

Period 360 is 2000-01-01 at monthly resolution
Period 736 is 2000-01-01 at 16-day resolution

The problem at present: The output timeseries seems to be too short by 1-2 periods. So even if we have monthly data for December (starting on 12/1/2011), the output will only run through 11/16/2011 because the 16-day periods are bounded by 12/1/2011 rather than 12/31/2011."

   (let [series (repeat ?periods-base-res 1)
         ts (schema/timeseries-value ?start-idx series)
         expected-count (count (:series (ts-expander ?base-res ?target-res ts)))
         ]
     expected-count => ?periods-target-res))
 ?base-res ?target-res ?periods-base-res ?periods-target-res ?start-idx
 "32"          "16"            1                1               360
 "32"          "16"            2                3               360
 "32"          "16"            3                5               360
 "32"          "16"            9                17              360
 "32"          "16"            10               19              360
 "32"          "16"            11               20              360 
 "32"          "16"            12               23              360
 "32"          "16"            13               24              360
 "32"          "16"            14               26              360
 "32"          "16"            24               46              360
 "32"          "16"            25               47              360
 
 "32"          "8"             1                3               360
 "32"          "8"             2                7               360
 "32"          "8"             3                11              360
 "32"          "8"             12               45              360

 "16"          "8"             1                2               736
 "16"          "8"             2                4               736
 "16"          "8"             3                6               736
 "16"          "8"             23               45              736)


 

(tabular
 (fact
