pvatfile_compile
ΒΆ
Compile the pvat file.
The traditional pvat file is in ascii format.
''' Compile the pvat file.
The traditional pvat file is in ascii format.
'''
import os
import random
import time
import gzip
import datetime
import pickle as pickle
import numpy as np
from irfpy.util.irfpyrc import Rc
import irfpy.cy1orb.Cy1Orbit
def check_open_textfile(basedir, nexam=1):
'''
'''
tlist = []
cols = list(range(23))
cols.pop(2)
for iexam in range(nexam):
onr = random.randrange(400, 3400)
fn = os.path.join(basedir, 'pvat_%04d.gz' % onr)
t0 = time.time()
f = gzip.open(fn)
val = np.loadtxt(f, usecols=cols)
t1 = time.time()
print(t1 - t0)
tlist.append(t1 - t0)
return tlist
def check_pvat2(nexam=1):
tlist = []
for iexam in range(nexam):
import irfpy.cy1orb.pvat2 as pvat
t0 = time.time()
pvat.getmepos(datetime.datetime(2009, 1, 1) + datetime.timedelta(days=iexam))
# pvat.getmepos(datetime.datetime(2009, 1, 1) + datetime.timedelta(days=iexam, minutes=10))
# pvat.getmepos(datetime.datetime(2009, 1, 1) + datetime.timedelta(days=iexam, minutes=15))
t1 = time.time()
print(t1 - t0)
tlist.append(t1 - t0)
return tlist
def check_compile(basedir, nexam=1):
cols = list(range(23))
cols.pop(2)
tlist = []
for iexam in range(nexam):
onr = random.randrange(400, 3400)
fn = os.path.join(basedir, 'pvat_%04d.gz' % onr)
f = gzip.open(fn)
print('Reading/Dumping. Not counted.')
val = np.loadtxt(f, usecols=cols)
f.close()
f = gzip.open('pvat_%04d.pickle.gz' % onr, 'w')
pickle.dump(val, f)
f.close()
f = gzip.open('pvat_%04d.pickle.gz' % onr)
t0 = time.time()
val = pickle.load(f)
t1 = time.time()
print(t1 - t0)
tlist.append(t1 - t0)
return tlist
def main():
'''Main script'''
rc = Rc()
basedir = rc.get('cy1orb', 'pvatbasedir')
print('Text file loaded by loadtxt')
tl0 = check_open_textfile(basedir, 0)
print('Data obtained by pvat2')
tl1 = check_pvat2(0)
print('Data compiled to a pickle file')
tl2 = check_compile(basedir, 10)
if __name__ == "__main__":
main()