Changeset c04676b


Ignore:
Timestamp:
Apr 19, 2020, 6:20:04 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
f0e8020
Parents:
2a31181
Message:

Fixed pep8 errors

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/gnuboat/common/datahandler/loghandler.py

    r2a31181 rc04676b  
    8888        nmea_file_date_should = datetime.datetime.utcnow().strftime("%Y-%m-%d")
    8989        mode = 'A'
    90         if self._nmea_file == None or self._nmea_file_date is None or self._nmea_file_date != nmea_file_date_should:
     90        if (self._nmea_file is None or self._nmea_file_date is None or
     91                self._nmea_file_date != nmea_file_date_should):
    9192            if self._nmea_file:
    9293                self._nmea_file.close()
    … …  
    189190        }
    190191
    191     """ Reads the original gnuboat log files and calls a callable function on all complete LogDataset
    192                 callback must be of a function wich excepts the LogDataset as a parameter.
    193         """
    194 
    195192    def gnuboat_read_file(
    196193        self,
    … …  
    200197        errors_ignore=False
    201198    ):
     199        """
     200            Reads the original gnuboat log files and calls a callable function
     201            on all complete LogDataset callback must be of a function wich
     202            excepts the LogDataset as a parameter.
     203        """
    202204        result = LogParsingResult()
    203205
    … …  
    217219        return result
    218220
    219     """ Reads the original gnuboat log from input_list and calls a callable function on all complete LogDataset
    220                 callback must be of a function wich excepts the LogDataset as a parameter.
    221         """
    222 
    223221    def gnuboat_read(
    224222        self, input_list, callback, checksums_fix=False, errors_ignore=False
    225223    ):
     224        """
     225            Reads the original gnuboat log from input_list and calls a callable
     226            function on all complete LogDataset callback must be of a function
     227            wich excepts the LogDataset as a parameter.
     228        """
    226229        result = LogParsingResult()
    227230
    … …  
    272275                    last_row.water_depth_set(None)
    273276                    last_row.water_temperature_set(None)
    274                 elif nmea_sentence.sentence_type == 'DPT' and last_row is not None:
     277                elif (nmea_sentence.sentence_type == 'DPT' and
     278                      last_row is not None):
    275279                    last_row.water_depth_set(
    276280                        self._to_float(nmea_sentence.depth, current_row)
    277281                    )
    278                 elif nmea_sentence.sentence_type == 'MTW' and last_row is not None:
     282                elif (nmea_sentence.sentence_type == 'MTW' and
     283                      last_row is not None):
    279284                    last_row.water_temperature_set(
    280285                        self._to_float(nmea_sentence.temperature, current_row)
    … …  
    294299            except ValueError as error:
    295300                print(
    296                     'INFO: Failed to convert value from line {} into numeric: {}\n      Message: {}'
    297                     .format(current_row, string, error)
     301                    ('INFO: Failed to convert value from line '
     302                     '{} into numeric: {}\n      Message: {}').format(
     303                        current_row, string, error)
    298304                )
    299305                return 0
    … …  
    306312        if matches is None:
    307313            print(
    308                 'INFO: Failed to convert latitude position value from line {} into decimal degrees: {}'
    309                 .format(current_row, nmea_value)
     314                ('INFO: Failed to convert latitude position value from line '
     315                 '{} into decimal degrees: {}').format(current_row, nmea_value)
    310316            )
    311317            return
    … …  
    321327        if matches is None:
    322328            print(
    323                 'INFO: Failed to convert longitude position value from line {} into decimal degrees: {}'
    324                 .format(current_row, nmea_value)
     329                ('INFO: Failed to convert longitude position value from line '
     330                 '{} into decimal degrees: {}').format(current_row, nmea_value)
    325331            )
    326332            return
  • src/gnuboat/common/spatial/tilegenerator.py

    r2a31181 rc04676b  
    3333    from dataclasses import dataclass
    3434
    35     #@dataclass
    36     #class TileWidth:
    37     #"""
    38     #tile_size: The tile size in Pixel,
    39     #longitude: The width of the Tile in decimal degrees
    40     #latitude:  The height of the Tile in decimal degrees
    41     #"""
    42     #tile_size: int
    43     #longitude: float
    44     #latitude: float
    45 
    4635    @dataclass
    4736    class ResultPath:
    4837        """
    49                         path: Absolute path of the created results
    50                         prefixes: Dict with meaningful prefixes in the path. e.g. {'tile_size': '512', 'density': '10_100'}
    51                 """
     38            path: Absolute path of the created results
     39            prefixes: Dict with meaningful prefixes in the path. e.g.
     40            {'tile_size': '512', 'density': '10_100'}
     41        """
    5242        path: str
    5343        prefixes: dict
    5444
    5545except ImportError:
    56     #class TileWidth:
    57     #"""
    58     #Workaround for @dataclass, until python 3.7 is available in main distros
    59     #"""
    60     #def __init__(self, tile_size, longitude, latitude):
    61     #self.tile_size = tile_size
    62     #self.longitude = longitude
    63     #self.latitude = latitude
    64 
     46    # Workaround for @dataclass, until python 3.7 is available in
     47    # main distros
    6548    class ResultPath:
    6649        """
    67                         path: Absolute path of the created results
    68                         prefixes: Dict with meaningful prefixes in the path. e.g. {'tile_size': '512', 'density': '10_100'}
    69                 """
     50            path: Absolute path of the created results
     51            prefixes: Dict with meaningful prefixes in the path. e.g.
     52            {'tile_size': '512', 'density': '10_100'}
     53        """
    7054        def __init__(self, path, prefixes):
    7155            self.path = path
    … …  
    133117class RasterSlice(dict):
    134118    """
    135                 lng_lat_box: LngLatBbox
    136                 zoom_range: ZoomRange
    137                 tile_size: The tile size in Pixel,
    138                 grid_width: The width of the resulting rastr
    139                 grid_height:  The height of the resulting rastr
    140                
    141                 It's derived from dict to be json serialisable
    142         """
     119        lng_lat_box: LngLatBbox
     120        zoom_range: ZoomRange
     121        tile_size: The tile size in Pixel,
     122        grid_width: The width of the resulting rastr
     123        grid_height:  The height of the resulting rastr
     124
     125        It's derived from dict to be json serialisable
     126    """
    143127    def __init__(
    144128        self, lng_lat_box, zoom_range, tile_size, grid_width, grid_height
    … …  
    180164class TileGenerator:
    181165    """
    182                 - tile_sizes = Array of tile sizes in pixel, which should be rendered
    183                 - zoom_range = Range of zooms, tiles are created for
    184                 - densities = Array with counts of data points per density_base, where tiles are created for
    185                 - density_base = Radios of circle as a datum plane for the densities values
    186                 - nodata_value = Value used for pixels without valid data
    187         """
     166        - tile_sizes = Array of tile sizes in pixel, which should be rendered
     167        - zoom_range = Range of zooms, tiles are created for
     168        - densities = Array with counts of data points per density_base, where
     169          tiles are created for
     170        - density_base = Radios of circle as a datum plane for the densities
     171          values
     172        - nodata_value = Value used for pixels without valid data
     173    """
    188174    def __init__(
    189175        self,
    … …  
    200186        self._debug = debug
    201187
    202         # -999 is a workaround, as long gdal python api does not handle addAlpha
     188        # -999 is a workaround, as long gdal python api does not handle
     189        # addAlpha
    203190        self._colors = {
    204191            -999: '255 255 255',
    … …  
    213200    def fit_extent_to_tiles(self, lng_lat_box, zoom_range):
    214201        """
    215                         Enlarges the extent (given by lng_lat_box) to the borders of the tiles
    216                         lng_lat_box is of Type LngLatBbox
    217                 """
     202            Enlarges the extent (given by lng_lat_box) to the borders of the
     203            tiles lng_lat_box is of Type LngLatBbox
     204        """
    218205        tile_bounding = mercantile.bounding_tile(
    219206            lng_lat_box.west(), lng_lat_box.south(), lng_lat_box.east(),
    … …  
    241228    ):
    242229        """
    243                         Slice the complete area of input_file into smaller pieces,
    244                         so that each created raster file is smaller than raster_file_size_max
    245                         and cut into pieces at the borders of tiles and not thorugh tiles.
    246                         It returns an array of latitude longitude boxes representaing the borders, per slice.
    247                 """
     230            Slice the complete area of input_file into smaller pieces,
     231            so that each created raster file is smaller than
     232            raster_file_size_max and cut into pieces at the borders of
     233            tiles and not thorugh tiles. It returns an array of latitude
     234            longitude boxes representaing the borders, per slice.
     235        """
    248236        if tile_sizes is None:
    249237            tile_sizes = self._tile_sizes
    … …  
    259247                LngLatBbox(west, south, east, north), zoom_range
    260248            )
    261             # The lng_lat_box is exactly on the border between tiles. Since there are rounding errors,
    262             # we move the corner edges a very little bit (about a few mm) into the tile. This makes sure,
    263             # that we only get those tiles returned, which are really in the lng_lat_box.
     249            # The lng_lat_box is exactly on the border between tiles.
     250            # Since there are rounding errors, we move the corner edges
     251            # a very little bit (about a few mm) into the tile. This makes
     252            # sure, that we only get those tiles returned, which are really
     253            # in the lng_lat_box.
    264254            tiles_zoom_min = mercantile.tiles(
    265255                lng_lat_box.west() + 1 * 10**-7,
    … …  
    349339    ):
    350340        """
    351                         Runs all nescessary steps to create the tiles.
    352                         All default parameters equal to none are replaced by the one of the object
    353                         input_file = vrt source file used as a base for all steps to creating the tiles
    354                         Returns an array of paths with the created tiles if successfull
    355                 """
     341            Runs all nescessary steps to create the tiles.
     342            All default parameters equal to none are replaced by the one
     343            of the object input_file = vrt source file used as a base for
     344            all steps to creating the tiles. Returns an array of paths with
     345            the created tiles if successfull
     346        """
    356347        if densities is None:
    357348            densities = self._densities
    … …  
    364355        datasource = self._datasource_open(input_file)
    365356        source_layer = datasource.GetLayerByIndex(0)
    366         source_x_min, source_x_max, source_y_min, source_y_max = source_layer.GetExtent(
    367         )
     357        (source_x_min, source_x_max,
     358         source_y_min, source_y_max) = source_layer.GetExtent()
    368359        source_layer_name = source_layer.GetName()
    369360
    … …  
    379370        tile_result_paths = []
    380371        for density_min in densities:
    381             gridding_algorithm = 'average:radius1={}:radius2={}:angle=0.0:min_points={}:nodata={}'.format(
     372            gridding_algorithm = ('average:radius1={}:radius2={}:angle=0.0:'
     373                                  'min_points={}:nodata={}').format(
    382374                radius_x, radius_y, density_min, nodata_value
    383375            )
    … …  
    433425            )
    434426            # create the tiles
    435             title = 'GNUBoat {} datasets per {} squaremetre, Tilesize: {}'.format(
     427            title = ('GNUBoat {} datasets per {} squaremetre, '
     428                     'Tilesize: {}').format(
    436429                density_min, density_base, tile_slice.tile_size()
    437430            )
    … …  
    468461    ):
    469462        """
    470                         Rastering the data from source file into a tif.
    471                         The input should be a vrt source file.
    472                         The function returns the path to the generated tif file.
    473                 """
     463            Rastering the data from source file into a tif.
     464            The input should be a vrt source file.
     465            The function returns the path to the generated tif file.
     466        """
    474467        if nodata_value is None:
    475468            nodata_value = self._nodata_value
    … …  
    504497    ):
    505498        """
    506                         Creates the hillshade from a raster tif file and returns the path to the resulting tif file
    507                 """
     499            Creates the hillshade from a raster tif file and returns the path
     500            to the resulting tif file
     501        """
    508502        gdal.DEMProcessing(
    509503            output_file,
    … …  
    521515    ):
    522516        """
    523                         Creates the color relief from a raster tif and returns the path to the resulting tif file
    524                 """
     517            Creates the color relief from a raster tif and returns
     518            the path to the resulting tif file
     519        """
    525520        if colors is None:
    526521            colors = self._colors
    … …  
    596591            zoom_range.minimum(), zoom_range.maximum()
    597592        )
    598         # using the patched (tilesize) gdal2tiles.py script here, until the upstream version mades it in the distros
     593        # using the patched (tilesize) gdal2tiles.py script here, until the
     594        # upstream version mades it in the distros
    599595        subprocess.run([
    600596            'gdal2tiles-gnuboat.py', '-q', '-w', 'none',
    601             '--tilesize={}'.format(tile_size), '-z', tile_zoom_option, '-t',
    602             title, input_file, output_directory
    603         ],
    604                        check=True,
    605                        stdout=subprocess.PIPE,
    606                        stderr=subprocess.PIPE)
     597            '--tilesize={}'.format(tile_size), '-z', tile_zoom_option,
     598            '-t', title, input_file, output_directory],
     599            check=True,
     600            stdout=subprocess.PIPE,
     601            stderr=subprocess.PIPE)
    607602
    608603    def move_tiles_in_place(self, source_path, target_path, skip_empty=True):
    609604        """
    610                         Moves the generated tiles from the source_path into the target_path.
    611                         It moves file per file, so that the tiles are going to be integrated into an existing folder.
    612                         If skip_emtpy = True only one empty tile is copied to the top level directory. All other empty
    613                         tiles are not moved into target_path.
    614                 """
     605            Moves the generated tiles from the source_path into the
     606            target_path. It moves file per file, so that the tiles are
     607            going to be integrated into an existing folder. If
     608            skip_emtpy = True only one empty tile is copied to the
     609            top level directory. All other empty tiles are not moved
     610            into target_path.
     611        """
    615612        copied_empty_tile = False
    616613
    … …  
    663660        return True
    664661
    665     #def contours_create():
     662    # def contours_create():
    666663    # @todo Cut Tifs / warp
    667     #contour_input = gdal.Open(gdal_file, gdalconst.GA_ReadOnly)
    668     #contour_input_band = contour_input.GetRasterBand(1)
    669     ##Generate layer to save Contourlines in
    670     #contour_output = ogr.GetDriverByName("ESRI Shapefile").CreateDataSource(gdal_file_contours)
    671     #proj = osr.SpatialReference()
    672     #proj.SetWellKnownGeogCS(input_epsg)
    673     #for depth in colors:
    674     #contour_layer = contour_output.CreateLayer('contour_{}_{}_{}'.format(density_min, density_base, depth), srs = proj)
    675     #field_definition = ogr.FieldDefn("ID", ogr.OFTInteger)
    676     #contour_layer.CreateField(field_definition)
    677     #field_definition = ogr.FieldDefn("elev", ogr.OFTReal)
    678     #contour_layer.CreateField(field_definition)
    679     ##Generate Contourlines
    680     #gdal.ContourGenerate(contour_input_band, depth, 0, [], 0, 0, contour_layer, 0, 1)
    681     #contour_output = None
    682     #del contour_output
    683     #print("  Created contour lines {}".format(gdal_file_contours))
    684 
    685     #def crop():
    686     # cropping the tifs
    687     #gdal.Warp('/tmp/gnuboat/test.tif', gdal_file_color_relief, options = gdal.WarpOptions(format = 'GTiff', dstAlpha = True, srcNodata = "255 255 255", dstNodata = target_nodata_value, cutlineDSName = '/tmp/gnuboat/contours/contour-0.shp', cutlineLayer="contour-0", cropToCutline=True))
     664    # contour_input = gdal.Open(gdal_file, gdalconst.GA_ReadOnly)
     665    # contour_input_band = contour_input.GetRasterBand(1)
     666    # Generate layer to save Contourlines in
     667    # contour_output = ogr.GetDriverByName("ESRI Shapefile")
     668    #    .CreateDataSource(gdal_file_contours)
     669    # proj = osr.SpatialReference()
     670    # proj.SetWellKnownGeogCS(input_epsg)
     671    # for depth in colors:
     672    # contour_layer = contour_output.CreateLayer('contour_{}_{}_{}'
     673    #    .format(density_min, density_base, depth), srs = proj)
     674    # field_definition = ogr.FieldDefn("ID", ogr.OFTInteger)
     675    # contour_layer.CreateField(field_definition)
     676    # field_definition = ogr.FieldDefn("elev", ogr.OFTReal)
     677    # contour_layer.CreateField(field_definition)
     678    # Generate Contourlines
     679    # gdal.ContourGenerate(contour_input_band, depth, 0, [], 0, 0,
     680    #    contour_layer, 0, 1)
     681    # contour_output = None
     682    # del contour_output
     683    # print("  Created contour lines {}".format(gdal_file_contours))
     684
     685    # def crop():
     686    #  cropping the tifs
     687    # gdal.Warp('/tmp/gnuboat/test.tif', gdal_file_color_relief,
     688    #    options = gdal.WarpOptions(format = 'GTiff', dstAlpha = True,
     689    #        srcNodata = "255 255 255", dstNodata = target_nodata_value,
     690    #        cutlineDSName = '/tmp/gnuboat/c contours/contour-0.shp',
     691    #        cutlineLayer="contour-0", cropToCutline=True))
  • src/gnuboat/common/tests/test_tilegenerator.py

    r2a31181 rc04676b  
    260260    datasource = ogr.Open(datasource_vrt)
    261261    source_layer = datasource.GetLayerByIndex(0)
    262     source_x_min, source_x_max, source_y_min, source_y_max = source_layer.GetExtent(
    263     )
     262    (source_x_min, source_x_max,
     263     source_y_min, source_y_max) = source_layer.GetExtent()
    264264    source_layer_name = source_layer.GetName()
    265265    lon_metre_max = 60 * 1852 * math.cos(
    … …  
    272272
    273273    tilegen = tilegenerator.TileGenerator()
    274     gridding_algorithm = 'average:radius1={}:radius2={}:angle=0.0:min_points={}:nodata={}'.format(
     274    gridding_algorithm = ('average:radius1={}:radius2={}:angle=0.0:'
     275                          'min_points={}:nodata={}').format(
    275276        radius_x, radius_y, 10, -999
    276277    )
    … …  
    318319        'density_base':
    319320            100,
    320         'nodata_value':
    321             -999,
     321        'nodata_value': -999,
    322322        'skip_empty':
    323323            True
    … …  
    346346                         'density_base':
    347347                             100,
    348                          'nodata_value':
    349                              -999,
     348                         'nodata_value': -999,
    350349                         'skip_empty':
    351350                             True
  • tox.ini

    r2a31181 rc04676b  
    2727pep8ignore =
    2828    src/gnuboat/mapservice_impl/tasks/tileconfig.py E701
     29    src/gnuboat/common/spatial/tilegenerator.py E701
    2930    src/gnuboat/mapservice/controllers/*.py E501
    3031    src/gnuboat/mapservice/models/*.py E501
    31     src/gnuboat/mapservice/test/test_.py E501
     32    src/gnuboat/mapservice/test/*.py E501 W293
     33    src/gnuboat/common/bin/gdal2tiles-gnuboat.py ALL
Note: See TracChangeset for help on using the changeset viewer.