<s> '''<STR_LIT>''' <EOL> import os <EOL> import sys <EOL> import argparse <EOL> import logging <EOL> import re <EOL> import psycopg2 <EOL> import numpy <EOL> import shutil <EOL> from osgeo import gdal , osr <EOL> from math import floor , ceil <EOL> from datetime import datetime <EOL> from copy import copy <EOL> import time <EOL> import numexpr <EOL> from scipy import ndimage <EOL> from EOtools . bodies . vincenty import vinc_dist <EOL> from EOtools . blrb import interpolate_grid <EOL> from EOtools . utils import log_multiline <EOL> from EOtools . execute import execute <EOL> from agdc import DataCube <EOL> console_handler = logging . StreamHandler ( sys . stdout ) <EOL> console_handler . setLevel ( logging . INFO ) <EOL> console_formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> console_handler . setFormatter ( console_formatter ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> if not logger . level : <EOL> logger . setLevel ( logging . DEBUG ) <EOL> logger . addHandler ( console_handler ) <EOL> CONTIGUITY_BIT_INDEX = <NUM_LIT:8> <EOL> nan = numpy . float32 ( numpy . NaN ) <EOL> RADIANS_PER_DEGREE = <NUM_LIT> <EOL> class earth ( object ) : <EOL> RADIUS = <NUM_LIT> <EOL> SEMI_MAJOR_AXIS = <NUM_LIT> <EOL> A = <NUM_LIT> <EOL> B = <NUM_LIT> <EOL> F = ( A - B ) / A <EOL> ECC2 = <NUM_LIT:1.0> - B ** <NUM_LIT:2> / A ** <NUM_LIT:2> <EOL> MEAN_RADIUS = ( A * <NUM_LIT:2> + B ) / <NUM_LIT:3> <EOL> OMEGA = <NUM_LIT> <EOL> class DEMTiler ( DataCube ) : <EOL> def getFileSizekB ( self , path ) : <EOL> """<STR_LIT>""" <EOL> return os . path . getsize ( path ) / <NUM_LIT> <EOL> def getFileSizeMB ( self , path ) : <EOL> """<STR_LIT>""" <EOL> return self . getFileSizekB ( path ) / <NUM_LIT> <EOL> def parse_args ( self ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( '<STR_LIT>' ) <EOL> _arg_parser = argparse . ArgumentParser ( '<STR_LIT>' ) <EOL> _arg_parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> default = os . path . join ( self . agdc_root , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' ) <EOL> _arg_parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> default = False , action = '<STR_LIT>' , const = True , <EOL> help = '<STR_LIT>' ) <EOL> _arg_parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> default = True , action = '<STR_LIT>' , const = True , <EOL> help = '<STR_LIT>' ) <EOL> _arg_parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> required = False , default = None , <EOL> help = '<STR_LIT>' ) <EOL> _arg_parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:filename>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> _arg_parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> return _arg_parser . parse_args ( ) <EOL> def get_pixel_size ( self , dataset , ( x , y ) ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( '<STR_LIT>' , x , y ) <EOL> spatial_reference = osr . SpatialReference ( ) <EOL> spatial_reference . ImportFromWkt ( dataset . GetProjection ( ) ) <EOL> geotransform = dataset . GetGeoTransform ( ) <EOL> logger . debug ( '<STR_LIT>' , geotransform ) <EOL> latlong_spatial_reference = spatial_reference . CloneGeogCS ( ) <EOL> coord_transform_to_latlong = osr . CoordinateTransformation ( spatial_reference , latlong_spatial_reference ) <EOL> xw = geotransform [ <NUM_LIT:0> ] + x * geotransform [ <NUM_LIT:1> ] <EOL> yn = geotransform [ <NUM_LIT:3> ] + y * geotransform [ <NUM_LIT:5> ] <EOL> xc = geotransform [ <NUM_LIT:0> ] + ( x + <NUM_LIT:0.5> ) * geotransform [ <NUM_LIT:1> ] <EOL> yc = geotransform [ <NUM_LIT:3> ] + ( y + <NUM_LIT:0.5> ) * geotransform [ <NUM_LIT:5> ] <EOL> xe = geotransform [ <NUM_LIT:0> ] + ( x + <NUM_LIT:1.0> ) * geotransform [ <NUM_LIT:1> ] <EOL> ys = geotransform [ <NUM_LIT:3> ] + ( y + <NUM_LIT:1.0> ) * geotransform [ <NUM_LIT:5> ] <EOL> logger . debug ( '<STR_LIT>' , xw , yn , xc , yc , xe , ys ) <EOL> lon1 , lat1 , _z = coord_transform_to_latlong . TransformPoint ( xw , yc , <NUM_LIT:0> ) <EOL> lon2 , lat2 , _z = coord_transform_to_latlong . TransformPoint ( xe , yc , <NUM_LIT:0> ) <EOL> logger . debug ( '<STR_LIT>' , lon1 , lat1 , lon2 , lat2 ) <EOL> x_size , _az_to , _az_from = vinc_dist ( earth . F , earth . A , <EOL> lat1 * RADIANS_PER_DEGREE , lon1 * RADIANS_PER_DEGREE , <EOL> lat2 * RADIANS_PER_DEGREE , lon2 * RADIANS_PER_DEGREE ) <EOL> lon1 , lat1 , _z = coord_transform_to_latlong . TransformPoint ( xc , yn , <NUM_LIT:0> ) <EOL> lon2 , lat2 , _z = coord_transform_to_latlong . TransformPoint ( xc , ys , <NUM_LIT:0> ) <EOL> logger . debug ( '<STR_LIT>' , lon1 , lat1 , lon2 , lat2 ) <EOL> y_size , _az_to , _az_from = vinc_dist ( earth . F , earth . A , <EOL> lat1 * RADIANS_PER_DEGREE , lon1 * RADIANS_PER_DEGREE , <EOL> lat2 * RADIANS_PER_DEGREE , lon2 * RADIANS_PER_DEGREE ) <EOL> logger . debug ( '<STR_LIT>' , x_size , y_size ) <EOL> return ( x_size , y_size ) <EOL> def get_pixel_size_grids ( self , dataset ) : <EOL> """<STR_LIT>""" <EOL> def get_pixel_x_size ( x , y ) : <EOL> return self . get_pixel_size ( dataset , ( x , y ) ) [ <NUM_LIT:0> ] <EOL> def get_pixel_y_size ( x , y ) : <EOL> return self . get_pixel_size ( dataset , ( x , y ) ) [ <NUM_LIT:1> ] <EOL> x_size_grid = numpy . zeros ( ( dataset . RasterXSize , dataset . RasterYSize ) ) . astype ( numpy . float32 ) <EOL> interpolate_grid ( depth = <NUM_LIT:1> , shape = x_size_grid . shape , eval_func = get_pixel_x_size , grid = x_size_grid ) <EOL> y_size_grid = numpy . zeros ( ( dataset . RasterXSize , dataset . RasterYSize ) ) . astype ( numpy . float32 ) <EOL> interpolate_grid ( depth = <NUM_LIT:1> , shape = y_size_grid . shape , eval_func = get_pixel_y_size , grid = y_size_grid ) <EOL> return ( x_size_grid , y_size_grid ) <EOL> def __init__ ( self , source_datacube = None , default_tile_type_id = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if source_datacube : <EOL> self . __dict__ = copy ( source_datacube . __dict__ ) <EOL> args = self . parse_args ( ) <EOL> for attribute_name in args . __dict__ . keys ( ) : <EOL> attribute_value = args . __dict__ [ attribute_name ] <EOL> self . __setattr__ ( attribute_name , attribute_value ) <EOL> else : <EOL> DataCube . __init__ ( self ) ; <EOL> if self . debug : <EOL> console_handler . setLevel ( logging . DEBUG ) <EOL> self . db_connection . autocommit = False <EOL> self . db_connection . set_isolation_level ( psycopg2 . extensions . ISOLATION_LEVEL_READ_COMMITTED ) <EOL> try : <EOL> self . default_tile_type_id = int ( self . default_tile_type_id ) <EOL> except : <EOL> self . default_tile_type_id = default_tile_type_id <EOL> try : <EOL> self . start_date = datetime . strptime ( self . start_date , '<STR_LIT>' ) . date ( ) <EOL> except : <EOL> self . start_date = None <EOL> try : <EOL> self . end_date = datetime . strptime ( self . end_date , '<STR_LIT>' ) . date ( ) <EOL> except : <EOL> self . end_date = None <EOL> try : <EOL> self . min_path = int ( self . min_path ) <EOL> except : <EOL> self . min_path = None <EOL> try : <EOL> self . max_path = int ( self . max_path ) <EOL> except : <EOL> self . max_path = None <EOL> try : <EOL> self . min_row = int ( self . min_row ) <EOL> except : <EOL> self . min_row = None <EOL> try : <EOL> self . max_row = int ( self . max_row ) <EOL> except : <EOL> self . max_row = None <EOL> def create_tiles ( self , filename = None , level_name = None , tile_type_id = None ) : <EOL> filename = filename or self . filename <EOL> level_name = level_name or self . level_name <EOL> tile_type_id = tile_type_id or self . default_tile_type_id <EOL> nodata_value = None <EOL> tile_type_info = self . tile_type_dict [ tile_type_id ] <EOL> dem_band_info = self . bands [ tile_type_id ] . get ( ( '<STR_LIT>' , level_name ) ) <EOL> assert dem_band_info , '<STR_LIT>' % level_name <EOL> def find_tiles ( x_index = None , y_index = None ) : <EOL> """<STR_LIT>""" <EOL> db_cursor2 = self . db_connection . cursor ( ) <EOL> sql = """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : x_index , <EOL> '<STR_LIT>' : y_index , <EOL> '<STR_LIT>' : tile_type_info [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : level_name } <EOL> log_multiline ( logger . debug , db_cursor2 . mogrify ( sql , params ) , '<STR_LIT>' , '<STR_LIT:\t>' ) <EOL> db_cursor2 . execute ( sql , params ) <EOL> tile_info = { } <EOL> for record in db_cursor2 : <EOL> tile_info_dict = { <EOL> '<STR_LIT>' : record [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : record [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : record [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : record [ <NUM_LIT:4> ] , <EOL> '<STR_LIT>' : record [ <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : record [ <NUM_LIT:6> ] , <EOL> '<STR_LIT>' : record [ <NUM_LIT:7> ] <EOL> } <EOL> tile_info [ record [ <NUM_LIT:0> ] ] = tile_info_dict <EOL> log_multiline ( logger . debug , tile_info , '<STR_LIT>' , '<STR_LIT:\t>' ) <EOL> return tile_info <EOL> db_cursor = self . db_connection . cursor ( ) <EOL> dataset = gdal . Open ( filename ) <EOL> assert dataset , '<STR_LIT>' % filename <EOL> spatial_reference = osr . SpatialReference ( ) <EOL> spatial_reference . ImportFromWkt ( dataset . GetProjection ( ) ) <EOL> geotransform = dataset . GetGeoTransform ( ) <EOL> logger . debug ( '<STR_LIT>' , geotransform ) <EOL> latlong_spatial_reference = spatial_reference . CloneGeogCS ( ) <EOL> coord_transform_to_latlong = osr . CoordinateTransformation ( spatial_reference , latlong_spatial_reference ) <EOL> tile_spatial_reference = osr . SpatialReference ( ) <EOL> s = re . match ( '<STR_LIT>' , tile_type_info [ '<STR_LIT>' ] ) <EOL> if s : <EOL> epsg_code = int ( s . group ( <NUM_LIT:1> ) ) <EOL> logger . debug ( '<STR_LIT>' , epsg_code ) <EOL> assert tile_spatial_reference . ImportFromEPSG ( epsg_code ) == <NUM_LIT:0> , '<STR_LIT>' <EOL> else : <EOL> assert tile_spatial_reference . ImportFromWkt ( tile_type_info [ '<STR_LIT>' ] ) , '<STR_LIT>' <EOL> logger . debug ( '<STR_LIT>' , tile_spatial_reference . ExportToWkt ( ) ) <EOL> coord_transform_to_tile = osr . CoordinateTransformation ( spatial_reference , tile_spatial_reference ) <EOL> ul_x , ul_y = geotransform [ <NUM_LIT:0> ] , geotransform [ <NUM_LIT:3> ] <EOL> ul_lon , ul_lat , _z = coord_transform_to_latlong . TransformPoint ( ul_x , ul_y , <NUM_LIT:0> ) <EOL> tile_ul_x , tile_ul_y , _z = coord_transform_to_tile . TransformPoint ( ul_x , ul_y , <NUM_LIT:0> ) <EOL> ur_x , ur_y = geotransform [ <NUM_LIT:0> ] + geotransform [ <NUM_LIT:1> ] * dataset . RasterXSize , geotransform [ <NUM_LIT:3> ] <EOL> ur_lon , ur_lat , _z = coord_transform_to_latlong . TransformPoint ( ur_x , ur_y , <NUM_LIT:0> ) <EOL> tile_ur_x , tile_ur_y , _z = coord_transform_to_tile . TransformPoint ( ur_x , ur_y , <NUM_LIT:0> ) <EOL> lr_x , lr_y = geotransform [ <NUM_LIT:0> ] + geotransform [ <NUM_LIT:1> ] * dataset . RasterXSize , geotransform [ <NUM_LIT:3> ] + geotransform [ <NUM_LIT:5> ] * dataset . RasterYSize <EOL> lr_lon , lr_lat , _z = coord_transform_to_latlong . TransformPoint ( lr_x , lr_y , <NUM_LIT:0> ) <EOL> tile_lr_x , tile_lr_y , _z = coord_transform_to_tile . TransformPoint ( lr_x , lr_y , <NUM_LIT:0> ) <EOL> ll_x , ll_y = geotransform [ <NUM_LIT:0> ] , geotransform [ <NUM_LIT:3> ] + geotransform [ <NUM_LIT:5> ] * dataset . RasterYSize <EOL> ll_lon , ll_lat , _z = coord_transform_to_latlong . TransformPoint ( ll_x , ll_y , <NUM_LIT:0> ) <EOL> tile_ll_x , tile_ll_y , _z = coord_transform_to_tile . TransformPoint ( ll_x , ll_y , <NUM_LIT:0> ) <EOL> tile_min_x = min ( tile_ul_x , tile_ll_x ) <EOL> tile_max_x = max ( tile_ur_x , tile_lr_x ) <EOL> tile_min_y = min ( tile_ll_y , tile_lr_y ) <EOL> tile_max_y = max ( tile_ul_y , tile_ur_y ) <EOL> tile_index_range = ( int ( floor ( ( tile_min_x - tile_type_info [ '<STR_LIT>' ] ) / tile_type_info [ '<STR_LIT>' ] ) ) , <EOL> int ( floor ( ( tile_min_y - tile_type_info [ '<STR_LIT>' ] ) / tile_type_info [ '<STR_LIT>' ] ) ) , <EOL> int ( ceil ( ( tile_max_x - tile_type_info [ '<STR_LIT>' ] ) / tile_type_info [ '<STR_LIT>' ] ) ) , <EOL> int ( ceil ( ( tile_max_y - tile_type_info [ '<STR_LIT>' ] ) / tile_type_info [ '<STR_LIT>' ] ) ) ) <EOL> sql = """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : os . path . basename ( filename ) } <EOL> log_multiline ( logger . debug , db_cursor . mogrify ( sql , params ) , '<STR_LIT>' , '<STR_LIT:\t>' ) <EOL> db_cursor . execute ( sql , params ) <EOL> result = db_cursor . fetchone ( ) <EOL> if result : <EOL> dataset_id = result [ <NUM_LIT:0> ] <EOL> if self . refresh : <EOL> logger . info ( '<STR_LIT>' , filename ) <EOL> sql = """<STR_LIT>""" <EOL> else : <EOL> logger . info ( '<STR_LIT>' , filename ) <EOL> return <EOL> else : <EOL> logger . info ( '<STR_LIT>' , filename ) <EOL> dataset_id = None <EOL> sql = """<STR_LIT>""" <EOL> dataset_size = self . getFileSizekB ( filename ) <EOL> params = { '<STR_LIT>' : dataset_id , <EOL> '<STR_LIT>' : filename , <EOL> '<STR_LIT>' : level_name , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : dataset_size , <EOL> '<STR_LIT>' : ll_lon , <EOL> '<STR_LIT>' : ll_lat , <EOL> '<STR_LIT>' : lr_lon , <EOL> '<STR_LIT>' : lr_lat , <EOL> '<STR_LIT>' : ul_lon , <EOL> '<STR_LIT>' : ul_lat , <EOL> '<STR_LIT>' : ur_lon , <EOL> '<STR_LIT>' : ur_lat , <EOL> '<STR_LIT>' : dataset . GetProjection ( ) , <EOL> '<STR_LIT>' : ll_x , <EOL> '<STR_LIT>' : ll_y , <EOL> '<STR_LIT>' : lr_x , <EOL> '<STR_LIT>' : lr_y , <EOL> '<STR_LIT>' : ul_x , <EOL> '<STR_LIT>' : ul_y , <EOL> '<STR_LIT>' : ur_x , <EOL> '<STR_LIT>' : ur_y , <EOL> '<STR_LIT>' : dataset . RasterXSize , <EOL> '<STR_LIT>' : dataset . RasterYSize , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None <EOL> } <EOL> log_multiline ( logger . debug , db_cursor . mogrify ( sql , params ) , '<STR_LIT>' , '<STR_LIT:\t>' ) <EOL> db_cursor . execute ( sql , params ) <EOL> result = db_cursor . fetchone ( ) <EOL> dataset_id = dataset_id or result [ <NUM_LIT:0> ] <EOL> tile_output_root = os . path . join ( self . tile_root , <EOL> tile_type_info [ '<STR_LIT>' ] , <EOL> level_name , <EOL> os . path . basename ( filename ) <EOL> ) <EOL> logger . debug ( '<STR_LIT>' , tile_output_root ) <EOL> self . create_directory ( tile_output_root ) <EOL> work_directory = os . path . join ( self . temp_dir , <EOL> os . path . basename ( filename ) <EOL> ) <EOL> logger . debug ( '<STR_LIT>' , work_directory ) <EOL> self . create_directory ( work_directory ) <EOL> for x_index in range ( tile_index_range [ <NUM_LIT:0> ] , tile_index_range [ <NUM_LIT:2> ] ) : <EOL> for y_index in range ( tile_index_range [ <NUM_LIT:1> ] , tile_index_range [ <NUM_LIT:3> ] ) : <EOL> tile_info = find_tiles ( x_index , y_index ) <EOL> if tile_info : <EOL> logger . info ( '<STR_LIT>' , x_index , y_index ) <EOL> continue <EOL> tile_basename = '<STR_LIT:_>' . join ( [ level_name , <EOL> re . sub ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % ( x_index , y_index ) ) ] ) + tile_type_info [ '<STR_LIT>' ] <EOL> tile_output_path = os . path . join ( tile_output_root , tile_basename ) <EOL> if not self . lock_object ( tile_output_path ) : <EOL> logger . warning ( '<STR_LIT>' , tile_output_path ) <EOL> continue <EOL> try : <EOL> self . remove ( tile_output_path ) <EOL> temp_tile_path = os . path . join ( self . temp_dir , tile_basename ) <EOL> tile_extents = ( tile_type_info [ '<STR_LIT>' ] + x_index * tile_type_info [ '<STR_LIT>' ] , <EOL> tile_type_info [ '<STR_LIT>' ] + y_index * tile_type_info [ '<STR_LIT>' ] , <EOL> tile_type_info [ '<STR_LIT>' ] + ( x_index + <NUM_LIT:1> ) * tile_type_info [ '<STR_LIT>' ] , <EOL> tile_type_info [ '<STR_LIT>' ] + ( y_index + <NUM_LIT:1> ) * tile_type_info [ '<STR_LIT>' ] ) <EOL> logger . debug ( '<STR_LIT>' , tile_extents ) <EOL> command_string = '<STR_LIT>' <EOL> if not self . debug : <EOL> command_string += '<STR_LIT>' <EOL> command_string += '<STR_LIT>' % ( <EOL> tile_type_info [ '<STR_LIT>' ] , <EOL> tile_extents [ <NUM_LIT:0> ] , tile_extents [ <NUM_LIT:1> ] , tile_extents [ <NUM_LIT:2> ] , tile_extents [ <NUM_LIT:3> ] , <EOL> tile_type_info [ '<STR_LIT>' ] , tile_type_info [ '<STR_LIT>' ] , <EOL> dem_band_info [ <NUM_LIT:10> ] [ '<STR_LIT>' ] <EOL> ) <EOL> if nodata_value is not None : <EOL> command_string += '<STR_LIT>' % ( nodata_value , nodata_value ) <EOL> command_string += '<STR_LIT>' % tile_type_info [ '<STR_LIT>' ] <EOL> if tile_type_info [ '<STR_LIT>' ] : <EOL> for format_option in tile_type_info [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> command_string += '<STR_LIT>' % format_option <EOL> command_string += '<STR_LIT>' % ( <EOL> filename , <EOL> temp_tile_path <EOL> ) <EOL> logger . debug ( '<STR_LIT>' , command_string ) <EOL> result = execute ( command_string = command_string ) <EOL> if result [ '<STR_LIT>' ] : <EOL> log_multiline ( logger . info , result [ '<STR_LIT>' ] , '<STR_LIT>' + command_string , '<STR_LIT:\t>' ) <EOL> if result [ '<STR_LIT>' ] : <EOL> log_multiline ( logger . error , result [ '<STR_LIT>' ] , '<STR_LIT>' + command_string , '<STR_LIT:\t>' ) <EOL> raise Exception ( '<STR_LIT>' , command_string ) <EOL> temp_dataset = gdal . Open ( temp_tile_path ) <EOL> gdal_driver = gdal . GetDriverByName ( tile_type_info [ '<STR_LIT>' ] ) <EOL> output_dataset = gdal_driver . Create ( tile_output_path , <EOL> temp_dataset . RasterXSize , temp_dataset . RasterYSize , <EOL> len ( dem_band_info ) , <EOL> temp_dataset . GetRasterBand ( <NUM_LIT:1> ) . DataType , <EOL> tile_type_info [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> assert output_dataset , '<STR_LIT>' % output_dataset <EOL> output_geotransform = temp_dataset . GetGeoTransform ( ) <EOL> output_dataset . SetGeoTransform ( output_geotransform ) <EOL> output_dataset . SetProjection ( temp_dataset . GetProjection ( ) ) <EOL> elevation_array = temp_dataset . GetRasterBand ( <NUM_LIT:1> ) . ReadAsArray ( ) <EOL> del temp_dataset <EOL> self . remove ( temp_tile_path ) <EOL> pixel_x_size = abs ( output_geotransform [ <NUM_LIT:1> ] ) <EOL> pixel_y_size = abs ( output_geotransform [ <NUM_LIT:5> ] ) <EOL> x_m_array , y_m_array = self . get_pixel_size_grids ( output_dataset ) <EOL> dzdx_array = ndimage . sobel ( elevation_array , axis = <NUM_LIT:1> ) / ( <NUM_LIT> * abs ( output_geotransform [ <NUM_LIT:1> ] ) ) <EOL> dzdx_array = numexpr . evaluate ( "<STR_LIT>" ) <EOL> del x_m_array <EOL> dzdy_array = ndimage . sobel ( elevation_array , axis = <NUM_LIT:0> ) / ( <NUM_LIT> * abs ( output_geotransform [ <NUM_LIT:5> ] ) ) <EOL> dzdy_array = numexpr . evaluate ( "<STR_LIT>" ) <EOL> del y_m_array <EOL> for band_file_number in sorted ( dem_band_info . keys ( ) ) : <EOL> output_band_number = dem_band_info [ band_file_number ] [ '<STR_LIT>' ] <EOL> output_band = output_dataset . GetRasterBand ( output_band_number ) <EOL> if band_file_number == <NUM_LIT:10> : <EOL> output_band . WriteArray ( elevation_array ) <EOL> del elevation_array <EOL> elif band_file_number == <NUM_LIT:20> : <EOL> hypotenuse_array = numpy . hypot ( dzdx_array , dzdy_array ) <EOL> slope_array = numexpr . evaluate ( "<STR_LIT>" ) <EOL> del hypotenuse_array <EOL> output_band . WriteArray ( slope_array ) <EOL> del slope_array <EOL> elif band_file_number == <NUM_LIT:30> : <EOL> aspect_array = numexpr . evaluate ( "<STR_LIT>" ) <EOL> output_band . WriteArray ( aspect_array ) <EOL> del aspect_array <EOL> if nodata_value is not None : <EOL> output_band . SetNoDataValue ( nodata_value ) <EOL> output_band . FlushCache ( ) <EOL> output_dataset . FlushCache ( ) <EOL> del output_dataset <EOL> logger . info ( '<STR_LIT>' , tile_output_path ) <EOL> tile_size = self . getFileSizeMB ( tile_output_path ) <EOL> sql = """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : x_index , <EOL> '<STR_LIT>' : y_index , <EOL> '<STR_LIT>' : tile_type_info [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : tile_extents [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : tile_extents [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : tile_extents [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : tile_extents [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : dataset_id , <EOL> '<STR_LIT>' : tile_output_path , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : tile_size <EOL> } <EOL> log_multiline ( logger . debug , db_cursor . mogrify ( sql , params ) , '<STR_LIT>' , '<STR_LIT:\t>' ) <EOL> db_cursor . execute ( sql , params ) <EOL> self . db_connection . commit ( ) <EOL> finally : <EOL> self . unlock_object ( tile_output_path ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dem_tiler = DEMTiler ( ) <EOL> dem_tiler . create_tiles ( ) </s>
