#NEWLINE# def __init__( self , data_cube , lookup_scheme_name = None , tile_type_id = 1 , satellite_tag = None , sensor_name = None , level_name = None ) : #NEWLINE# #INDENT# '\n        Constructor for BandLookup class\n        Parameters (can all be set later with the exception of data_cube):\n             data_cube: Parent data_cube (or descendant) object \n             lookup_scheme_name: lookup scheme name. Needs to be a member of self.lookup_schemes \n             tile_type_id: Tile Type identifier. Defaults to 1 - should this be None?\n             satellite_tag: Short name of satellite \n             sensor_name: Name of sensor\n             level_name: Processing level name\n        ' #NEWLINE# assert isinstance ( data_cube , DataCube ) , 'data_cube parameter must be of type DataCube' #NEWLINE# assert ( ( not lookup_scheme_name ) or ( type ( lookup_scheme_name ) == str ) ) , 'lookup_scheme_name parameter must be of type str' #NEWLINE# assert ( ( not tile_type_id ) or ( type ( tile_type_id ) in ( long , int ) ) ) , 'tile_type_id parameter must be of type long or int' #NEWLINE# assert ( ( not satellite_tag ) or ( type ( satellite_tag ) == str ) ) , 'satellite_tag parameter must be of type str' #NEWLINE# assert ( ( not sensor_name ) or ( type ( sensor_name ) == str ) ) , 'sensor_name parameter must be of type str' #NEWLINE# assert ( ( not level_name ) or ( type ( level_name ) == str ) ) , 'level_name parameter must be of type str' #NEWLINE# if data_cube . debug : #NEWLINE# #INDENT# console_handler . setLevel ( logging . DEBUG ) #NEWLINE# #UNINDENT# self . lookup_scheme_name = lookup_scheme_name #NEWLINE# self . tile_type_id = tile_type_id #NEWLINE# self . satellite_tag = satellite_tag #NEWLINE# self . sensor_name = sensor_name #NEWLINE# self . level_name = level_name #NEWLINE# self . db_connection = data_cube . db_connection #NEWLINE# db_cursor = self . db_connection . cursor ( ) #NEWLINE# if ( not BandLookup . _band_lookup_dict ) : #NEWLINE# #INDENT# sql = "-- Retrieve all band equivalence information\n SELECT\n    band_lookup_scheme.lookup_scheme_name,\n    band_source.tile_type_id,\n    coalesce(satellite.satellite_tag, 'DERIVED') as satellite_tag,\n    coalesce(sensor_name, level_name) as sensor_name,\n    processing_level.level_name,\n    band_equivalent.master_band_tag,\n    band_source.tile_layer,\n    band_equivalent.nominal_centre::float,\n    band_equivalent.nominal_bandwidth::float,\n    band_equivalent.centre_tolerance::float,\n    band_equivalent.bandwidth_tolerance::float,\n    COALESCE(band_adjustment.adjustment_offset, 0.0)::float AS adjustment_offset,\n    COALESCE(band_adjustment.adjustment_multiplier, 1.0)::float AS adjustment_multiplier,\n    band_lookup_scheme.lookup_scheme_id,\n    band.satellite_id,\n    band.sensor_id,\n    band.band_id,\n    band_equivalent.master_band_name,\n    band_type_name,\n    band.min_wavelength::float,\n    band.max_wavelength::float,\n    band_lookup_scheme.lookup_scheme_description\n   FROM band\n   JOIN band_type using(band_type_id)\n   JOIN band_source using (band_id)\n   JOIN processing_level using(level_id)\n   JOIN band_equivalent ON band_equivalent.band_type_id = band.band_type_id\n     and abs((band.max_wavelength::numeric + band.min_wavelength::numeric) / 2.0 - band_equivalent.nominal_centre) <= band_equivalent.centre_tolerance \n     AND abs(band.max_wavelength::numeric - band.min_wavelength::numeric - band_equivalent.nominal_bandwidth) <= band_equivalent.bandwidth_tolerance\n   JOIN band_lookup_scheme USING (lookup_scheme_id)\n   LEFT JOIN band_adjustment USING (lookup_scheme_id, band_id)\n   LEFT JOIN sensor using(satellite_id, sensor_id)\n   LEFT JOIN satellite using(satellite_id)\n   ORDER BY 1,2,3,4,5,7\n" #NEWLINE# log_multiline ( logger . debug , sql , 'SQL' , '\t' ) #NEWLINE# db_cursor . execute ( sql ) #NEWLINE# for record in db_cursor : #NEWLINE# #INDENT# lookup_scheme_dict = BandLookup . _band_lookup_dict . get ( record [ 0 ] ) #NEWLINE# if ( lookup_scheme_dict is None ) : #NEWLINE# #INDENT# lookup_scheme_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# BandLookup . _band_lookup_dict [ record [ 0 ] ] = lookup_scheme_dict #NEWLINE# BandLookup . _lookup_schemes [ record [ 0 ] ] = record [ 21 ] #NEWLINE# #UNINDENT# tile_type_id_dict = lookup_scheme_dict . get ( record [ 1 ] ) #NEWLINE# if ( self is None ) : #NEWLINE# #INDENT# tile_type_id_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# lookup_scheme_dict [ record [ 1 ] ] = tile_type_id_dict #NEWLINE# #UNINDENT# satellite_tag_dict = tile_type_id_dict . get ( record [ 2 ] ) #NEWLINE# if ( satellite_tag_dict is None ) : #NEWLINE# #INDENT# satellite_tag_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# tile_type_id_dict [ record [ 2 ] ] = satellite_tag_dict #NEWLINE# #UNINDENT# sensor_name_dict = satellite_tag_dict . get ( record [ 3 ] ) #NEWLINE# if ( sensor_name_dict is None ) : #NEWLINE# #INDENT# sensor_name_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# satellite_tag_dict [ record [ 3 ] ] = sensor_name_dict #NEWLINE# #UNINDENT# level_name_dict = sensor_name_dict . get ( record [ 4 ] ) #NEWLINE# if ( level_name_dict is None ) : #NEWLINE# #INDENT# level_name_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# sensor_name_dict [ record [ 4 ] ] = level_name_dict #NEWLINE# #UNINDENT# assert ( level_name_dict . get ( record [ 5 ] ) is None ) , 'Duplicated band_tag record' #NEWLINE# level_name_dict [ record [ 5 ] ] = { #NEWLINE# #INDENT# 'tile_layer' : record [ 6 ] , #NEWLINE# 'nominal_centre' : record [ 7 ] , #NEWLINE# 'nominal_bandwidth' : record [ 8 ] , #NEWLINE# 'centre_tolerance' : record [ 9 ] , #NEWLINE# 'bandwidth_tolerance' : record [ 10 ] , #NEWLINE# 'adjustment_offset' : record [ 11 ] , #NEWLINE# 'adjustment_multiplier' : record [ 12 ] , #NEWLINE# 'lookup_scheme_id' : record [ 13 ] , #NEWLINE# 'satellite_id' : record [ 14 ] , #NEWLINE# 'sensor_id' : record [ 15 ] , #NEWLINE# 'band_id' : record [ 16 ] , #NEWLINE# 'master_band_name' : record [ 17 ] , #NEWLINE# 'band_type_name' : record [ 18 ] , #NEWLINE# 'min_wavelength' : record [ 19 ] , #NEWLINE# 'max_wavelength' : record [ 20 ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# log_multiline ( logger . debug , BandLookup . _band_lookup_dict , 'BandLookup._band_lookup_dict' , '\t' )