Skip to content

Instantly share code, notes, and snippets.

@robintw
Last active August 29, 2015 14:01
Show Gist options
  • Save robintw/d0a2ed285da634688682 to your computer and use it in GitHub Desktop.
Save robintw/d0a2ed285da634688682 to your computer and use it in GitHub Desktop.
Comparison of ARCSI code with/without parallelisation
# Simple test of method used in current ARCSI code (old_method)
# and Py6S parallelisation (new_method)
# Results from running it on my (relatively old, dual-core) MacBook Pro:
# old_method: 21.1s
# new_method: 10.6s
#
# We get roughly the 2x speed up that you'd expect with two cores.
#
# Running on my work machine which has 8 cores I get:
# old_method: 11s
# new_method: 3.41s
#
# The speedup isn't anywhere near 8x (so it doesn't scale perfectly)
# but a 3x speedup isn't bad
import Py6S
s = Py6S.SixS()
s.altitudes.set_target_sea_level()
s.altitudes.set_sensor_satellite_level()
s.atmos_corr = Py6S.AtmosCorr.AtmosCorrLambertianFromRadiance(100)
def old_method():
sixsCoeffs = numpy.zeros((6, 3), dtype=numpy.float32)
# Band 1
s.wavelength = Py6S.Wavelength(Py6S.SixSHelpers.PredefinedWavelengths.LANDSAT_ETM_B1)
s.run()
sixsCoeffs[0,0] = float(s.outputs.values['coef_xa'])
sixsCoeffs[0,1] = float(s.outputs.values['coef_xb'])
sixsCoeffs[0,2] = float(s.outputs.values['coef_xc'])
# Band 2
s.wavelength = Py6S.Wavelength(Py6S.SixSHelpers.PredefinedWavelengths.LANDSAT_ETM_B2)
s.run()
sixsCoeffs[1,0] = float(s.outputs.values['coef_xa'])
sixsCoeffs[1,1] = float(s.outputs.values['coef_xb'])
sixsCoeffs[1,2] = float(s.outputs.values['coef_xc'])
# Band 3
s.wavelength = Py6S.Wavelength(Py6S.SixSHelpers.PredefinedWavelengths.LANDSAT_ETM_B3)
s.run()
sixsCoeffs[2,0] = float(s.outputs.values['coef_xa'])
sixsCoeffs[2,1] = float(s.outputs.values['coef_xb'])
sixsCoeffs[2,2] = float(s.outputs.values['coef_xc'])
# Band 4
s.wavelength = Py6S.Wavelength(Py6S.SixSHelpers.PredefinedWavelengths.LANDSAT_ETM_B4)
s.run()
sixsCoeffs[3,0] = float(s.outputs.values['coef_xa'])
sixsCoeffs[3,1] = float(s.outputs.values['coef_xb'])
sixsCoeffs[3,2] = float(s.outputs.values['coef_xc'])
# Band 5
s.wavelength = Py6S.Wavelength(Py6S.SixSHelpers.PredefinedWavelengths.LANDSAT_ETM_B5)
s.run()
sixsCoeffs[4,0] = float(s.outputs.values['coef_xa'])
sixsCoeffs[4,1] = float(s.outputs.values['coef_xb'])
sixsCoeffs[4,2] = float(s.outputs.values['coef_xc'])
# Band 7
s.wavelength = Py6S.Wavelength(Py6S.SixSHelpers.PredefinedWavelengths.LANDSAT_ETM_B7)
s.run()
sixsCoeffs[5,0] = float(s.outputs.values['coef_xa'])
sixsCoeffs[5,1] = float(s.outputs.values['coef_xb'])
sixsCoeffs[5,2] = float(s.outputs.values['coef_xc'])
return sixsCoeffs
def new_method():
sixsCoeffs = numpy.zeros((6, 3), dtype=numpy.float32)
wavelengths, results = Py6S.SixSHelpers.Wavelengths.run_landsat_etm(s)
coef_xa = [getattr(r, 'coef_xa') for r in results]
coef_xb = [getattr(r, 'coef_xb') for r in results]
coef_xc = [getattr(r, 'coef_xc') for r in results]
sixsCoeffs[:, 0] = coef_xa
sixsCoeffs[:, 1] = coef_xb
sixsCoeffs[:, 2] = coef_xc
return sixsCoeffs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment