gridsphere_performanceΒΆ

Performance check for gridsphere

''' Performance check for gridsphere
'''
import time
import numpy as np
import irfpy.util.gridsphere

def gridsphere_each(lonlist, latlist, datlist):

    gs = irfpy.util.gridsphere.SimpleGridSphere()
    t0 = time.time()
    for lon, lat, dat in zip(lonlist, latlist, datlist):
        gs.append_value_lonlat(lon, lat, dat)
    t1 = time.time()

    return gs, t1 - t0
        
def gridsphere_list(lonlist, latlist, datlist):

    gs = irfpy.util.gridsphere.SimpleGridSphere()
    t0 = time.time()
    gs.append_values_lonlat(lonlist, latlist, datlist)
    t1 = time.time()

    return gs, t1 - t0

def main():
    '''Main script'''

    n = 50000
    lonlist = np.random.random(n) * 1800 - 900
    latlist = np.random.random(n) * 180 - 90
    datlist = np.arange(n)
    
    ge, te = gridsphere_each(lonlist, latlist, datlist)
    gl, tl = gridsphere_list(lonlist, latlist, datlist)

    print('Each=', te, 'sec')
    print('List=', tl, 'sec')

    print((ge.get_counts() == gl.get_counts()).all())
    print((ge.get_average() == gl.get_average()).all())

if __name__ == "__main__":
    main()