apps130226_orbit_finder.limit
ΒΆ
Test to limit the time when pvat is supported.
''' Test to limit the time when pvat is supported.
'''
import sys
import datetime
import irfpy.cy1orb.pvat2 as pvat
def main():
'''Main script
Too slow to be used. Taking 7-8 sec.
'''
t0 = datetime.datetime(2010, 1, 1, 0) # Much after CY1 project.
t1 = datetime.datetime(2008, 1, 1, 0) # Much before CY1 project.
tc = datetime.datetime(2009, 4, 1, 0) # Inside the CY1 project.
try:
pvat.getlsepos(tc)
except RuntimeError as e:
print('Failed to load the data. Please fix as pvat2 works.', file=sys.stderr)
print(e, file=sys.stderr)
sys.exit(-1)
dtlim = datetime.timedelta(microseconds=100000)
### Max date available
tup = t0
tdn = tc
dt = tup - tdn
while dt > dtlim:
texam = tdn + dt / 2
# print tup, tdn, texam, dt
try:
pvat.getlsepos(texam)
except (RuntimeError, IOError) as e:
tup = texam
else:
tdn = texam
dt = tup - tdn
tmax = tdn
### Min date available
tup = tc
tdn = t1
dt = tup - tdn
while dt > dtlim:
texam = tdn + dt / 2
# print tup, tdn, texam, dt
try:
pvat.getlsepos(texam)
except (RuntimeError, IOError) as e:
tdn = texam
else:
tup = texam
dt = tup - tdn
tmin = tup
return tmin, tmax
def main2():
''' The second idea of retrieving start/stop datetime of pvat data.
Acceptable ~1s time scale. It is now used as :func:`irfpy.util.pvat2.getdatarange`.
'''
import urllib.request, urllib.parse, urllib.error
import irfpy.util.irfpyrc
import irfpy.util.utc
import irfpy.util.julday
import irfpy.cy1orb.Cy1Orbit
rc = irfpy.util.irfpyrc.Rc()
path = rc.get('cy1orb', 'pvatbase')
print(path)
i = 0
while i < 10000: # At a certain point, you have to be stopped.
try:
uri = path + '/pvat_%04d.gz' % i
urllib.request.urlretrieve(uri)
except:
i += 1
continue
print('First orbit is %d' % i)
oi = irfpy.cy1orb.Cy1Orbit.Cy1Orbit()
t0 = oi.getPosOfOrb(i)[0, 0]
print(t0)
t0 = irfpy.util.utc.convert(irfpy.util.julday.Julday(t0), datetime.datetime)
print(t0)
break
while i < 10000:
try:
uri = path + '/pvat_%04d.gz' % i
urllib.request.urlretrieve(uri)
except:
print('Last orbit is %d' % (i - 1))
oi = irfpy.cy1orb.Cy1Orbit.Cy1Orbit()
t1 = oi.getPosOfOrb(i - 1)[0, -1]
print(t1)
t1 = irfpy.util.utc.convert(irfpy.util.julday.Julday(t1), datetime.datetime)
print(t1)
break
else:
i += 1
return t0, t1
if __name__ == "__main__":
print(main2())