From 25b0a9981b66c443a1c1af1d5f26182c93268b45 Mon Sep 17 00:00:00 2001 From: Vaclav Petras Date: Wed, 30 Mar 2022 10:17:35 -0400 Subject: [PATCH] Update to Black 22.3.0 (#723) - A new version of Click broke Black. The new version of Black fixes the issue. - New stable version of Black (22.1, 22.3) changes some of the code formatting. - Targeting Python >=3.7 adds trailing comma after `**kwargs`. - Strings prefixed by u are replaced by plain strings which are Unicode in Python 3. - Changes applied to all files. - Python 2 files are now ignored (to be fixed or removed in the future). - CI workflow synced to core repo. - See also https://github.com/OSGeo/grass/pull/2212 for the update to stable Black in core repo. - See also https://github.com/OSGeo/grass/pull/2286 for the Click-related update. --- .github/workflows/black.yml | 24 +- pyproject.toml | 16 + .../d.vect.thematic2/d.vect.thematic2.py | 2 +- src/general/g.rename.many/g.rename.many.py | 2 +- src/gui/wxpython/newgui/api_test.py | 6 +- src/gui/wxpython/wx.mwprecip/mw3.py | 84 +++-- src/gui/wxpython/wx.rdigit/frame.py | 2 +- .../wxpython/wx.rdigit/rdigit/dialogs_core.py | 2 +- .../wxpython/wx.rdigit/rdigit/mapwindow.py | 4 +- .../wxpython/wx.stream/gui_modules/rstream.py | 4 +- .../i.ann.maskrcnn/maskrcnnlib/model.py | 4 +- src/imagery/i.cutlines/i.cutlines.py | 4 +- src/imagery/i.gabor/i.gabor.py | 4 +- src/imagery/i.landsat8.swlst/randomness.py | 2 +- .../i.landsat8.swlst/split_window_lst.py | 4 +- .../intercalibration_models.py | 4 +- .../test_intercalibration_models.py | 2 +- .../i.pysptools.unmix/i.pysptools.unmix.py | 8 +- .../i.segment.hierarchical.py | 4 +- src/imagery/i.segment.uspo/i.segment.uspo.py | 6 +- src/raster/r.basin/r.basin.py | 6 +- .../r.connectivity.distance.py | 14 +- .../estimap_recreation/main.py | 2 +- .../testsuite/test_r_futures_calib.py | 4 +- .../r.green/r.green.gshp/libgshp/ashrae.py | 78 ++-- .../r.green/r.green.gshp/libgshp/gpot.py | 6 +- .../r.green/r.green.hydro/libhydro/plant.py | 46 +-- .../r.green.hydro.financial.py | 10 +- .../r.green.hydro.technical.py | 20 +- src/raster/r.hazard.flood/r.hazard.flood.py | 4 +- src/raster/r.hypso/r.hypso.py | 2 +- src/raster/r.in.pdal/r.in.pdal.py | 54 +-- src/raster/r.in.usgs/r.in.usgs.py | 4 +- src/raster/r.lake.series/r.lake.series.py | 2 +- src/raster/r.mapcalc.tiled/r.mapcalc.tiled.py | 2 +- src/raster/r.mwprecip/r.mwprecip.py | 25 +- .../r.object.spatialautocor.py | 2 +- src/raster/r.shaded.pca/r.shaded.pca.py | 2 +- src/raster/r.skyview/r.skyview.py | 2 +- src/raster/r.sun.daily/r.sun.daily.py | 2 +- src/raster/r.sun.hourly/r.sun.hourly.py | 2 +- src/raster/r.texture.tiled/r.texture.tiled.py | 2 +- src/raster/r.tri/r.tri.py | 2 +- src/raster/r.valley.bottom/r.valley.bottom.py | 12 +- src/raster/r.vect.stats/r.vect.stats.py | 2 +- .../r.vector.ruggedness.py | 2 +- src/raster/r.viewshed.cva/r.viewshed.cva.py | 2 +- .../r.viewshed.exposure.py | 4 +- src/raster/r.width.funct/r.width.funct.py | 4 +- src/vector/v.build.pg/v.build.pg.py | 2 +- src/vector/v.civil/road_base.py | 10 +- src/vector/v.civil/road_crosstools.py | 2 +- src/vector/v.civil/road_displ.py | 2 +- src/vector/v.civil/road_tables.py | 350 +++++++++--------- src/vector/v.class.ml/features.py | 2 +- src/vector/v.class.ml/ml_functions.py | 4 +- src/vector/v.class.ml/npy2table.py | 2 +- src/vector/v.class.ml/v.class.ml.py | 2 +- src/vector/v.clean.ogr/v.clean.ogr.py | 4 +- src/vector/v.krige/v.krige.py | 2 +- .../v.stream.inbasin/v.stream.inbasin.py | 14 +- .../v.stream.profiler/v.stream.profiler.py | 2 +- src/vector/v.transects/v.transects.py | 2 +- 63 files changed, 473 insertions(+), 434 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index c53f027b32..04266fe343 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,13 +1,25 @@ name: Python Black Formatting on: - - push - - pull_request + push: + branches: + - grass* + pull_request: jobs: run-black: - name: Check - runs-on: ubuntu-20.04 + name: Black ${{ matrix.black-version }} + + # Using matrix just to get variables which are not environmental variables + # and also to sync with other workflows which use matrix. + strategy: + matrix: + include: + - os: ubuntu-20.04 + python-version: "3.10" + black-version: "22.3.0" + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -15,12 +27,12 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: ${{ matrix.python-version }} - name: Install run: | python -m pip install --upgrade pip - pip install black==21.5b1 + pip install black==${{ matrix.black-version }} - name: Run Black run: | diff --git a/pyproject.toml b/pyproject.toml index 98d7250e08..2f10d31d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [tool.black] line-length = 88 +target-version = ['py37', 'py38', 'py39', 'py310'] include = '\.pyi?$' exclude = ''' ( @@ -17,5 +18,20 @@ exclude = ''' | bin\..* | dist\..* )/ + | src/hadoop/hd/dependency.py + | src/hadoop/hd/hd.hive.select/hd.hive.select.py + | src/hadoop/hd/hdfsgrass/hdfs_grass_util.py + | src/hadoop/hd/hdfswrapper/webhdfs_hook.py + | src/gui/wxpython/wx.rdigit/rdigit/main.py + | src/gui/wxpython/wx.stream/gui_modules/ImageViewer.py + | src/gui/wxpython/wx.stream/gui_modules/rstream_panelOne.py + | src/gui/wxpython/wx.wms/parse.py + | src/gui/wxpython/wx.wms/wmsmenu.py + | src/gui/wxpython/wx.wms/LoadConfig.py + | src/gui/wxpython/newgui/wxgui.py + | src/gui/wxpython/newgui/render2.py + | src/gui/wxpython/newgui/mapwindow.py + | src/gui/wxpython/newgui/frame.py + | src/raster/r.agent/tests/test_grassland.py ) ''' diff --git a/src/display/d.vect.thematic2/d.vect.thematic2.py b/src/display/d.vect.thematic2/d.vect.thematic2.py index 8041f3207e..e2ac4970ee 100755 --- a/src/display/d.vect.thematic2/d.vect.thematic2.py +++ b/src/display/d.vect.thematic2/d.vect.thematic2.py @@ -1357,7 +1357,7 @@ def main(): icon=icon, size=ptsize, quiet=True, - **kwargs + **kwargs, ) if themetype != "graduated_lines": diff --git a/src/general/g.rename.many/g.rename.many.py b/src/general/g.rename.many/g.rename.many.py index e34ab8dc66..5a431a3574 100644 --- a/src/general/g.rename.many/g.rename.many.py +++ b/src/general/g.rename.many/g.rename.many.py @@ -131,7 +131,7 @@ def map_exists(name, type, mapset=None): mapset=mapset, stdout=PIPE, stderr=PIPE, - **extra_params + **extra_params, ) output, errors = process.communicate() info = parse_key_val(output) diff --git a/src/gui/wxpython/newgui/api_test.py b/src/gui/wxpython/newgui/api_test.py index 201f68ca9c..6309a0d6cc 100644 --- a/src/gui/wxpython/newgui/api_test.py +++ b/src/gui/wxpython/newgui/api_test.py @@ -79,7 +79,7 @@ def __init__( Map=Map(), auimgr=None, name=None, - **kwargs + **kwargs, ): """! @@ -100,7 +100,7 @@ def __init__( style=style, auimgr=auimgr, name=name, - **kwargs + **kwargs, ) self.Map = Map # instance of render.Map @@ -192,7 +192,7 @@ def __init__( | CT.TR_ROW_LINES | CT.TR_FULL_ROW_HIGHLIGHT | CT.TR_MULTIPLE, - **kwargs + **kwargs, ): wx.Panel.__init__(self, parent=parent, id=id, style=style) diff --git a/src/gui/wxpython/wx.mwprecip/mw3.py b/src/gui/wxpython/wx.mwprecip/mw3.py index d30c84e852..381a5ec4fa 100755 --- a/src/gui/wxpython/wx.mwprecip/mw3.py +++ b/src/gui/wxpython/wx.mwprecip/mw3.py @@ -474,21 +474,24 @@ def createWin(self): def sumValues(self): ##summing values per (->user)timestep interval self.viewDB = "computed_precip_sum" - sql = "CREATE %s %s.%s as \ + sql = ( + "CREATE %s %s.%s as \ SELECT %s ,round(avg(precip)::numeric,3) as %s, date_trunc('%s',time)as time \ FROM %s.%s \ GROUP BY %s, date_trunc('%s',time)\ - ORDER BY time" % ( - self.viewStatement, - self.schema, - self.viewDB, - self.typeID, - self.database.precipColName, - self.sumStep, - self.schema, - self.tbName, - self.typeID, - self.sumStep, + ORDER BY time" + % ( + self.viewStatement, + self.schema, + self.viewDB, + self.typeID, + self.database.precipColName, + self.sumStep, + self.schema, + self.tbName, + self.typeID, + self.sumStep, + ) ) self.database.connection.executeSql(sql, False, True) @@ -560,17 +563,20 @@ def removeLinksOthers(self): sql = "DROP TABLE %s.linktmp " % self.schema self.database.connection.executeSql(sql, False, True) - sql = "DELETE FROM %s.%s WHERE NOT EXISTS\ + sql = ( + "DELETE FROM %s.%s WHERE NOT EXISTS\ (SELECT %s FROM %s.linktmp \ - WHERE %s.%s.%s=linksonly.%s)" % ( - self.schema, - self.viewDB, - self.typeID, - self.schema, - self.schema, - self.viewDB, - self.typeID, - self.typeID, + WHERE %s.%s.%s=linksonly.%s)" + % ( + self.schema, + self.viewDB, + self.typeID, + self.schema, + self.schema, + self.viewDB, + self.typeID, + self.typeID, + ) ) self.database.connection.executeSql(sql, False, True) @@ -612,15 +618,18 @@ def crateTimeWin(self): tgrass = view_name + "|" + str(cur_timestamp) + "\n" tgrass_vector.append(tgrass) - sql = "CREATE TABLE %s.%s as\ + sql = ( + "CREATE TABLE %s.%s as\ SELECT * from %s.%s \ - WHERE time=(timestamp'%s'+ %s * interval '1 second')" % ( - self.schema, - view_name, - self.schema, - self.viewDB, - self.timestamp_min, - time_const, + WHERE time=(timestamp'%s'+ %s * interval '1 second')" + % ( + self.schema, + view_name, + self.schema, + self.viewDB, + self.timestamp_min, + time_const, + ) ) data = self.database.connection.executeSql(sql, False, True) @@ -1158,15 +1167,18 @@ def checkValidity(freq, polarization): self.timeWin.timestamp_max) resu = self.database.connection.executeSql(sql, True, True) """ - sql = "CREATE TABLE %s.record AS (SELECT linkid,time,txpower-rxpower as a \ + sql = ( + "CREATE TABLE %s.record AS (SELECT linkid,time,txpower-rxpower as a \ FROM %s.record \ WHERE time >= '%s' AND\ time <= '%s' \ - ORDER by recordid);" % ( - self.database.schema, - self.database.dataSchema, - self.timeWin.timestamp_min, - self.timeWin.timestamp_max, + ORDER by recordid);" + % ( + self.database.schema, + self.database.dataSchema, + self.timeWin.timestamp_min, + self.timeWin.timestamp_max, + ) ) self.database.connection.executeSql(sql, False, True) diff --git a/src/gui/wxpython/wx.rdigit/frame.py b/src/gui/wxpython/wx.rdigit/frame.py index d05a58547a..d139869ab4 100644 --- a/src/gui/wxpython/wx.rdigit/frame.py +++ b/src/gui/wxpython/wx.rdigit/frame.py @@ -57,7 +57,7 @@ def __init__( toolbars=["digitMap", "rdigit"], size=(875, 600), name="RDigitWindow", - **kwargs + **kwargs, ): """! @param parent (no parent is expected) diff --git a/src/gui/wxpython/wx.rdigit/rdigit/dialogs_core.py b/src/gui/wxpython/wx.rdigit/rdigit/dialogs_core.py index a3c296a0c9..ad6cd51c29 100644 --- a/src/gui/wxpython/wx.rdigit/rdigit/dialogs_core.py +++ b/src/gui/wxpython/wx.rdigit/rdigit/dialogs_core.py @@ -43,7 +43,7 @@ def __init__( disableAdd=False, showType=False, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, - *kwargs + *kwargs, ): """!Dialog for creating new vector map diff --git a/src/gui/wxpython/wx.rdigit/rdigit/mapwindow.py b/src/gui/wxpython/wx.rdigit/rdigit/mapwindow.py index d231acc190..d43da36e2a 100644 --- a/src/gui/wxpython/wx.rdigit/rdigit/mapwindow.py +++ b/src/gui/wxpython/wx.rdigit/rdigit/mapwindow.py @@ -43,7 +43,7 @@ def __init__( tree=None, lmgr=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, - **kwargs + **kwargs, ): BufferedWindow.__init__( self, @@ -54,7 +54,7 @@ def __init__( frame=frame, tree=tree, style=style, - **kwargs + **kwargs, ) self.lmgr = lmgr self.pdcVector = wx.PseudoDC() diff --git a/src/gui/wxpython/wx.stream/gui_modules/rstream.py b/src/gui/wxpython/wx.stream/gui_modules/rstream.py index 05bee7bf47..d81d95709a 100644 --- a/src/gui/wxpython/wx.stream/gui_modules/rstream.py +++ b/src/gui/wxpython/wx.stream/gui_modules/rstream.py @@ -73,7 +73,7 @@ def __init__( id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, title=_("GRASS GIS Hydrological Modelling Utility"), - **kwargs + **kwargs, ): """!Main window of r.stream's GUI @@ -92,7 +92,7 @@ def __init__( title=title, name="RStream", size=(600, 900), - **kwargs + **kwargs, ) self.SetIcon( wx.Icon(os.path.join(globalvar.ETCICONDIR, "grass.ico"), wx.BITMAP_TYPE_ICO) diff --git a/src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py b/src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py index fd6553a5d7..9a2a021bce 100644 --- a/src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py +++ b/src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py @@ -1134,7 +1134,7 @@ def smooth_l1_loss(y_true, y_pred): """ diff = K.abs(y_true - y_pred) less_than_one = K.cast(K.less(diff, 1.0), "float32") - loss = (less_than_one * 0.5 * diff ** 2) + (1 - less_than_one) * (diff - 0.5) + loss = (less_than_one * 0.5 * diff**2) + (1 - less_than_one) * (diff - 0.5) return loss @@ -2067,7 +2067,7 @@ def build(self, mode, config): # Image size must be dividable by 2 multiple times h, w = config.IMAGE_SHAPE[:2] - if h / 2 ** 6 != int(h / 2 ** 6) or w / 2 ** 6 != int(w / 2 ** 6): + if h / 2**6 != int(h / 2**6) or w / 2**6 != int(w / 2**6): raise Exception( "Image size must be dividable by 2 at least 6 times " "to avoid fractions when downscaling and upscaling." diff --git a/src/imagery/i.cutlines/i.cutlines.py b/src/imagery/i.cutlines/i.cutlines.py index 97ad46eac2..e4c222e763 100755 --- a/src/imagery/i.cutlines/i.cutlines.py +++ b/src/imagery/i.cutlines/i.cutlines.py @@ -268,7 +268,7 @@ def main(): overlap=overlap, processes=processes, split=False, - **kwargs + **kwargs, ) grd.run() else: @@ -299,7 +299,7 @@ def main(): processes=processes, split=False, flags="n", - **kwargs + **kwargs, ) grd.run() else: diff --git a/src/imagery/i.gabor/i.gabor.py b/src/imagery/i.gabor/i.gabor.py index c34daa704e..a141c26844 100755 --- a/src/imagery/i.gabor/i.gabor.py +++ b/src/imagery/i.gabor/i.gabor.py @@ -124,7 +124,7 @@ def gabor2d(win_size, orientation=0, wavelength=5, aspect=0.5, offset=0, ntype=" xr = x * np.cos(orientation) + y * np.sin(orientation) yr = -x * np.sin(orientation) + y * np.cos(orientation) - gaussian = np.exp(-((xr ** 2 + aspect ** 2 * yr ** 2) / (2 * stddev ** 2))) + gaussian = np.exp(-((xr**2 + aspect**2 * yr**2) / (2 * stddev**2))) if ntype == "imag": sf = np.sin(2 * np.pi * xr / wavelength + offset) else: @@ -162,7 +162,7 @@ def main(): if flags["q"]: if not threshold: grass.fatal(_("A percentile threshold is needed to quantify.")) - q = [2 ** i for i in range(len(orientation))] + q = [2**i for i in range(len(orientation))] else: q = 0 diff --git a/src/imagery/i.landsat8.swlst/randomness.py b/src/imagery/i.landsat8.swlst/randomness.py index bdfafb347d..73311c1d7c 100644 --- a/src/imagery/i.landsat8.swlst/randomness.py +++ b/src/imagery/i.landsat8.swlst/randomness.py @@ -9,7 +9,7 @@ def random_digital_numbers(count=2): digital_numbers = [] for dn in range(0, count): - digital_numbers.append(random.randint(1, 2 ** 12)) + digital_numbers.append(random.randint(1, 2**12)) if count == 1: return digital_numbers[0] diff --git a/src/imagery/i.landsat8.swlst/split_window_lst.py b/src/imagery/i.landsat8.swlst/split_window_lst.py index 140defa2ac..aa8866cc46 100644 --- a/src/imagery/i.landsat8.swlst/split_window_lst.py +++ b/src/imagery/i.landsat8.swlst/split_window_lst.py @@ -381,10 +381,10 @@ def compute_lst(self, t10, t11, coefficients): # addends a = b0 - b1 = b1 + b2 * (1 - avg) / avg + b3 * delta / avg ** 2 + b1 = b1 + b2 * (1 - avg) / avg + b3 * delta / avg**2 b2 = (t10 + t11) / 2 b = b1 * b2 - c1 = b4 + b5 * (1 - avg) / avg + b6 * delta / avg ** 2 + c1 = b4 + b5 * (1 - avg) / avg + b6 * delta / avg**2 c2 = (t10 - t11) / 2 c = c1 * c2 d = b7 * (t10 - t11) ** 2 diff --git a/src/imagery/i.nightlights.intercalibration/intercalibration_models.py b/src/imagery/i.nightlights.intercalibration/intercalibration_models.py index 00981b0a02..312c681df3 100644 --- a/src/imagery/i.nightlights.intercalibration/intercalibration_models.py +++ b/src/imagery/i.nightlights.intercalibration/intercalibration_models.py @@ -210,7 +210,7 @@ def calibrate(self, dn): build a calibration equation for the requested satellite and year. """ if self.is_dn_valid(dn): - cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn ** 2)) + cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn**2)) model = EQUATIONS[self.author].model # look in equations.py self._model = model.format(dn=dn, cdn=cdn, c0=self.c0, c1=self.c1, c2=self.c2) return cdn @@ -289,7 +289,7 @@ def calibrate(self, dn): build a calibration equation for the requested satellite and year. """ if self.is_dn_valid(dn): - cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn ** 2)) + cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn**2)) # Update _model as well! model = "{cdn} = ({c0}) + ({c1}) * {dn} + ({c2}) * {dn}^2" diff --git a/src/imagery/i.nightlights.intercalibration/test_intercalibration_models.py b/src/imagery/i.nightlights.intercalibration/test_intercalibration_models.py index 95ece8df4a..ec2176584a 100644 --- a/src/imagery/i.nightlights.intercalibration/test_intercalibration_models.py +++ b/src/imagery/i.nightlights.intercalibration/test_intercalibration_models.py @@ -45,7 +45,7 @@ def calibrate_digital_number(dn, c0, c1, c2): "The provided Digital Number value is out of the " "expected range [0, 63]" ) - return c0 + (c1 * dn) + (c2 * (dn ** 2)) + return c0 + (c1 * dn) + (c2 * (dn**2)) def test_model(author): diff --git a/src/imagery/i.pysptools.unmix/i.pysptools.unmix.py b/src/imagery/i.pysptools.unmix/i.pysptools.unmix.py index 1acb7e0c7c..df6c50992e 100644 --- a/src/imagery/i.pysptools.unmix/i.pysptools.unmix.py +++ b/src/imagery/i.pysptools.unmix/i.pysptools.unmix.py @@ -108,9 +108,9 @@ def get_rastertype(raster): if not isinstance(raster[0, 0], np.float32) and not isinstance( raster[0, 0], np.float64 ): - map_type = u"INTEGER" + map_type = "INTEGER" else: - map_type = u"REAL" + map_type = "REAL" return map_type @@ -325,7 +325,7 @@ def main(): # Build attribute table # Deinfe columns for attribute table - cols = [(u"cat", "INTEGER PRIMARY KEY")] + cols = [("cat", "INTEGER PRIMARY KEY")] for b in band_types.keys(): cols.append((b.replace(".", "_"), band_types[b])) @@ -359,7 +359,7 @@ def main(): n = 0 attr = [] for b in band_types.keys(): - if band_types[b] == u"INTEGER": + if band_types[b] == "INTEGER": attr.append(int(e[n])) else: attr.append(float(e[n])) diff --git a/src/imagery/i.segment.hierarchical/i.segment.hierarchical.py b/src/imagery/i.segment.hierarchical/i.segment.hierarchical.py index e01ea9ac3a..f6b4b75ca4 100755 --- a/src/imagery/i.segment.hierarchical/i.segment.hierarchical.py +++ b/src/imagery/i.segment.hierarchical/i.segment.hierarchical.py @@ -269,7 +269,7 @@ def segment(thresholds, minsizes, output="seg__%.2f", **opts): processes=PROCESSES, move=MOVE, debug=DEBUG, - **OPTS + **OPTS, ) SEG.run() else: @@ -278,5 +278,5 @@ def segment(thresholds, minsizes, output="seg__%.2f", **opts): OPTS.pop("thresholds"), OPTS.pop("minsizes"), output=OPTS.pop("outputs_prefix"), - **OPTS + **OPTS, ) diff --git a/src/imagery/i.segment.uspo/i.segment.uspo.py b/src/imagery/i.segment.uspo/i.segment.uspo.py index 7a8d6aaa9a..1eb117adc8 100644 --- a/src/imagery/i.segment.uspo/i.segment.uspo.py +++ b/src/imagery/i.segment.uspo/i.segment.uspo.py @@ -680,7 +680,7 @@ def get_autocorrelation(mapname, raster, neighbordict, indicator): means[l[0]] = float(l[i]) mean_diffs[l[0]] = float(l[i]) - global_mean - sum_sq_mean_diffs = sum(x ** 2 for x in mean_diffs.values()) + sum_sq_mean_diffs = sum(x**2 for x in mean_diffs.values()) total_nb_neighbors = 0 for region in neighbordict: @@ -738,10 +738,10 @@ def create_optimization_list(variancelist, autocorlist, opt_function, alpha, dir optlist = [normvariance[x] + normautocor[x] for x in range(len(normvariance))] if opt_function == "f": optlist = [ - (1 + alpha ** 2) + (1 + alpha**2) * ( (normvariance[x] * normautocor[x]) - / float(alpha ** 2 * normautocor[x] + normvariance[x]) + / float(alpha**2 * normautocor[x] + normvariance[x]) ) if (normautocor[x] + normvariance[x]) > 0 else 0 diff --git a/src/raster/r.basin/r.basin.py b/src/raster/r.basin/r.basin.py index 7896fffb1a..a223327502 100644 --- a/src/raster/r.basin/r.basin.py +++ b/src/raster/r.basin/r.basin.py @@ -174,7 +174,7 @@ def main(): # Managing flag if autothreshold: resolution = grass.region()["nsres"] - th = 1000000 / (resolution ** 2) + th = 1000000 / (resolution**2) grass.message("threshold : %s" % th) else: th = options["threshold"] @@ -487,7 +487,7 @@ def main(): # Directing vector delta_x = abs(float(basin_east) - east) delta_y = abs(float(basin_north) - north) - L_orienting_vect = math.sqrt((delta_x ** 2) + (delta_y ** 2)) / 1000 + L_orienting_vect = math.sqrt((delta_x**2) + (delta_y**2)) / 1000 grass.message("Directing vector done") # Prevalent orientation @@ -499,7 +499,7 @@ def main(): grass.message("Compactness coefficient done") # Circularity ratio - R_c = (4 * math.pi * area_basin) / (perimeter_basin ** 2) + R_c = (4 * math.pi * area_basin) / (perimeter_basin**2) grass.message("Circularity ratio done") # Mainchannel diff --git a/src/raster/r.connectivity/r.connectivity.distance/r.connectivity.distance.py b/src/raster/r.connectivity/r.connectivity.distance/r.connectivity.distance.py index 672c35156d..2ce0a15611 100755 --- a/src/raster/r.connectivity/r.connectivity.distance/r.connectivity.distance.py +++ b/src/raster/r.connectivity/r.connectivity.distance/r.connectivity.distance.py @@ -527,18 +527,18 @@ def main(): # Init output vector maps if they are requested by user network = VectorTopo(edge_map) network_columns = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"from_p", "INTEGER"), - (u"to_p", "INTEGER"), - (u"min_dist", "DOUBLE PRECISION"), - (u"dist", "DOUBLE PRECISION"), - (u"max_dist", "DOUBLE PRECISION"), + ("cat", "INTEGER PRIMARY KEY"), + ("from_p", "INTEGER"), + ("to_p", "INTEGER"), + ("min_dist", "DOUBLE PRECISION"), + ("dist", "DOUBLE PRECISION"), + ("max_dist", "DOUBLE PRECISION"), ] network.open("w", tab_name=edge_map, tab_cols=network_columns) vertex = VectorTopo(vertex_map) vertex_columns = [ - (u"cat", "INTEGER PRIMARY KEY"), + ("cat", "INTEGER PRIMARY KEY"), (pop_proxy, "DOUBLE PRECISION"), ] vertex.open("w", tab_name=vertex_map, tab_cols=vertex_columns) diff --git a/src/raster/r.estimap.recreation/estimap_recreation/main.py b/src/raster/r.estimap.recreation/estimap_recreation/main.py index e9cceed839..440d41bae2 100644 --- a/src/raster/r.estimap.recreation/estimap_recreation/main.py +++ b/src/raster/r.estimap.recreation/estimap_recreation/main.py @@ -713,7 +713,7 @@ def main(options, flags): ns_resolution=population_ns_resolution, ew_resolution=population_ew_resolution, print_only=print_only, - **supply_parameters + **supply_parameters, ) # restore region diff --git a/src/raster/r.futures/r.futures.calib/testsuite/test_r_futures_calib.py b/src/raster/r.futures/r.futures.calib/testsuite/test_r_futures_calib.py index 633f7a07ba..c02034d025 100755 --- a/src/raster/r.futures/r.futures.calib/testsuite/test_r_futures_calib.py +++ b/src/raster/r.futures/r.futures.calib/testsuite/test_r_futures_calib.py @@ -142,7 +142,7 @@ def test_pga_calib_compactness(self): nprocs=1, repeat=2, random_seed=1, - **self.pga_params + **self.pga_params, ) self.assertTrue( filecmp.cmp("data/out_calib.csv", "data/ref_calib.csv", shallow=False), @@ -165,7 +165,7 @@ def test_pga_calib_compactness_subregions(self): nprocs=1, repeat=2, random_seed=1, - **self.pga_params + **self.pga_params, ) self.assertTrue( filecmp.cmp( diff --git a/src/raster/r.green/r.green.gshp/libgshp/ashrae.py b/src/raster/r.green/r.green.gshp/libgshp/ashrae.py index f74b809f99..bbca32f9aa 100644 --- a/src/raster/r.green/r.green.gshp/libgshp/ashrae.py +++ b/src/raster/r.green/r.green.gshp/libgshp/ashrae.py @@ -199,11 +199,11 @@ def ground_resistence(ground, borehole, period="6h"): * ( c0 + c1 * borehole - + c2 * borehole ** 2.0 + + c2 * borehole**2.0 + c3 * diffusivity - + c4 * diffusivity ** 2.0 + + c4 * diffusivity**2.0 + c5 * log_diff - + c6 * log_diff ** 2 + + c6 * log_diff**2 + c7 * borehole * diffusivity + c8 * borehole * log_diff + c9 * diffusivity * log_diff @@ -582,7 +582,7 @@ def bh_resistence_grout(bh, ground_conductivity): + log(bh.radius / bh.distance) + (bh.k_grout - ground_conductivity) / (bh.k_grout + ground_conductivity) - * log(bh.radius ** 4.0 / (bh.radius ** 4.0 - (bh.distance / 2.0) ** 4.0)) + * log(bh.radius**4.0 / (bh.radius**4.0 - (bh.distance / 2.0) ** 4.0)) ) ) @@ -759,7 +759,7 @@ def get_vars(out, bhe, basename, execute=True, **kwargs): bhe.borehole.radius, period="10y", execute=execute, - **kwargs + **kwargs, ) medium_term = basename + out + "_medium_term" r_ground_resistence( @@ -768,7 +768,7 @@ def get_vars(out, bhe, basename, execute=True, **kwargs): bhe.borehole.radius, period="1m", execute=execute, - **kwargs + **kwargs, ) short_term = basename + out + "_short_term" r_ground_resistence( @@ -777,7 +777,7 @@ def get_vars(out, bhe, basename, execute=True, **kwargs): bhe.borehole.radius, period="6h", execute=execute, - **kwargs + **kwargs, ) fluid_temp = basename + out + "_fluid_temp" r_fluid_temperature_borehole( @@ -941,41 +941,41 @@ def _temperature_penality( * ( TP[0] + TP[1] * dd_ratio - + TP[2] * dd_ratio ** 2 - + TP[3] * dd_ratio ** 3 + + TP[2] * dd_ratio**2 + + TP[3] * dd_ratio**3 + TP[4] * ln_dim_time - + TP[5] * ln_dim_time ** 2 - + TP[6] * ln_dim_time ** 3 + + TP[5] * ln_dim_time**2 + + TP[6] * ln_dim_time**3 + TP[7] * number - + TP[8] * number ** 2 - + TP[9] * number ** 3 + + TP[8] * number**2 + + TP[9] * number**3 + TP[10] * ratio - + TP[11] * ratio ** 2 - + TP[12] * ratio ** 3 + + TP[11] * ratio**2 + + TP[12] * ratio**3 + TP[13] * dd_ratio * ln_dim_time - + TP[14] * dd_ratio * ln_dim_time ** 2 + + TP[14] * dd_ratio * ln_dim_time**2 + TP[15] * dd_ratio * number - + TP[16] * dd_ratio * number ** 2 + + TP[16] * dd_ratio * number**2 + TP[17] * dd_ratio * ratio - + TP[18] * dd_ratio * ratio ** 2 - + TP[19] * dd_ratio ** 2 * ln_dim_time - + TP[20] * dd_ratio ** 2 * ln_dim_time ** 2 - + TP[21] * dd_ratio ** 2 * number - + TP[22] * dd_ratio ** 2 * number ** 2 - + TP[23] * dd_ratio ** 2 * ratio - + TP[24] * dd_ratio ** 2 * ratio ** 2 + + TP[18] * dd_ratio * ratio**2 + + TP[19] * dd_ratio**2 * ln_dim_time + + TP[20] * dd_ratio**2 * ln_dim_time**2 + + TP[21] * dd_ratio**2 * number + + TP[22] * dd_ratio**2 * number**2 + + TP[23] * dd_ratio**2 * ratio + + TP[24] * dd_ratio**2 * ratio**2 + TP[25] * ln_dim_time * number - + TP[26] * ln_dim_time * number ** 2 + + TP[26] * ln_dim_time * number**2 + TP[27] * ln_dim_time * ratio - + TP[28] * ln_dim_time * ratio ** 2 - + TP[29] * ln_dim_time ** 2 * number - + TP[30] * ln_dim_time ** 2 * number ** 2 - + TP[31] * ln_dim_time ** 2 * ratio - + TP[32] * ln_dim_time ** 2 * ratio ** 2 + + TP[28] * ln_dim_time * ratio**2 + + TP[29] * ln_dim_time**2 * number + + TP[30] * ln_dim_time**2 * number**2 + + TP[31] * ln_dim_time**2 * ratio + + TP[32] * ln_dim_time**2 * ratio**2 + TP[33] * number * ratio - + TP[34] * number * ratio ** 2 - + TP[35] * number ** 2 * ratio - + TP[36] * number ** 2 * ratio ** 2 + + TP[34] * number * ratio**2 + + TP[35] * number**2 * ratio + + TP[36] * number**2 * ratio**2 ) ) @@ -990,7 +990,7 @@ def _r_temperature_penality( number, ratio, execute=True, - **kwargs + **kwargs, ): """Return the temperature penality of a BHE field @@ -1148,7 +1148,7 @@ def _r_get_length( ground_temp, temperature_penality, execute=True, - **kwargs + **kwargs, ): """Return a first attempt of the BHE field lenght @@ -1268,7 +1268,7 @@ def r_temperature_penality(out, field, length, execute=True, **kwargs): field.number, field.ratio, execute=execute, - **kwargs + **kwargs, ) @@ -1364,7 +1364,7 @@ def r_field_length( length_single=None, tol=1e-3, execute=True, - **kwargs + **kwargs, ): """Return the total borefield length: L [m] @@ -1419,7 +1419,7 @@ def r_field_length( gtemp, temp_penality, execute=execute, - **kwargs + **kwargs, ) diff_template = basename + out + "_absdiff_{:02d}" index = 1 @@ -1441,7 +1441,7 @@ def r_field_length( gtemp, temp_penality, execute=execute, - **kwargs + **kwargs, ) rename("raster", length1, out) return out diff --git a/src/raster/r.green/r.green.gshp/libgshp/gpot.py b/src/raster/r.green/r.green.gshp/libgshp/gpot.py index 5502db962c..3bcdba9b5d 100644 --- a/src/raster/r.green/r.green.gshp/libgshp/gpot.py +++ b/src/raster/r.green/r.green.gshp/libgshp/gpot.py @@ -79,7 +79,7 @@ def norm_time(time, borehole_radius, ground_conductivity, ground_capacity): ... # doctest: +ELLIPSIS 1.1147973744292237e-06 """ - return borehole_radius ** 2.0 / ( + return borehole_radius**2.0 / ( 4 * ground_conductivity / ground_capacity * 0.000001 * time ) @@ -91,7 +91,7 @@ def r_norm_time( ground_conductivity, ground_capacity, execute=True, - **kwargs + **kwargs, ): """Normalized time in s @@ -214,7 +214,7 @@ def r_power( borehole_resistence, gmax, execute=True, - **kwargs + **kwargs, ): """Return the potential power using the g.pot method in W diff --git a/src/raster/r.green/r.green.hydro/libhydro/plant.py b/src/raster/r.green/r.green.hydro/libhydro/plant.py index d774778e97..f07093d1fc 100644 --- a/src/raster/r.green/r.green.hydro/libhydro/plant.py +++ b/src/raster/r.green/r.green.hydro/libhydro/plant.py @@ -14,25 +14,25 @@ from grass.script import core as gcore COLS = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"plant_id", "VARCHAR(10)"), - (u"stream_id", "INTEGER"), - (u"pot_power", "DOUBLE"), - (u"discharge", "DOUBLE"), - (u"elev_up", "DOUBLE"), - (u"elev_down", "DOUBLE"), + ("cat", "INTEGER PRIMARY KEY"), + ("plant_id", "VARCHAR(10)"), + ("stream_id", "INTEGER"), + ("pot_power", "DOUBLE"), + ("discharge", "DOUBLE"), + ("elev_up", "DOUBLE"), + ("elev_down", "DOUBLE"), ] COLS_points = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"kind", "VARCHAR(10)"), - (u"plant_id", "VARCHAR(10)"), - (u"kind_label", "VARCHAR(10)"), - (u"stream_id", "INTEGER"), - (u"elevation", "DOUBLE"), - (u"discharge", "DOUBLE"), - (u"pot_power", "DOUBLE"), + ("cat", "INTEGER PRIMARY KEY"), + ("kind", "VARCHAR(10)"), + ("plant_id", "VARCHAR(10)"), + ("kind_label", "VARCHAR(10)"), + ("stream_id", "INTEGER"), + ("elevation", "DOUBLE"), + ("discharge", "DOUBLE"), + ("pot_power", "DOUBLE"), ] HydroStruct = namedtuple("HydroStruct", ["intake", "conduct", "penstock", "side"]) @@ -237,14 +237,14 @@ def write_hydrostruct(out, hydro, plant): out.table.conn.commit() tab_cols = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"plant_id", "VARCHAR(10)"), - (u"intake_id", "INTEGER"), - (u"discharge", "DOUBLE"), - (u"gross_head", "DOUBLE"), - (u"power", "DOUBLE"), - (u"kind", "VARCHAR(10)"), - (u"side", "VARCHAR(10)"), + ("cat", "INTEGER PRIMARY KEY"), + ("plant_id", "VARCHAR(10)"), + ("intake_id", "INTEGER"), + ("discharge", "DOUBLE"), + ("gross_head", "DOUBLE"), + ("power", "DOUBLE"), + ("kind", "VARCHAR(10)"), + ("side", "VARCHAR(10)"), ] with VectorTopo(output, mode="w", overwrite=overwrite) as out: diff --git a/src/raster/r.green/r.green.hydro/r.green.hydro.financial/r.green.hydro.financial.py b/src/raster/r.green/r.green.hydro/r.green.hydro.financial/r.green.hydro.financial.py index 079785df82..06caa5af3d 100644 --- a/src/raster/r.green/r.green.hydro/r.green.hydro.financial/r.green.hydro.financial.py +++ b/src/raster/r.green/r.green.hydro/r.green.hydro.financial/r.green.hydro.financial.py @@ -627,7 +627,7 @@ def get_cnames( expr, _names_cache=ne.utils.CacheDict(256) if ne else ne, _numexpr_cache=ne.utils.CacheDict(256) if ne else ne, - **kwargs + **kwargs, ): if not isinstance(expr, (str, unicode)): raise ValueError("must specify expression as a string") @@ -647,7 +647,7 @@ def vcolcalc( expr, condition=lambda x: x is None, notfinitesubstitute=None, - **kwargs + **kwargs, ): equal = expr.index("=") if equal < 0: @@ -805,9 +805,9 @@ def get_electro_length(opts): new = VectorTopo(elines) # new vec with elines new.layer = 1 cols = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"plant_id", "VARCHAR(10)"), - (u"side", "VARCHAR(10)"), + ("cat", "INTEGER PRIMARY KEY"), + ("plant_id", "VARCHAR(10)"), + ("side", "VARCHAR(10)"), ] new.open("w", tab_cols=cols) reg = Region() diff --git a/src/raster/r.green/r.green.hydro/r.green.hydro.technical/r.green.hydro.technical.py b/src/raster/r.green/r.green.hydro/r.green.hydro.technical/r.green.hydro.technical.py index 72aeeceddb..30e4a7bd51 100644 --- a/src/raster/r.green/r.green.hydro/r.green.hydro.technical/r.green.hydro.technical.py +++ b/src/raster/r.green/r.green.hydro/r.green.hydro.technical/r.green.hydro.technical.py @@ -279,12 +279,12 @@ def diam_pen(discharge, length, gross_head, percentage, epsilon=0.015): def diam(x, *args): q, l, h, p, e = args return sqrt( - (100 * 8 * l * q ** 2) / (p * h * pi ** 2 * 9.81 * x ** 5) + (100 * 8 * l * q**2) / (p * h * pi**2 * 9.81 * x**5) ) + 2 * log10( (e * 0.001) / (3.71 * x) + (2.51 * 0.000001 * pi) / (4 * q * l) - * sqrt((100 * 8 * l * q ** 2) / (p * h * pi ** 2 * 9.81 * x)) + * sqrt((100 * 8 * l * q**2) / (p * h * pi**2 * 9.81 * x)) ) out = fsolve(diam, 0.1, args=(discharge, length, gross_head, percentage, epsilon))[ @@ -333,14 +333,14 @@ def coeff_f(x, *args): first_log_arg = (e * 0.001) / (3.71 * d) # epsilon [mm] rho_water = 1000.0 # kg/m2 mu_water = 0.001 # Pa - vel = discharge / (pi * d ** 2.0 / 4.0) + vel = discharge / (pi * d**2.0 / 4.0) re_number = rho_water * vel * d / mu_water return x + 2 * log10(first_log_arg + 2.51 * x / re_number) out = fsolve(coeff_f, 0, args=(discharge, diameter, epsilon)) - f = 1 / out ** 2 - h_colebrooke = (f[0] * 8 * length * discharge ** 2) / ( - pi ** 2 * diameter ** 5 * 9.81 + f = 1 / out**2 + h_colebrooke = (f[0] * 8 * length * discharge**2) / ( + pi**2 * diameter**5 * 9.81 ) return h_colebrooke @@ -376,7 +376,7 @@ def losses_Strickler(discharge, length, diameter, theta, velocity, ks=75): """ # circolar section r = diameter * 0.5 - A = 0.5 * r ** 2 * (2 * pi - theta + sin(theta)) + A = 0.5 * r**2 * (2 * pi - theta + sin(theta)) pw = r * (2 * pi - theta) Rh = A / pw @@ -387,7 +387,7 @@ def losses_Strickler(discharge, length, diameter, theta, velocity, ks=75): # i = v**2 / (ks**2 * Rh ** (4/3)) # hs = i * l - return velocity ** 2 / (ks ** 2 * Rh ** (4.0 / 3.0)) * length + return velocity**2 / (ks**2 * Rh ** (4.0 / 3.0)) * length def singular_losses(gross_head, length, discharge, diameter_penstock): @@ -398,7 +398,7 @@ def singular_losses(gross_head, length, discharge, diameter_penstock): 0.5 + (gross_head / length) ** 2 + 2 * (sin(asin(min(1, gross_head / length)) / 2)) ** 4 - ) * ((8 * discharge ** 2) / (9.81 * pi ** 2 * diameter_penstock ** 4)) + ) * ((8 * discharge**2) / (9.81 * pi**2 * diameter_penstock**4)) else: h_sing = 0 return h_sing @@ -464,7 +464,7 @@ def compute_losses( roughness_penstock, ) line.attrs["diameter"] = diameter - length = (length ** 2.0 + gross_head ** 2.0) ** 0.5 + length = (length**2.0 + gross_head**2.0) ** 0.5 if gross_head > length: msgr = get_msgr() msgr.warning( diff --git a/src/raster/r.hazard.flood/r.hazard.flood.py b/src/raster/r.hazard.flood/r.hazard.flood.py index a8fb268f90..8ce3a5bb9d 100755 --- a/src/raster/r.hazard.flood/r.hazard.flood.py +++ b/src/raster/r.hazard.flood/r.hazard.flood.py @@ -103,7 +103,7 @@ def main(): grass.message("Slope map done. ") # n exponent - n = 0.016 * (resolution ** 0.46) + n = 0.016 * (resolution**0.46) grass.message("Exponent : %s " % n) # MTI threshold @@ -139,7 +139,7 @@ def main(): # Delete areas of less than a threshold of cells (corresponding to 1 square kilometer) # Calculating threshold - th = int(1000000 / resolution ** 2) + th = int(1000000 / resolution**2) grass.message("Deleting areas of less than %s cells.. " % th) grass.run_command( "r.area", input="r_clump", output="r_flood_th", lesser=th, flags="b" diff --git a/src/raster/r.hypso/r.hypso.py b/src/raster/r.hypso/r.hypso.py index 396560fe97..66d25dcbde 100755 --- a/src/raster/r.hypso/r.hypso.py +++ b/src/raster/r.hypso/r.hypso.py @@ -75,7 +75,7 @@ def main(): for i in range(len(stats)): zn[i, 3] = 1 - (zn[i, 2] / sum(zn[:, 1])) - zn[i, 4] = zn[i, 3] * (((res ** 2) / 1000000) * sum(zn[:, 1])) + zn[i, 4] = zn[i, 3] * (((res**2) / 1000000) * sum(zn[:, 1])) zn[i, 5] = (zn[i, 0] - min(zn[:, 0])) / (max(zn[:, 0]) - min(zn[:, 0])) kl[i, 0] = zn[i, 0] kl[i, 1] = 1 - (zn[i, 2] / totcell) diff --git a/src/raster/r.in.pdal/r.in.pdal.py b/src/raster/r.in.pdal/r.in.pdal.py index 6715438ac0..75e916fb12 100644 --- a/src/raster/r.in.pdal/r.in.pdal.py +++ b/src/raster/r.in.pdal/r.in.pdal.py @@ -199,10 +199,10 @@ def footprint_to_vectormap(infile, footprint): fh.close() data = json.load(open(tmp_fp)) xy_in = "" - str1 = u"boundary" + str1 = "boundary" try: - str2 = u"boundary_json" - str3 = u"coordinates" + str2 = "boundary_json" + str3 = "coordinates" coord = data[str1][str2][str3][0][0] for xy in coord: xy_in += str(xy[0]) + "," + str(xy[1]) + "\n" @@ -289,13 +289,13 @@ def scan_extent(infile): data = json.load(open(tmp_scan)) if summary: - str1 = u"summary" - str2 = u"bounds" - y_str = u"Y" - x_str = u"X" - z_str = u"Z" - min_str = u"min" - max_str = u"max" + str1 = "summary" + str2 = "bounds" + y_str = "Y" + x_str = "X" + z_str = "Z" + min_str = "min" + max_str = "max" try: n = str(data[str1][str2][y_str][max_str]) s = str(data[str1][str2][y_str][min_str]) @@ -304,12 +304,12 @@ def scan_extent(infile): t = str(data[str1][str2][z_str][max_str]) b = str(data[str1][str2][z_str][min_str]) except: - ymin_str = u"miny" - xmin_str = u"minx" - zmin_str = u"minz" - ymax_str = u"maxy" - xmax_str = u"maxx" - zmax_str = u"maxz" + ymin_str = "miny" + xmin_str = "minx" + zmin_str = "minz" + ymax_str = "maxy" + xmax_str = "maxx" + zmax_str = "maxz" n = str(data[str1][str2][ymax_str]) s = str(data[str1][str2][ymin_str]) w = str(data[str1][str2][xmin_str]) @@ -317,16 +317,16 @@ def scan_extent(infile): t = str(data[str1][str2][zmax_str]) b = str(data[str1][str2][zmin_str]) else: - str1 = u"stats" - str2 = u"bbox" - str3 = u"native" - str4 = u"bbox" - n = str(data[str1][str2][str3][str4][u"maxy"]) - s = str(data[str1][str2][str3][str4][u"miny"]) - w = str(data[str1][str2][str3][str4][u"minx"]) - e = str(data[str1][str2][str3][str4][u"maxx"]) - t = str(data[str1][str2][str3][str4][u"maxz"]) - b = str(data[str1][str2][str3][str4][u"minz"]) + str1 = "stats" + str2 = "bbox" + str3 = "native" + str4 = "bbox" + n = str(data[str1][str2][str3][str4]["maxy"]) + s = str(data[str1][str2][str3][str4]["miny"]) + w = str(data[str1][str2][str3][str4]["minx"]) + e = str(data[str1][str2][str3][str4]["maxx"]) + t = str(data[str1][str2][str3][str4]["maxz"]) + b = str(data[str1][str2][str3][str4]["minz"]) return n, s, w, e, t, b @@ -394,7 +394,7 @@ def main(): "r.external", input=raster_file, flags="o", output=raster_reference ) result = grass.find_file(name=raster_reference, element="raster") - if result[u"fullname"] == u"": + if result["fullname"] == "": raster_reference = raster_reference + ".1" # option 1: set region to extent of tiles while precisely aligning pixel # geometry to raster_reference (including both raster_reference and raster_file) diff --git a/src/raster/r.in.usgs/r.in.usgs.py b/src/raster/r.in.usgs/r.in.usgs.py index e0b9067d7b..b8a6a01eda 100755 --- a/src/raster/r.in.usgs/r.in.usgs.py +++ b/src/raster/r.in.usgs/r.in.usgs.py @@ -1009,7 +1009,7 @@ def exist_list(): input=gui_output_layer, elevation=gui_output_layer, nprocs=nprocs, - **rst_params + **rst_params, ) else: gscript.run_command( @@ -1061,7 +1061,7 @@ def exist_list(): input=patch_names[0], elevation=gui_output_layer, nprocs=nprocs, - **rst_params + **rst_params, ) if not preserve_imported_tiles: gscript.run_command( diff --git a/src/raster/r.lake.series/r.lake.series.py b/src/raster/r.lake.series/r.lake.series.py index bf461b6738..b426a6adcf 100644 --- a/src/raster/r.lake.series/r.lake.series.py +++ b/src/raster/r.lake.series/r.lake.series.py @@ -214,7 +214,7 @@ def main(): lake=outputs[i], water_level=water_level, overwrite=gcore.overwrite(), # TODO: really works? Its seems that hardcoding here False does not prevent overwriting. - **kwargs + **kwargs, ) except CalledModuleError: # remove maps created so far, try to remove also i-th map diff --git a/src/raster/r.mapcalc.tiled/r.mapcalc.tiled.py b/src/raster/r.mapcalc.tiled/r.mapcalc.tiled.py index 2e8b90a451..c3e534034d 100755 --- a/src/raster/r.mapcalc.tiled/r.mapcalc.tiled.py +++ b/src/raster/r.mapcalc.tiled/r.mapcalc.tiled.py @@ -153,7 +153,7 @@ def main(): split=False, mapset_prefix=mapset_prefix, out_prefix=output_mapname, - **kwargs + **kwargs, ) grd.run() diff --git a/src/raster/r.mwprecip/r.mwprecip.py b/src/raster/r.mwprecip/r.mwprecip.py index cd5a125191..c9474eadac 100755 --- a/src/raster/r.mwprecip/r.mwprecip.py +++ b/src/raster/r.mwprecip/r.mwprecip.py @@ -1472,19 +1472,22 @@ def makeTimeWin(db, typeid, table): ##summing values per (->user)timestep interval view_db = typeid + "_" + randomWord(3) - sql = "CREATE %s %s.%s as select\ + sql = ( + "CREATE %s %s.%s as select\ %s ,round(avg(precip)::numeric,3) as precip_mm_h, date_trunc('%s',time)\ as time FROM %s.%s GROUP BY %s, date_trunc('%s',time)\ - ORDER BY time" % ( - view_statement, - schema_name, - view_db, - typeid, - sum_precip, - schema_name, - table, - typeid, - sum_precip, + ORDER BY time" + % ( + view_statement, + schema_name, + view_db, + typeid, + sum_precip, + schema_name, + table, + typeid, + sum_precip, + ) ) data = db.executeSql(sql, False, True) stamp = "" diff --git a/src/raster/r.object.spatialautocor/r.object.spatialautocor.py b/src/raster/r.object.spatialautocor/r.object.spatialautocor.py index 751bd7d147..d4b6e1b2b2 100644 --- a/src/raster/r.object.spatialautocor/r.object.spatialautocor.py +++ b/src/raster/r.object.spatialautocor/r.object.spatialautocor.py @@ -129,7 +129,7 @@ def get_autocorrelation(mapname, raster, neighbordict, method): means[l[0]] = float(l[i]) mean_diffs[l[0]] = float(l[i]) - global_mean - sum_sq_mean_diffs = sum(x ** 2 for x in mean_diffs.values()) + sum_sq_mean_diffs = sum(x**2 for x in mean_diffs.values()) total_nb_neighbors = 0 for region in neighbordict: diff --git a/src/raster/r.shaded.pca/r.shaded.pca.py b/src/raster/r.shaded.pca/r.shaded.pca.py index 3e64df19cf..b979f8e72f 100644 --- a/src/raster/r.shaded.pca/r.shaded.pca.py +++ b/src/raster/r.shaded.pca/r.shaded.pca.py @@ -146,7 +146,7 @@ def run_r_shaded_relief( altitude=altitude, overwrite=core.overwrite(), quiet=True, - **params + **params, ) diff --git a/src/raster/r.skyview/r.skyview.py b/src/raster/r.skyview/r.skyview.py index ebe7a230ce..a436536b1e 100755 --- a/src/raster/r.skyview/r.skyview.py +++ b/src/raster/r.skyview/r.skyview.py @@ -189,7 +189,7 @@ def main(): step=horizon_step, output=TMP_NAME, flags="d", - **params + **params, ) new_maps = _get_horizon_maps() diff --git a/src/raster/r.sun.daily/r.sun.daily.py b/src/raster/r.sun.daily/r.sun.daily.py index 955bfc8ac3..13ba9ab15b 100755 --- a/src/raster/r.sun.daily/r.sun.daily.py +++ b/src/raster/r.sun.daily/r.sun.daily.py @@ -387,7 +387,7 @@ def run_r_sun( step=step, overwrite=core.overwrite(), quiet=True, - **params + **params, ) diff --git a/src/raster/r.sun.hourly/r.sun.hourly.py b/src/raster/r.sun.hourly/r.sun.hourly.py index 0d2a9f93ac..3746078053 100755 --- a/src/raster/r.sun.hourly/r.sun.hourly.py +++ b/src/raster/r.sun.hourly/r.sun.hourly.py @@ -360,7 +360,7 @@ def run_r_sun( time=time, overwrite=core.overwrite(), quiet=True, - **params + **params, ) if binary: for output in (beam_rad, diff_rad, refl_rad, glob_rad): diff --git a/src/raster/r.texture.tiled/r.texture.tiled.py b/src/raster/r.texture.tiled/r.texture.tiled.py index ebc464d323..e36401be82 100755 --- a/src/raster/r.texture.tiled/r.texture.tiled.py +++ b/src/raster/r.texture.tiled/r.texture.tiled.py @@ -166,7 +166,7 @@ def main(): processes=processes, split=False, mapset_prefix=mapset_prefix, - **kwargs + **kwargs, ) grd.run() diff --git a/src/raster/r.tri/r.tri.py b/src/raster/r.tri/r.tri.py index 1827b96a83..6762a4865a 100755 --- a/src/raster/r.tri/r.tri.py +++ b/src/raster/r.tri/r.tri.py @@ -173,7 +173,7 @@ def idw_weights(radius, p, circular=False): # create inverse distance weights W = dist.copy() W[centre, centre] = np.inf - W = 1 / (W ** p) + W = 1 / (W**p) # normalize weights to sum to 1 (excluding centre) W[centre, centre] = np.inf diff --git a/src/raster/r.valley.bottom/r.valley.bottom.py b/src/raster/r.valley.bottom/r.valley.bottom.py index cf381df2bc..1f567b614b 100644 --- a/src/raster/r.valley.bottom/r.valley.bottom.py +++ b/src/raster/r.valley.bottom/r.valley.bottom.py @@ -217,14 +217,10 @@ def focal_expr(radius, window_square=False): row_start = row - radius col_start = col - radius - if ( - pow(row_start, 2) + pow(col_start, 2) <= pow(radius, 2) - and ( - i, - j, - ) - != (0, 0) - ): + if pow(row_start, 2) + pow(col_start, 2) <= pow(radius, 2) and ( + i, + j, + ) != (0, 0): offsets.append((j, i)) return offsets diff --git a/src/raster/r.vect.stats/r.vect.stats.py b/src/raster/r.vect.stats/r.vect.stats.py index 1d2106b026..22d7f44d45 100755 --- a/src/raster/r.vect.stats/r.vect.stats.py +++ b/src/raster/r.vect.stats/r.vect.stats.py @@ -79,7 +79,7 @@ def main(): format="point", separator=sep, flags="r", - **out_args + **out_args, ) in_process = gs.start_command( "r.in.xyz", diff --git a/src/raster/r.vector.ruggedness/r.vector.ruggedness.py b/src/raster/r.vector.ruggedness/r.vector.ruggedness.py index c60d620f89..d8e1ecf13d 100755 --- a/src/raster/r.vector.ruggedness/r.vector.ruggedness.py +++ b/src/raster/r.vector.ruggedness/r.vector.ruggedness.py @@ -125,7 +125,7 @@ def idw_weights(size, p): W = distance_from_centre(math.floor(size / 2)) W = np.floor(W) W = size - (W + 1) - W = W ** p + W = W**p # turn W into character for GRASS r.neighbors W_text = str(W) diff --git a/src/raster/r.viewshed.cva/r.viewshed.cva.py b/src/raster/r.viewshed.cva/r.viewshed.cva.py index 754e6a62e8..d4017aa060 100755 --- a/src/raster/r.viewshed.cva/r.viewshed.cva.py +++ b/src/raster/r.viewshed.cva/r.viewshed.cva.py @@ -204,7 +204,7 @@ def main(): input=elev, output=tempry, coordinates=site[0] + "," + site[1], - **viewshed_options + **viewshed_options, ) # now make a mapcalc statement to add all the viewsheds together to make the outout cumulative viewsheds map grass.message(_("Calculating cumulative viewshed map <%s>") % out) diff --git a/src/raster/r.viewshed.exposure/r.viewshed.exposure.py b/src/raster/r.viewshed.exposure/r.viewshed.exposure.py index 97e409070f..75ad5bc5f0 100755 --- a/src/raster/r.viewshed.exposure/r.viewshed.exposure.py +++ b/src/raster/r.viewshed.exposure/r.viewshed.exposure.py @@ -699,7 +699,7 @@ def distance_decay_reverse( v_scal = np.where(abs(v_scal) < 1e-6, (reg.nsres + reg.ewres) / 2, v_scal) # 4. distance decay function - distance_decay = (reg.nsres * reg.ewres) / (v_scal ** 2) + distance_decay = (reg.nsres * reg.ewres) / (v_scal**2) # 5. multiply distance decay by binary viewshed and weight return distance_decay * np_viewshed * t_loc[-1] @@ -867,7 +867,7 @@ def visual_magnitude_reverse( # 8. visual magnitude adjusted for distance weight visual_magnitude = ( - np.cos(beta) * np.cos(theta) * ((reg.nsres * reg.ewres) / (v_scal ** 2)) + np.cos(beta) * np.cos(theta) * ((reg.nsres * reg.ewres) / (v_scal**2)) ) # 9. Multiply visual magnitude by binary viewshed and weight diff --git a/src/raster/r.width.funct/r.width.funct.py b/src/raster/r.width.funct/r.width.funct.py index fc514420f0..281136a210 100755 --- a/src/raster/r.width.funct/r.width.funct.py +++ b/src/raster/r.width.funct/r.width.funct.py @@ -66,11 +66,11 @@ def main(): if i != 0: zn[i, 0], zn[i, 1] = map(float, stats[i].split(" ")) zn[i, 2] = zn[i, 1] + zn[i - 1, 2] - zn[i, 3] = zn[i, 1] * (res ** 2) + zn[i, 3] = zn[i, 1] * (res**2) totcell = sum(zn[:, 1]) print("Tot. cells %s" % (totcell)) - totarea = totcell * (res ** 2) + totarea = totcell * (res**2) print("Tot. area %s" % (totarea)) maxdist = max(zn[:, 0]) print("Max distance %s" % (maxdist)) diff --git a/src/vector/v.build.pg/v.build.pg.py b/src/vector/v.build.pg/v.build.pg.py index 5fcd50c766..c393dcfcbb 100755 --- a/src/vector/v.build.pg/v.build.pg.py +++ b/src/vector/v.build.pg/v.build.pg.py @@ -102,7 +102,7 @@ def main(): ret = grass.db_select( sql="SELECT COUNT(*) FROM topology.topology " "WHERE name = '%s'" % options["topo_schema"], - **pg_conn + **pg_conn, ) if not ret or int(ret[0][0]) == 1: diff --git a/src/vector/v.civil/road_base.py b/src/vector/v.civil/road_base.py index 8075f50779..7778e0a712 100644 --- a/src/vector/v.civil/road_base.py +++ b/src/vector/v.civil/road_base.py @@ -110,7 +110,7 @@ def cloth_local(radio, a_clot): if radio == 0: leng, tau = 0, 0 else: - leng = a_clot ** 2 / abs(radio) + leng = a_clot**2 / abs(radio) tau = leng / (2 * radio) x_e, y_e = aprox_coord(leng, tau) x_o = x_e - radio * math.sin(tau) @@ -904,7 +904,7 @@ def distance(self, pnt): else: slope = (self.pend.x - self.pstart.x) / (self.pend.y - self.pstart.y) rest = self.pstart.y + slope * self.pstart.x - return (slope * pnt.x + pnt.y - rest) / math.sqrt(slope ** 2 + 1) + return (slope * pnt.x + pnt.y - rest) / math.sqrt(slope**2 + 1) def parallel(self, dist, radio): """Return a parallel straight with a given distance and side given by @@ -1323,7 +1323,7 @@ def _get_pts_clot_in(self, start, end, interv): while start <= end: if start == 0: start = 0.0000001 - rad_clo = self.a_clot ** 2 / start + rad_clo = self.a_clot**2 / start tau_clo = start / (2 * rad_clo) x_o, y_o = aprox_coord(start, tau_clo) x_1, y_1 = self.cloth_global(x_o, y_o) @@ -1351,7 +1351,7 @@ def _get_pts_clot_out(self, start, end, interv): if end2 == 0: end2 = 0.0000001 - rad_clo = self.a_clot ** 2 / end2 + rad_clo = self.a_clot**2 / end2 tau_clo = end2 / (2 * rad_clo) x_o, y_o = aprox_coord((end2), tau_clo) x_1, y_1 = self.cloth_global(x_o, y_o) @@ -1514,7 +1514,7 @@ def cloth_global(self, x_local, y_local): def funct(self, leng, recta2): """Funtion for use with bisecc""" - rad_i = self.a_clot ** 2 / leng + rad_i = self.a_clot**2 / leng tau_i = leng / (2 * rad_i) x_o, y_o = aprox_coord(leng, tau_i) x_1, y_1 = self.cloth_global(x_o, y_o) diff --git a/src/vector/v.civil/road_crosstools.py b/src/vector/v.civil/road_crosstools.py index bb6da628c2..d5ac6add65 100644 --- a/src/vector/v.civil/road_crosstools.py +++ b/src/vector/v.civil/road_crosstools.py @@ -291,7 +291,7 @@ def curve_curve(self, radio, dist1, dist2): r_a = self._get_radio_leng(self.plant2, radio, dist2) r_c = self.plant1.center.distance(self.plant2.center) - ang_a = math.acos((r_b ** 2 + r_c ** 2 - r_a ** 2) / (2 * r_b * r_c)) + ang_a = math.acos((r_b**2 + r_c**2 - r_a**2) / (2 * r_b * r_c)) # ang_b = math.acos((r_a ** 2 + r_c ** 2 - r_b ** 2) / (2 * r_a * r_c)) # ang_c = math.pi - ang_a - ang_b diff --git a/src/vector/v.civil/road_displ.py b/src/vector/v.civil/road_displ.py index 0a94fc70c4..24606ff075 100644 --- a/src/vector/v.civil/road_displ.py +++ b/src/vector/v.civil/road_displ.py @@ -352,7 +352,7 @@ def _distx(self, rad, pc_d, pstart): recta_c = Base.Straight(pc_d, None, pstart.azi, 10) pto_corte = recta_pnt.cutoff(recta_c) distxx = pc_d.distance(pto_corte) - seno = math.sqrt(rad ** 2 - distxx ** 2) + seno = math.sqrt(rad**2 - distxx**2) distx = pstart.distance(pto_corte) - seno return distx diff --git a/src/vector/v.civil/road_tables.py b/src/vector/v.civil/road_tables.py index 4bb58857be..e3fe0bf60f 100644 --- a/src/vector/v.civil/road_tables.py +++ b/src/vector/v.civil/road_tables.py @@ -71,59 +71,59 @@ def funcion_r(*arg): # TABLES TABLES = { - "first": [(u"cat", u"INTEGER PRIMARY KEY"), (u"name", u"TEXT")], + "first": [("cat", "INTEGER PRIMARY KEY"), ("name", "TEXT")], "_Plan": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"pk_eje", u"DOUBLE PRECISION"), - (u"radio", u"DOUBLE PRECISION"), - (u"a_in", u"DOUBLE PRECISION"), - (u"a_out", u"DOUBLE PRECISION"), - (u"widening", u"DOUBLE PRECISION"), - (u"superelev", u"TEXT"), - (u"dc_", u"DOUBLE PRECISION"), - (u"lr_", u"DOUBLE PRECISION"), + ("cat2", "INTEGER PRIMARY KEY"), + ("pk_eje", "DOUBLE PRECISION"), + ("radio", "DOUBLE PRECISION"), + ("a_in", "DOUBLE PRECISION"), + ("a_out", "DOUBLE PRECISION"), + ("widening", "DOUBLE PRECISION"), + ("superelev", "TEXT"), + ("dc_", "DOUBLE PRECISION"), + ("lr_", "DOUBLE PRECISION"), ], "_Vert": [ - (u"cat3", u"INTEGER PRIMARY KEY"), - (u"pk", u"DOUBLE PRECISION"), - (u"elev", u"DOUBLE PRECISION"), - (u"kv", u"DOUBLE PRECISION"), - (u"l", u"DOUBLE PRECISION"), - (u"b", u"DOUBLE PRECISION"), + ("cat3", "INTEGER PRIMARY KEY"), + ("pk", "DOUBLE PRECISION"), + ("elev", "DOUBLE PRECISION"), + ("kv", "DOUBLE PRECISION"), + ("l", "DOUBLE PRECISION"), + ("b", "DOUBLE PRECISION"), ], "_Displ": [ - (u"cat4", u"INTEGER PRIMARY KEY"), - (u"pk", u"DOUBLE PRECISION"), - (u"sec_left", u"TEXT"), - (u"sec_right", u"TEXT"), - (u"type_left", u"TEXT"), - (u"type_right", u"TEXT"), + ("cat4", "INTEGER PRIMARY KEY"), + ("pk", "DOUBLE PRECISION"), + ("sec_left", "TEXT"), + ("sec_right", "TEXT"), + ("type_left", "TEXT"), + ("type_right", "TEXT"), ], "_Terr": [ - (u"cat5", u"INTEGER PRIMARY KEY"), - (u"pk", u"DOUBLE PRECISION"), - (u"cut_left", u"DOUBLE PRECISION"), - (u"cut_right", u"DOUBLE PRECISION"), - (u"fill_left", u"DOUBLE PRECISION"), - (u"fill_right", u"DOUBLE PRECISION"), - (u"height", u"DOUBLE PRECISION"), - (u"leng", u"DOUBLE PRECISION"), + ("cat5", "INTEGER PRIMARY KEY"), + ("pk", "DOUBLE PRECISION"), + ("cut_left", "DOUBLE PRECISION"), + ("cut_right", "DOUBLE PRECISION"), + ("fill_left", "DOUBLE PRECISION"), + ("fill_right", "DOUBLE PRECISION"), + ("height", "DOUBLE PRECISION"), + ("leng", "DOUBLE PRECISION"), ], "_Trans": [ - (u"cat6", u"INTEGER PRIMARY KEY"), - (u"pk", u"DOUBLE PRECISION"), - (u"dist_left", u"DOUBLE PRECISION"), - (u"dist_right", u"DOUBLE PRECISION"), - (u"npk", u"DOUBLE PRECISION"), + ("cat6", "INTEGER PRIMARY KEY"), + ("pk", "DOUBLE PRECISION"), + ("dist_left", "DOUBLE PRECISION"), + ("dist_right", "DOUBLE PRECISION"), + ("npk", "DOUBLE PRECISION"), ], "_Marks": [ - (u"cat7", u"INTEGER PRIMARY KEY"), - (u"pk", u"DOUBLE PRECISION"), - (u"dist", u"TEXT"), - (u"elev", u"TEXT"), - (u"azi", u"TEXT"), - (u"name", u"TEXT"), - (u"cod", u"TEXT"), + ("cat7", "INTEGER PRIMARY KEY"), + ("pk", "DOUBLE PRECISION"), + ("dist", "TEXT"), + ("elev", "TEXT"), + ("azi", "TEXT"), + ("name", "TEXT"), + ("cod", "TEXT"), ], } @@ -131,189 +131,189 @@ def funcion_r(*arg): OUT_TABLES = { # Plant "__Plant": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"type", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"param", u"TEXT"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("type", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("param", "TEXT"), + ("GRASSRGB", "TEXT"), ], "__Plant_PC": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("param", "TEXT"), ], - "__Plant_C": [(u"cat3", u"INTEGER PRIMARY KEY"), (u"param", u"TEXT")], + "__Plant_C": [("cat3", "INTEGER PRIMARY KEY"), ("param", "TEXT")], # Vertical "__Vertical": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"type", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"param", u"TEXT"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("type", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("param", "TEXT"), + ("GRASSRGB", "TEXT"), ], "__Vertical_PC": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("type", "TEXT"), + ("param", "TEXT"), ], # Displaced "__Displaced": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"param", u"DOUBLE PRECISIO"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("param", "DOUBLE PRECISIO"), + ("GRASSRGB", "TEXT"), ], "__Displaced_PC": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), - (u"displ", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("param", "TEXT"), + ("displ", "TEXT"), ], - "__Displaced_Areas": [(u"cat", u"INTEGER PRIMARY KEY"), (u"num", u"TEXT")], + "__Displaced_Areas": [("cat", "INTEGER PRIMARY KEY"), ("num", "TEXT")], # Trans "__Pks": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("GRASSRGB", "TEXT"), ], "__Trans": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"dist_left", u"DOUBLE PRECISION"), - (u"dist_right", u"DOUBLE PRECISION"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("dist_left", "DOUBLE PRECISION"), + ("dist_right", "DOUBLE PRECISION"), + ("GRASSRGB", "TEXT"), ], "__Trans_PC": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"trans", u"TEXT"), - (u"param", u"TEXT"), - (u"type", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("trans", "TEXT"), + ("param", "TEXT"), + ("type", "TEXT"), ], "__Trans_PT": [ - (u"cat3", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"trans", u"TEXT"), - (u"param", u"TEXT"), - (u"type", u"TEXT"), + ("cat3", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("trans", "TEXT"), + ("param", "TEXT"), + ("type", "TEXT"), ], # Taludes "__Slopes": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"param", u"DOUBLE PRECISION"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("param", "DOUBLE PRECISION"), + ("GRASSRGB", "TEXT"), ], # Marks "__Marks": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"azimut", u"DOUBLE PRECISION"), - (u"name", u"TEXT"), - (u"cod", u"TEXT"), - (u"dist", u"DOUBLE PRECISION"), - (u"elev", u"DOUBLE PRECISION"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("azimut", "DOUBLE PRECISION"), + ("name", "TEXT"), + ("cod", "TEXT"), + ("dist", "DOUBLE PRECISION"), + ("elev", "DOUBLE PRECISION"), ], # Taludes "__Slopes_Areas": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("param", "TEXT"), + ("GRASSRGB", "TEXT"), ], # LongProfile "__LongProfile": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"type", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"param", u"TEXT"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("type", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("param", "TEXT"), + ("GRASSRGB", "TEXT"), ], "__LProfile_PC": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("type", "TEXT"), + ("param", "TEXT"), ], "__LProfile_Axis": [ - (u"cat3", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), + ("cat3", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("type", "TEXT"), + ("param", "TEXT"), ], - "__LProfile_Ticks": [(u"cat4", u"INTEGER PRIMARY KEY"), (u"param", u"TEXT")], + "__LProfile_Ticks": [("cat4", "INTEGER PRIMARY KEY"), ("param", "TEXT")], # TransProfiles "__TransProfiles": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"TEXT"), - (u"type", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"param", u"TEXT"), - (u"GRASSRGB", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "TEXT"), + ("type", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("param", "TEXT"), + ("GRASSRGB", "TEXT"), ], "__TProfile_PC": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"dist", u"TEXT"), - (u"elev", u"TEXT"), - (u"rel_elev", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("dist", "TEXT"), + ("elev", "TEXT"), + ("rel_elev", "TEXT"), ], "__TProfile_Axis": [ - (u"cat3", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"type", u"TEXT"), - (u"param", u"TEXT"), + ("cat3", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("type", "TEXT"), + ("param", "TEXT"), ], - "__TProfile_Ticks": [(u"cat4", u"INTEGER PRIMARY KEY"), (u"param", u"TEXT")], + "__TProfile_Ticks": [("cat4", "INTEGER PRIMARY KEY"), ("param", "TEXT")], # Tri "__Topo": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"pk", u"DOUBLE PRECISION"), - (u"name", u"TEXT"), - (u"azi", u"DOUBLE PRECISION"), - (u"p_type", u"TEXT"), - (u"align", u"INTEGER"), - (u"vparam", u"DOUBLE PRECISION"), - (u"v_type", u"TEXT"), - (u"terr", u"DOUBLE PRECISION"), - (u"t_type", u"TEXT"), - (u"dist_d", u"DOUBLE PRECISION"), - (u"x", u"DOUBLE PRECISION"), - (u"y", u"DOUBLE PRECISION"), - (u"z", u"DOUBLE PRECISION"), - (u"action", u"TEXT"), + ("cat", "INTEGER PRIMARY KEY"), + ("pk", "DOUBLE PRECISION"), + ("name", "TEXT"), + ("azi", "DOUBLE PRECISION"), + ("p_type", "TEXT"), + ("align", "INTEGER"), + ("vparam", "DOUBLE PRECISION"), + ("v_type", "TEXT"), + ("terr", "DOUBLE PRECISION"), + ("t_type", "TEXT"), + ("dist_d", "DOUBLE PRECISION"), + ("x", "DOUBLE PRECISION"), + ("y", "DOUBLE PRECISION"), + ("z", "DOUBLE PRECISION"), + ("action", "TEXT"), ], "__Topo_BreakLines": [ - (u"cat2", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), - (u"type", u"TEXT"), - (u"param", u"DOUBLE PRECISION"), - (u"GRASSRGB", u"TEXT"), + ("cat2", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("long", "DOUBLE PRECISION"), + ("type", "TEXT"), + ("param", "DOUBLE PRECISION"), + ("GRASSRGB", "TEXT"), ], "__Topo_Hull": [ - (u"cat", u"INTEGER PRIMARY KEY"), - (u"name", u"TEXT"), - (u"long", u"DOUBLE PRECISION"), + ("cat", "INTEGER PRIMARY KEY"), + ("name", "TEXT"), + ("long", "DOUBLE PRECISION"), ], } @@ -399,7 +399,7 @@ def _create_table(self): tab_sufix = self.name if self.name == "": tab_sufix = "first" - TABLES[tab_sufix][0] = (u"cat" + str(self.layer), u"INTEGER PRIMARY KEY") + TABLES[tab_sufix][0] = ("cat" + str(self.layer), "INTEGER PRIMARY KEY") if not table.exist(): table.create(TABLES[tab_sufix]) table.conn.commit() diff --git a/src/vector/v.class.ml/features.py b/src/vector/v.class.ml/features.py index 3182dc50ff..d39e488c40 100644 --- a/src/vector/v.class.ml/features.py +++ b/src/vector/v.class.ml/features.py @@ -29,7 +29,7 @@ def importances( csv="", img="", clf=ExtraTreesClassifier(n_estimators=N_ESTIMATORS, random_state=RANDOM_STATE), - **savefig + **savefig, ): clf.fit(X, y) imp = clf.feature_importances_ diff --git a/src/vector/v.class.ml/ml_functions.py b/src/vector/v.class.ml/ml_functions.py index 3d9327d550..dcf204c9f5 100644 --- a/src/vector/v.class.ml/ml_functions.py +++ b/src/vector/v.class.ml/ml_functions.py @@ -204,7 +204,7 @@ def plot_bias_variance( test_clr="r", alpha=0.2, fmt="png", - **kwargs + **kwargs, ): fig, ax = plt.subplots(figsize=(6, 5)) ax.set_ylim([0.0, 1.0]) @@ -455,7 +455,7 @@ def explorer_clsfiers( test_clr="r", alpha=0.2, fmt="png", - **kw + **kw, ) if extra: extra_analysis(cls, Xd, Yd, labels) diff --git a/src/vector/v.class.ml/npy2table.py b/src/vector/v.class.ml/npy2table.py index 517e152b58..7c5b953f06 100644 --- a/src/vector/v.class.ml/npy2table.py +++ b/src/vector/v.class.ml/npy2table.py @@ -117,7 +117,7 @@ def export_results( tab, cats.astype(int), up, - *[cls["predict"].astype(int) for cls in results] + *[cls["predict"].astype(int) for cls in results], ) if mode == "w": nlyr = len(vect.dblinks) + 1 diff --git a/src/vector/v.class.ml/v.class.ml.py b/src/vector/v.class.ml/v.class.ml.py index 64fd0396db..67959848c0 100755 --- a/src/vector/v.class.ml/v.class.ml.py +++ b/src/vector/v.class.ml/v.class.ml.py @@ -639,7 +639,7 @@ def main(opt, flg): csv=opt["imp_csv"], img=opt["imp_fig"], # default parameters to save the matplotlib figure - **dict(dpi=300, transparent=False, bbox_inches="tight") + **dict(dpi=300, transparent=False, bbox_inches="tight"), ) # optimize the training set diff --git a/src/vector/v.clean.ogr/v.clean.ogr.py b/src/vector/v.clean.ogr/v.clean.ogr.py index 361795e8c9..8ce8eba505 100644 --- a/src/vector/v.clean.ogr/v.clean.ogr.py +++ b/src/vector/v.clean.ogr/v.clean.ogr.py @@ -245,7 +245,7 @@ def main(): flags="i", quiet=True, overwrite=overwrite, - **vopts + **vopts, ) except CalledModuleError: grass.fatal(_("Unable to create location from OGR datasource <%s>") % indsn) @@ -267,7 +267,7 @@ def main(): layer=inlayer, output=outvect_tmp, overwrite=overwrite, - **vopts + **vopts, ) except CalledModuleError: grass.fatal(_("Unable to import OGR datasource <%s>") % indsn) diff --git a/src/vector/v.krige/v.krige.py b/src/vector/v.krige/v.krige.py index 92c1d538af..e9ea5e0fd0 100644 --- a/src/vector/v.krige/v.krige.py +++ b/src/vector/v.krige/v.krige.py @@ -308,7 +308,7 @@ def Run( block, output_var, command, - **kwargs + **kwargs, ): """Wrapper for all functions above.""" diff --git a/src/vector/v.stream.inbasin/v.stream.inbasin.py b/src/vector/v.stream.inbasin/v.stream.inbasin.py index 641f0d1648..bfacf9ac0d 100644 --- a/src/vector/v.stream.inbasin/v.stream.inbasin.py +++ b/src/vector/v.stream.inbasin/v.stream.inbasin.py @@ -165,10 +165,10 @@ def main(): pass tmp = vector.Vector("tmp") _cols = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"x", "DOUBLE PRECISION"), - (u"y", "DOUBLE PRECISION"), - (u"strcat", "DOUBLE PRECISION"), + ("cat", "INTEGER PRIMARY KEY"), + ("x", "DOUBLE PRECISION"), + ("y", "DOUBLE PRECISION"), + ("strcat", "DOUBLE PRECISION"), ] tmp.open("w", tab_name="tmp", tab_cols=_cols) point0 = Point(x_outlet, y_outlet) @@ -273,9 +273,9 @@ def main(): _y = y_outlet pptmp = vector.Vector(output_pour_point) _cols = [ - (u"cat", "INTEGER PRIMARY KEY"), - (u"x", "DOUBLE PRECISION"), - (u"y", "DOUBLE PRECISION"), + ("cat", "INTEGER PRIMARY KEY"), + ("x", "DOUBLE PRECISION"), + ("y", "DOUBLE PRECISION"), ] pptmp.open("w", tab_name=output_pour_point, tab_cols=_cols) point0 = Point(_x, _y) diff --git a/src/vector/v.stream.profiler/v.stream.profiler.py b/src/vector/v.stream.profiler/v.stream.profiler.py index 83561cf52b..0130ad3a72 100644 --- a/src/vector/v.stream.profiler/v.stream.profiler.py +++ b/src/vector/v.stream.profiler/v.stream.profiler.py @@ -220,7 +220,7 @@ def main(): _dx = np.diff(coords[:, 0]) _dy = np.diff(coords[:, 1]) - x_downstream_0 = np.hstack((0, np.cumsum((_dx ** 2 + _dy ** 2) ** 0.5))) + x_downstream_0 = np.hstack((0, np.cumsum((_dx**2 + _dy**2) ** 0.5))) x_downstream = x_downstream_0.copy() elif options["direction"] == "upstream": diff --git a/src/vector/v.transects/v.transects.py b/src/vector/v.transects/v.transects.py index b5d4b2b5a0..db59ae2b00 100755 --- a/src/vector/v.transects/v.transects.py +++ b/src/vector/v.transects/v.transects.py @@ -236,7 +236,7 @@ def NR(ip, fp): """!Take a vector, normalize and rotate it 90 degrees.""" x = fp[0] - ip[0] y = fp[1] - ip[1] - r = sqrt(x ** 2 + y ** 2) + r = sqrt(x**2 + y**2) return array([-y / r, x / r])