Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
anikaweinmann committed Dec 18, 2024
1 parent fe356c7 commit 9f74de6
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 24 deletions.
9 changes: 7 additions & 2 deletions src/grass_gis_helpers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def general_cleanup(
for rmg_wr in rm_groups_w_rasters:
if grass.find_file(name=rmg_wr, element="group")["file"]:
group_rasters = grass.parse_command(
"i.group", flags="lg", group=rmg_wr,
"i.group",
flags="lg",
group=rmg_wr,
)
rm_rasters.extend(group_rasters)
grass.run_command("g.remove", type="group", name=rmg, **kwargs)
Expand All @@ -72,7 +74,10 @@ def general_cleanup(
if find_reg.get("file"):
grass.run_command("g.region", region=orig_region)
grass.run_command(
"g.remove", type="region", name=orig_region, **kwargs,
"g.remove",
type="region",
name=orig_region,
**kwargs,
)
for rmreg in rm_regions:
find_reg = grass.find_file(name=rmreg, element="windows")
Expand Down
14 changes: 10 additions & 4 deletions src/grass_gis_helpers/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def get_list_of_tindex_locations(tindex, aoi=None):
tiles = [
val[0]
for val in grass.vector_db_select(
tindex_clipped, columns="location",
tindex_clipped,
columns="location",
)["values"].values()
]
finally:
Expand Down Expand Up @@ -284,7 +285,10 @@ def get_xyz_file_infos(xyz_file, separator="space"):


def import_single_local_xyz_file(
xyz_file, output, use_cur_reg=False, separator="space",
xyz_file,
output,
use_cur_reg=False,
separator="space",
):
"""Import single XYZ file.
Expand All @@ -300,7 +304,8 @@ def import_single_local_xyz_file(
"""
res, xyz_reg, shift_needed = get_xyz_file_infos(
xyz_file, separator=separator,
xyz_file,
separator=separator,
)
# check if aoi overlaps
if use_cur_reg:
Expand Down Expand Up @@ -440,7 +445,8 @@ def import_local_vector_data(aoi_map, local_data_dir, rm_vectors, output):
recursive=True,
)
shp_files = glob.glob(
os.path.join(local_data_dir, "**", "*.shp"), recursive=True,
os.path.join(local_data_dir, "**", "*.shp"),
recursive=True,
)
files.extend(shp_files)

Expand Down
4 changes: 3 additions & 1 deletion src/grass_gis_helpers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def log_memory(grassenv=None):
if not grassenv:
grassenv = grass.gisenv()
cmd = grass.Popen(
f"df -h {grassenv['GISDBASE']}", shell=True, stdout=subprocess.PIPE,
f"df -h {grassenv['GISDBASE']}",
shell=True,
stdout=subprocess.PIPE,
)
grass.message(
_(
Expand Down
10 changes: 8 additions & 2 deletions src/grass_gis_helpers/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def get_location_size():
"""Log size of current location."""
current_gisdbase = grass.gisenv()["GISDBASE"]
cmd = grass.Popen(
f"df -h {current_gisdbase}", shell=True, stdout=subprocess.PIPE,
f"df -h {current_gisdbase}",
shell=True,
stdout=subprocess.PIPE,
)
grass.message(
_(
Expand Down Expand Up @@ -67,7 +69,11 @@ def create_tmp_location(epsg=4326):
# create temp location from input without import
grass.verbose(_(f"Creating temporary location with EPSG:{epsg}..."))
grass.run_command(
"g.proj", flags="c", location=tmp_loc, quiet=True, **epsg_arg,
"g.proj",
flags="c",
location=tmp_loc,
quiet=True,
**epsg_arg,
)

# switch to temp location
Expand Down
4 changes: 3 additions & 1 deletion src/grass_gis_helpers/open_geodata_germany/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def fix_corrupted_data(file):
# remove corrupted data from TXT DOM files
if not os.path.exists(f"{file}.bak"):
with fileinput.FileInput(
file, inplace=True, backup=".bak",
file,
inplace=True,
backup=".bak",
) as file_object:
for line in file_object:
# two times replace of white spaces, since some lines contain
Expand Down
11 changes: 6 additions & 5 deletions src/grass_gis_helpers/open_geodata_germany/federal_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ def import_administrative_boundaries(output, aoi=None, level="KRS"):
response = requests.get(url)
if response.status_code != 200:
grass.fatal(

"The data import of the administrative boundaries are "
"currently not available.",

"The data import of the administrative boundaries are "
"currently not available.",
)

# download and import administrative boundaries
Expand Down Expand Up @@ -145,7 +143,10 @@ def get_federal_states(federal_state, federal_state_file):
fs_list_str = fs_file.read().strip()
if fs_list_str == "":
grass.fatal(
_("Federal state in <federal_state_file> is empty string!"),
_(
"Federal state in <federal_state_file> is empty "
"string!",
),
)
elif federal_state:
fs_list_str = federal_state.strip()
Expand Down
7 changes: 6 additions & 1 deletion src/grass_gis_helpers/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@


def run_module_parallel(
module, module_kwargs, tile_list, nprocs, uid, parallel=True,
module,
module_kwargs,
tile_list,
nprocs,
uid,
parallel=True,
):
"""Running a module in parallel on a grid."""
# save current mapset
Expand Down
6 changes: 5 additions & 1 deletion src/grass_gis_helpers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def get_number_of_grass_elements():


def check_number_of_grass_elements(
ref_num_rast, ref_num_vect, ref_num_gr, ref_num_reg, ref_num_mapsets,
ref_num_rast,
ref_num_vect,
ref_num_gr,
ref_num_reg,
ref_num_mapsets,
):
"""Check the number of grass elements.
Expand Down
16 changes: 13 additions & 3 deletions src/grass_gis_helpers/tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ def create_grid(tile_size, grid_prefix, sid, area=None):
if dist_ns <= float(tile_size) and dist_ew <= float(tile_size):
grass.run_command("v.in.region", output=grid, quiet=True)
grass.run_command(
"v.db.addtable", map=grid, columns="cat int", quiet=True,
"v.db.addtable",
map=grid,
columns="cat int",
quiet=True,
)
else:
# set region with tile_size
grass.run_command("g.region", res=tile_size, flags="a", quiet=True)

# create grid
grass.run_command(
"v.mkgrid", map=grid, box=f"{tile_size},{tile_size}", quiet=True,
"v.mkgrid",
map=grid,
box=f"{tile_size},{tile_size}",
quiet=True,
)
# reset region
reset_region(orig_region)
Expand Down Expand Up @@ -86,7 +92,11 @@ def create_grid(tile_size, grid_prefix, sid, area=None):
# create list of tiles
tiles_num_list = list(
grass.parse_command(
"v.db.select", map=grid_name, columns="cat", flags="c", quiet=True,
"v.db.select",
map=grid_name,
columns="cat",
flags="c",
quiet=True,
).keys(),
)

Expand Down
8 changes: 4 additions & 4 deletions src/grass_gis_helpers/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def get_gdalinfo_returncodes(input):
"""Return return codes from reading input file with gdalinfo."""
gdalinfo_cmd = ["gdalinfo", "-mm", input]
p_gdalinfo = subprocess.Popen(
gdalinfo_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
gdalinfo_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
gdalinfo_err = p_gdalinfo.communicate()[1].decode("utf-8")
gdalinfo_returncode = p_gdalinfo.returncode
Expand All @@ -48,7 +50,5 @@ def check_valid_rasterdata(input, strict=True):
),
)
# less strict check: fails only if bands can't be read
elif gdalinfo_returncode != 0 or (
"TIFFReadEncodedStrip" in gdalinfo_err
):
elif gdalinfo_returncode != 0 or ("TIFFReadEncodedStrip" in gdalinfo_err):
grass.fatal(_(f"<{input}> is a broken file"))

0 comments on commit 9f74de6

Please sign in to comment.