pesekon2 / grass

GRASS GIS - free and open source Geographic Information System (GIS)
https://grass.osgeo.org
Other
0 stars 0 forks source link

change listcomps to genexps #20

Open pesekon2 opened 1 year ago

pesekon2 commented 1 year ago

Probably not all, but at least some should be possible, saving memory:

> ag "for .* in .* for .* in .*"
python/grass/pygrass/vector/geometry.py
1520:            [" ".join(["%f" % coord for coord in pnt]) for pnt in line.to_list()]

python/grass/pygrass/modules/grid/grid.py
62:    for fil in (fi for fi in os.listdir(path_src) if fi.isupper()):
127:            [(k.strip(), v.strip()) for k, v in [row.split(":", 1) for row in gfile]]

python/grass/pygrass/modules/interface/env.py
19:                for k, v in [row.split(":", 1) for row in grc if row]

doc/notebooks/parallelization_tutorial.ipynb
112:    "As part of [GRASS GIS Python API](https://grass.osgeo.org/grass-stable/manuals/libpython/index.html), [GridModule](https://grass.osgeo.org/grass-stable/manuals/libpython/pygrass.modules.grid.html) decomposes input data into rectangular tiles, executes a given tool for each tile in parallel, and merges the results. Effectively, tiling is applied virtually (using computational region), determining the spatial extent of analysis for each parallel process. In some cases such as moving window analysis, tiles need to overlap to get correct results. Note that GridModule can be fairly inefficient due to the overhead from merging results back and is therefore best suited for computationally-itensive tasks such as interpolation."

vector/v.db.select/v.db.select.html
201:This format is for special uses in scripting, for example, in combination

utils/g.html2man/g.html2man.py
22:        return [fixed for item in content for fixed in [fix(item)] if fixed is not None]

utils/mkhtml.py
140:        for ptype, purl in (p.split("=") for p in proxy.split(",")):

gui/wxpython/gmodeler/model.py
2737:    for i in [key for key, value in paramFlags.items() if value[0].data == "True"]:
3238:    for i in [key for key, value in paramFlags.items() if value == "True"]:

gui/wxpython/animation/utils.py
304:    name = ";".join([item for sublist in cmds for item in sublist])

gui/wxpython/mapwin/analysis.py
390:            [str(item) for sublist in coordinates for item in sublist]

man/parser_standard_options.py
118:        self.columns = sorted(set([key for _, d in self.options for key in d.keys()]))

raster/r.geomorphon/r.geomorphon.html
59:<DD>All distance parameters (search, skip, flat distances) are supplied as meters instead of cells (default). To avoid situation when supplied distances is smaller than one cell program first check if supplied distance is longer than one cell in both NS and WE directions. For LatLong projection only NS distance checked, because in latitude angular unit comprise always bigger or equal distance than longitude one. If distance is supplied in cells, For all projections is recalculated into meters according formula: <code>number_of_cells*resolution_along_NS_direction</code>. It is important if geomorphons are calculated for large areas in LatLong projection.</DD>

scripts/d.rast.edit/d.rast.edit.py
568:            self.changed = [[False for c in row] for row in self.values]

scripts/g.extension/g.extension.py
2782:        for ptype, purl in (p.split("=") for p in options["proxy"].split(",")):
pesekon2 commented 1 year ago

Actually, should rethink this. Listcomps are faster than genexps unless you are doing any() and expect Falseto happenearly`. Should be used only when memory is ore important than speed.

pesekon2 commented 1 year ago

The same applies to tuples created from listcomps:

> ag "tuple.*\[.*for.*in"
python/grass/pygrass/vector/geometry.py
1142:                self.append(tuple([float(e) for e in coord.split(" ")]))

python/grass/pygrass/vector/testsuite/test_vector.py
39:            coords = tuple([pnt.coords() for pnt in vect[:3]])
41:            coords = tuple([pnt.coords() for pnt in vect[1:3]])

python/grass/pygrass/raster/buffer.py
7:CELL = tuple([getattr(np, attr) for attr in _CELL if hasattr(np, attr)])
9:FCELL = tuple([getattr(np, attr) for attr in _FCELL if hasattr(np, attr)])
11:DCELL = tuple([getattr(np, attr) for attr in _DCELL if hasattr(np, attr)])

python/grass/script/db.py
194:    result = [tuple(x.rstrip(os.linesep).split(args["sep"])) for x in ofile.readlines()]

gui/wxpython/core/settings.py
75:        return tuple(int(hexcode[i : i + 2], 16) for i in range(0, len(hexcode), 2))

gui/wxpython/animation/provider.py
635:    cmdTuple[1]["bgcolor"] = bgcolor = ":".join([str(part) for part in bgcolor])

scripts/d.rast.leg/d.rast.leg.py
107:    f = tuple([float(x) for x in s.split()])