def testDetermineAggregationWindow(self): """ Verify aggregation window can be determined from the cwtVar distribution """ weekPeriod = 604800.0 samplingIntervalInS = numpy.timedelta64(300, 's') widths = numpy.logspace(0, numpy.log10(40000 / 20), 50) timeScaleInS = widths * samplingIntervalInS * 4 timeScaleInS = timeScaleInS.astype('timedelta64[s]') ts = timeScaleInS.astype('float64') cwtVar = numpy.exp(-(ts - weekPeriod)**2 / (2 * 100000.0**2)) numDataPts = 40000 maxSamplingInterval = (float(numDataPts) / 1000.0 * samplingIntervalInS) maxSamplingInterval = maxSamplingInterval.item().total_seconds() timeScaleInMs = timeScaleInS.astype('timedelta64[ms]') samplingIntervalInMs = samplingIntervalInS.astype('timedelta64[ms]') aggregationTimeScaleInMs = param_finder._determineAggregationWindow( timeScale=timeScaleInMs, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingIntervalInMs, numDataPts=40000) aggregationTimeScaleInS = aggregationTimeScaleInMs.item( ).total_seconds() self.assertLessEqual(aggregationTimeScaleInS, maxSamplingInterval) self.assertGreater(aggregationTimeScaleInS, samplingIntervalInS.astype('float64')) # if the numDataPts < MIN_ROW_AFTER_AGGREGATION, no aggregation should occur aggregationTimeScaleInMs = param_finder._determineAggregationWindow( timeScale=timeScaleInMs, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingIntervalInMs, numDataPts=param_finder.MIN_ROW_AFTER_AGGREGATION - 1) aggregationTimeScaleInS = aggregationTimeScaleInMs.item( ).total_seconds() self.assertEqual(aggregationTimeScaleInS, samplingIntervalInS.astype('float64'))
def testDetermineAggregationWindow(self): """ Verify aggregation window can be determined from the cwtVar distribution """ weekPeriod = 604800.0 samplingIntervalInS = numpy.timedelta64(300, "s") widths = numpy.logspace(0, numpy.log10(40000 / 20), 50) timeScaleInS = widths * samplingIntervalInS * 4 timeScaleInS = timeScaleInS.astype("timedelta64[s]") ts = timeScaleInS.astype("float64") cwtVar = numpy.exp(-(ts - weekPeriod) ** 2 / (2 * 100000.0 ** 2)) numDataPts = 40000 maxSamplingInterval = float(numDataPts) / 1000.0 * samplingIntervalInS maxSamplingInterval = maxSamplingInterval.item().total_seconds() timeScaleInMs = timeScaleInS.astype("timedelta64[ms]") samplingIntervalInMs = samplingIntervalInS.astype("timedelta64[ms]") aggregationTimeScaleInMs = param_finder._determineAggregationWindow( timeScale=timeScaleInMs, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingIntervalInMs, numDataPts=40000 ) aggregationTimeScaleInS = aggregationTimeScaleInMs.item().total_seconds() self.assertLessEqual(aggregationTimeScaleInS, maxSamplingInterval) self.assertGreater(aggregationTimeScaleInS, samplingIntervalInS.astype("float64")) # if the numDataPts < MIN_ROW_AFTER_AGGREGATION, no aggregation should occur aggregationTimeScaleInMs = param_finder._determineAggregationWindow( timeScale=timeScaleInMs, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingIntervalInMs, numDataPts=param_finder.MIN_ROW_AFTER_AGGREGATION - 1, ) aggregationTimeScaleInS = aggregationTimeScaleInMs.item().total_seconds() self.assertEqual(aggregationTimeScaleInS, samplingIntervalInS.astype("float64"))
def testDetermineAggregationWindow(self): """ Verify aggregation window can be determined from the cwtVar distribution """ weekPeriod = 604800.0 samplingInterval = numpy.timedelta64(300, 's') widths = numpy.logspace(0, numpy.log10(40000 / 20), 50) timeScale = widths * samplingInterval * 4 timeScale = timeScale.astype('float64') cwtVar = numpy.exp(-(timeScale - weekPeriod) ** 2 / (2 * 100000.0 ** 2)) numDataPts = 40000 maxSamplingInterval = (float(numDataPts) / 1000.0 * samplingInterval) maxSamplingInterval = maxSamplingInterval.item().total_seconds() aggregationTimeScale = param_finder._determineAggregationWindow( timeScale=timeScale, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingInterval, numDataPts=40000 ) aggregationTimeScale = aggregationTimeScale.item().total_seconds() self.assertLessEqual(aggregationTimeScale, maxSamplingInterval) self.assertGreater(aggregationTimeScale, samplingInterval.astype('float64')) # if the numDataPts < MIN_ROW_AFTER_AGGREGATION, no aggregation should occur aggregationTimeScale = param_finder._determineAggregationWindow( timeScale=timeScale, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingInterval, numDataPts=param_finder.MIN_ROW_AFTER_AGGREGATION-1 ) aggregationTimeScale = aggregationTimeScale.item().total_seconds() self.assertEqual(aggregationTimeScale, samplingInterval.astype('float64'))
def testDetermineAggregationWindow(self): """ Verify aggregation window can be determined from the cwtVar distribution """ dayPeriod = 86400.0 weekPeriod = 604800.0 samplingInterval = numpy.timedelta64(300, 's') widths = numpy.logspace(0, numpy.log10(40000 / 20), 50) timeScale = widths * samplingInterval * 4 timeScale = timeScale.astype('float64') cwtVar = numpy.exp(-(timeScale - weekPeriod) ** 2 / (2 * 100000.0 ** 2)) numDataPts = 40000 maxSamplingInterval = (float(numDataPts) / 1000.0 * samplingInterval) aggregationTimeScale = param_finder._determineAggregationWindow( timeScale=timeScale, cwtVar=cwtVar, thresh=0.2, samplingInterval=samplingInterval, numDataPts=40000 ) self.assertLessEqual(aggregationTimeScale, maxSamplingInterval) self.assertGreater(aggregationTimeScale, samplingInterval.astype('float64'))