Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add additional linting to package #10

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions ocsmesh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import pathlib
from importlib import util
import tempfile
import os
import sys
import pathlib
import platform

import sys
import tempfile
from importlib import util

try:
import jigsawpy # noqa: F401
except OSError as e:
pkg = util.find_spec("jigsawpy")
libjigsaw = {
"Windows": "jigsaw.dll",
"Linux": "libjigsaw.so",
"Darwin": "libjigsaw.dylib"
}[platform.system()]
"Windows": "jigsaw.dll",
"Linux": "libjigsaw.so",
"Darwin": "libjigsaw.dylib",
}[platform.system()]
tgt_libpath = pathlib.Path(pkg.origin).parent / "_lib" / libjigsaw
pyenv = pathlib.Path("/".join(sys.executable.split('/')[:-2]))
src_libpath = pyenv / 'lib' / libjigsaw
pyenv = pathlib.Path("/".join(sys.executable.split("/")[:-2]))
src_libpath = pyenv / "lib" / libjigsaw
if not src_libpath.is_file():
raise e

os.symlink(src_libpath, tgt_libpath)


from .driver import JigsawDriver
from .geom import Geom
from .hfun import Hfun
from .raster import Raster
from .driver import JigsawDriver
from .mesh import Mesh
from .raster import Raster

if util.find_spec("colored_traceback") is not None:
import colored_traceback

colored_traceback.add_hook(always=True)

tmpdir = str(pathlib.Path(tempfile.gettempdir()+'/ocsmesh'))+'/'
tmpdir = str(pathlib.Path(tempfile.gettempdir() + "/ocsmesh")) + "/"
os.makedirs(tmpdir, exist_ok=True)

__all__ = [
Expand Down
149 changes: 84 additions & 65 deletions ocsmesh/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import argparse

from ocsmesh.ops import combine_geometry, combine_hfun
from ocsmesh.cli.cli import CmdCli
from ocsmesh.ops import combine_geometry, combine_hfun


class OCSMesh:

def __init__(self, args, ocsmesh_cli):
self._args = args
self._cli = ocsmesh_cli

def main(self):

if self._args.command == 'geom':
if self._args.command == "geom":

nprocs = self._args.nprocs
if self._args.geom_nprocs:
Expand All @@ -34,10 +33,11 @@ def main(self):
overlap=self._args.overlap,
nprocs=nprocs,
out_crs=self._args.output_crs,
base_crs=self._args.mesh_crs)
base_crs=self._args.mesh_crs,
)
combine_geometry(**arg_dict)

elif self._args.command == 'hfun':
elif self._args.command == "hfun":

nprocs = self._args.nprocs
if self._args.hfun_nprocs:
Expand All @@ -57,10 +57,11 @@ def main(self):
chunk_size=self._args.chunk_size,
overlap=self._args.overlap,
method=self._args.method,
nprocs=nprocs)
nprocs=nprocs,
)
combine_hfun(**arg_dict)

elif self._args.command == 'scripts':
elif self._args.command == "scripts":
self._cli.execute(self._args)


Expand All @@ -69,90 +70,108 @@ def create_parser():

common_parser.add_argument("--log-level", choices=["info", "debug", "warning"])
common_parser.add_argument(
"--nprocs", type=int, help="Number of parallel threads to use when "
"computing geom and hfun.")
"--nprocs",
type=int,
help="Number of parallel threads to use when " "computing geom and hfun.",
)
common_parser.add_argument(
"--geom-nprocs", type=int, help="Number of processors used when "
"computing the geom, overrides --nprocs argument.")
"--geom-nprocs",
type=int,
help="Number of processors used when "
"computing the geom, overrides --nprocs argument.",
)
common_parser.add_argument(
"--hfun-nprocs", type=int, help="Number of processors used when "
"computing the hfun, overrides --nprocs argument.")
"--hfun-nprocs",
type=int,
help="Number of processors used when "
"computing the hfun, overrides --nprocs argument.",
)
common_parser.add_argument(
"--chunk-size",
help='Size of square window to be used for processing the raster')
help="Size of square window to be used for processing the raster",
)
common_parser.add_argument(
"--overlap",
help='Size of overlap to be used for between raster windows')
"--overlap", help="Size of overlap to be used for between raster windows"
)

sub_parse_common = {
'parents': [common_parser],
'add_help': False
}
sub_parse_common = {"parents": [common_parser], "add_help": False}

parser = argparse.ArgumentParser(**sub_parse_common)
subp = parser.add_subparsers(dest='command')

geom_parser = subp.add_parser('geom', **sub_parse_common)
geom_subp = geom_parser.add_subparsers(dest='geom_cmd')
geom_bld = geom_subp.add_parser('build', **sub_parse_common)
geom_bld.add_argument('-o', '--output', required=True)
geom_bld.add_argument('-f', '--output-format', default="shapefile")
geom_bld.add_argument('--output-crs', default="EPSG:4326")
geom_bld.add_argument('--mesh', help='Mesh to extract hull from')
geom_bld.add_argument(
'--ignore-mesh-boundary', action='store_true',
help='Flag to ignore mesh boundary for final boundary union')
subp = parser.add_subparsers(dest="command")

