setScriptDescription('''Demo cadence checks.  In many cases, too small a cadence is identified and in others
a cadence is too big. See <a href='https://sourceforge.net/p/autoplot/bugs/1582/'>bug 1582</a>
and https://github.com/autoplot/dev/blob/master/bugs/2022/20220125/shouldNotBreak.jy 
https://jfaden.net/jenkins/job/autoplot-test014/''')

from org.das2.qds import SemanticOps
ds= getDataSet( '/home/jbf/project/juno/u/jeremy/20230706/cadenceCheck.d2s' )
print SemanticOps.guessXTagWidth( xtags(ds), ds ), ds


print 'Second case is interesting because saving data to a file does not show the bug'
from org.das2.qds import SemanticOps

L1= 5.1
MLT1= 5.890
MLT2= 6.09

MLT= linspace( MLT1, MLT2, 100 )
L1= ones(100) * L1

print SemanticOps.guessXTagWidth( cos(MLT)*L1, sin(MLT)*L1 ), min(diff( cos(MLT)*L1 ) ), max(diff( cos(MLT)*L1 ) )

# single-element dataset would cause IndexOutOfBounds error, so include test for it.
print 'DataSetUtil.guessCadence would fail with one timetag, which was surely a regression'
from org.das2.qds import DataSetUtil
xds= reform( dataset('2024-06-28T00:00'), [1] )
yds= reform( ones(1), [1] )
print str(DataSetUtil.guessCadence(xds,yds))