geom_parser = subp.add_parser("geom", **sub_parse_common)
geom_subp = geom_parser.add_subparsers(dest="geom_cmd")
geom_bld = geom_subp.add_parser("build", **sub_parse_common)
geom_bld.add_argument("-o", "--output", required=True)
geom_bld.add_argument("-f", "--output-format", default="shapefile")
geom_bld.add_argument("--output-crs", default="EPSG:4326")
geom_bld.add_argument("--mesh", help="Mesh to extract hull from")
geom_bld.add_argument(
'--mesh-crs', help='CRS of the input base mesh (overrides)')
"--ignore-mesh-boundary",
action="store_true",
help="Flag to ignore mesh boundary for final boundary union",
)
geom_bld.add_argument("--mesh-crs", help="CRS of the input base mesh (overrides)")
geom_bld.add_argument("--zmin", type=float, help="Maximum elevation to consider")
geom_bld.add_argument("--zmax", type=float, help="Maximum elevation to consider")
geom_bld.add_argument(
'--zmin', type=float,
help='Maximum elevation to consider')
geom_bld.add_argument(
'--zmax', type=float,
help='Maximum elevation to consider')
geom_bld.add_argument(
'dem', nargs='+',
help='Digital elevation model list to be used in geometry creation')

hfun_parser = subp.add_parser('hfun', **sub_parse_common)
hfun_subp = hfun_parser.add_subparsers(dest='hfun_cmd')
hfun_bld = hfun_subp.add_parser('build', **sub_parse_common)
hfun_bld.add_argument('-o', '--output', required=True)
hfun_bld.add_argument('-f', '--output-format', default="2dm")
hfun_bld.add_argument('--mesh', help='Base mesh size function')
hfun_bld.add_argument(
'--hmax', type=float, help='Maximum element size')
hfun_bld.add_argument(
'--hmin', type=float, help='Minimum element size')
"dem",
nargs="+",
help="Digital elevation model list to be used in geometry creation",
)

hfun_parser = subp.add_parser("hfun", **sub_parse_common)
hfun_subp = hfun_parser.add_subparsers(dest="hfun_cmd")
hfun_bld = hfun_subp.add_parser("build", **sub_parse_common)
hfun_bld.add_argument("-o", "--output", required=True)
hfun_bld.add_argument("-f", "--output-format", default="2dm")
hfun_bld.add_argument("--mesh", help="Base mesh size function")
hfun_bld.add_argument("--hmax", type=float, help="Maximum element size")
hfun_bld.add_argument("--hmin", type=float, help="Minimum element size")
hfun_bld.add_argument(
'--contour', action='append', nargs='+', type=float, default=[],
"--contour",
action="append",
nargs="+",
type=float,
default=[],
help="Each contour's (level, [expansion, target])"
" to be applied on all size functions in collector")
" to be applied on all size functions in collector",
)
hfun_bld.add_argument(
'--constant',
action='append', nargs=2, type=float, dest='constants',
metavar='CONST_DEFN', default=[],
"--constant",
action="append",
nargs=2,
type=float,
dest="constants",
metavar="CONST_DEFN",
default=[],
help="Specify constant mesh size above a given contour level"
" by passing (lower_bound, target_size) for each constant")
" by passing (lower_bound, target_size) for each constant",
)
hfun_bld.add_argument(
'--method', type=str, default='exact',
help='Method used to calculate size function ({exact} |fast)')
"--method",
type=str,
default="exact",
help="Method used to calculate size function ({exact} |fast)",
)
hfun_bld.add_argument(
'dem', nargs='+',
help='Digital elevation model list to be used in size function creation')
"dem",
nargs="+",
help="Digital elevation model list to be used in size function creation",
)

# Scripts don't use common arguments as they are standalon code
scripts_parser = subp.add_parser('scripts')
scripts_parser = subp.add_parser("scripts")
cmd_cli = CmdCli(scripts_parser)

return parser, cmd_cli


def main():
parser, ocsmesh_cli = create_parser()
# logger.init(args.log_level)
# logger.init(args.log_level)
OCSMesh(parser.parse_args(), ocsmesh_cli).main()


if __name__ == '__main__':
if __name__ == "__main__":
main()
11 changes: 6 additions & 5 deletions ocsmesh/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import warnings

from ocsmesh.cli.remesh_by_shape_factor import RemeshByShape
from ocsmesh.cli.remesh import RemeshByDEM
from ocsmesh.cli.mesh_upgrader import MeshUpgrader
from ocsmesh.cli.remesh import RemeshByDEM
from ocsmesh.cli.remesh_by_shape_factor import RemeshByShape

class CmdCli:

class CmdCli:
def __init__(self, parser):

# TODO: Later add non experimental CLI through this class
self._script_dict = {}

scripts_subp = parser.add_subparsers(dest='scripts_cmd')
scripts_subp = parser.add_subparsers(dest="scripts_cmd")
for cls in [RemeshByShape, RemeshByDEM, MeshUpgrader]:
item = cls(scripts_subp)
self._script_dict[item.script_name] = item
Expand All @@ -20,6 +20,7 @@ def execute(self, args):

warnings.warn(
"Scripts CLI is used for experimental new features"
" and is subject to change.")
" and is subject to change."
)

self._script_dict[args.scripts_cmd].run(args)
Loading