From 8bc49f971fe071247c1b37b4c9511c750ea4dc21 Mon Sep 17 00:00:00 2001 From: Dilawar Singh Date: Fri, 8 Jul 2022 16:06:51 +0000 Subject: [PATCH] refactor: Removed loguru Loguru threw runtime exception on Windows in #11 --- .github/workflows/python-app.yml | 2 +- CHANGELOG.md | 4 +++ figures/ECGImage.result.png | Bin 52965 -> 52965 bytes figures/graph_with_grid.result.png | Bin 30097 -> 30097 bytes figures/graphs_1.result.png | Bin 31938 -> 31938 bytes figures/trimmed.result.png | Bin 34609 -> 34609 bytes plotdigitizer/locate.py | 6 ++--- plotdigitizer/plotdigitizer.py | 41 ++++++++++------------------- plotdigitizer/trajectory.py | 8 +++--- poetry.lock | 32 ++-------------------- pyproject.toml | 3 +-- 11 files changed, 28 insertions(+), 68 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5ad9494..6f53139 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest, macos-latest ] - python-version: ['3.7', '3.9'] + python-version: ['3.7', '3.9', '3.10'] steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4504157..a03bf1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# [0.2.3] 2022-07-08 + +- Removed loguru. #11 + # 2021-06-30: v0.2.2 - Fixed regression: axis transformation was broken. diff --git a/figures/ECGImage.result.png b/figures/ECGImage.result.png index 597159f3a06ae71581f277c56fcc394136585cf3..9a54eb7a855c4772dc9002dac57069a085b931c9 100644 GIT binary patch delta 45 zcmaDlm-*>j<_T^Jrg}y?3K=CO1;tkS`nicE1v&X8Ihjd%`9j<_T^JCVECX3K=CO1;tkS`nicE1v&X8Ihjd%`9 delta 45 zcmbREnsMT5#tCi;CVECX3K=CO1;tkS`nicE1v&X8Ihjd%`92PG*u`eo?x2PG*u`eo?x T.List[geometry.Point]: @@ -148,10 +141,10 @@ def transform_axis(img, erase_near_axis: int = 0): T = axis_transformation(points_, locations_) p = geometry.find_origin(locations_) offCols, offRows = p.x, p.y - logger.info(f"{locations_} → origin {offCols}, {offRows}") + logging.info(f"{locations_} → origin {offCols}, {offRows}") img[:, : offCols + erase_near_axis] = params_["background"] img[-offRows - erase_near_axis :, :] = params_["background"] - logger.debug(f"Tranformation params: {T}") + logging.debug(f"Tranformation params: {T}") return T @@ -184,7 +177,7 @@ def _find_trajectory_colors(img, plot: bool = False) -> T.Tuple[int, T.List[int] # we assume that bgcolor is close to white. if bgcolor < 128: - logger.error( + logging.error( "I computed that background is 'dark' which is unacceptable to me." ) quit(-1) @@ -203,7 +196,7 @@ def compute_foregrond_background_stats(img) -> T.Dict[str, float]: bgcolor, trajcolors = _find_trajectory_colors(img) params["background"] = bgcolor params["timeseries_colors"] = trajcolors - logger.info(f" computed parameters: {params}") + logging.info(f" computed parameters: {params}") return params @@ -214,7 +207,7 @@ def process_image(img): T = transform_axis(img, erase_near_axis=3) assert img.std() > 0.0, "No data in image" - # logger.info(f" {img.mean()} {img.std()}") + # logging.info(f" {img.mean()} {img.std()}") save_img_in_cache(img, f"{args_.INPUT.name}.transformed_axis.png") # extract the plot that has color which is farthest from the background. @@ -231,7 +224,7 @@ def run(args): infile = Path(args.INPUT) assert infile.exists(), f"{infile} does not exists." - logger.info(f"Extracting trajectories from {infile}") + logging.info(f"Extracting trajectories from {infile}") img_ = cv.imread(str(infile), 0) @@ -246,10 +239,10 @@ def run(args): points_ = list_to_points(args.data_point) locations_ = list_to_points(args.location) - logger.debug(f"data points {args.data_point} → location on image {args.location}") + logging.debug(f"data points {args.data_point} → location on image {args.location}") if len(locations_) != len(points_): - logger.warning( + logging.warning( "Either the location of data-points are not specified or their numbers don't" " match with given datapoints. Asking user..." ) @@ -275,7 +268,7 @@ def run(args): with open(outfile, "w") as f: for r in traj: f.write("%g %g\n" % (r)) - logger.info("Wrote trajectory to %s" % outfile) + logging.info("Wrote trajectory to %s" % outfile) def main(): @@ -324,12 +317,6 @@ def main(): action="store_true", help="Preprocess the image. Useful with bad resolution images.", ) - parser.add_argument( - "--debug", - required=False, - action="store_true", - help="Enable debug logger", - ) args = parser.parse_args() run(args) diff --git a/plotdigitizer/trajectory.py b/plotdigitizer/trajectory.py index bfd09b5..03e1d9a 100644 --- a/plotdigitizer/trajectory.py +++ b/plotdigitizer/trajectory.py @@ -3,10 +3,8 @@ import numpy as np import cv2 as cv - from collections import defaultdict - -from loguru import logger +import logging def _find_center(vec): @@ -19,7 +17,7 @@ def fit_trajectory_using_median(traj, T, img): r, _ = img.shape # x, y = zip(*sorted(traj.items())) - # logger.info((xvec, ys)) + # logging.info((xvec, ys)) for k in sorted(traj): x = k @@ -54,7 +52,7 @@ def _valid_px(val: int) -> int: def find_trajectory(img: np.ndarray, pixel: int, T): - logger.info(f"Extracting trajectory for color {pixel}") + logging.info(f"Extracting trajectory for color {pixel}") assert img.min() <= pixel <= img.max(), f"{pixel} is outside the range" # Find all pixels which belongs to a trajectory. diff --git a/poetry.lock b/poetry.lock index fce9272..dee57af 100644 --- a/poetry.lock +++ b/poetry.lock @@ -24,7 +24,7 @@ tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (> name = "colorama" version = "0.4.5" description = "Cross-platform colored terminal text." -category = "main" +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" @@ -94,21 +94,6 @@ python-versions = ">=3.7" [package.dependencies] typing-extensions = {version = "*", markers = "python_version < \"3.8\""} -[[package]] -name = "loguru" -version = "0.5.3" -description = "Python logging made (stupidly) simple" -category = "main" -optional = false -python-versions = ">=3.5" - -[package.dependencies] -colorama = {version = ">=0.3.4", markers = "sys_platform == \"win32\""} -win32-setctime = {version = ">=1.0.0", markers = "sys_platform == \"win32\""} - -[package.extras] -dev = ["codecov (>=2.0.15)", "colorama (>=0.3.4)", "flake8 (>=3.7.7)", "tox (>=3.9.0)", "tox-travis (>=0.12)", "pytest (>=4.6.2)", "pytest-cov (>=2.7.1)", "Sphinx (>=2.2.1)", "sphinx-autobuild (>=0.7.1)", "sphinx-rtd-theme (>=0.4.3)", "black (>=19.10b0)", "isort (>=5.1.1)"] - [[package]] name = "matplotlib" version = "3.5.2" @@ -317,17 +302,6 @@ category = "main" optional = false python-versions = ">=3.7" -[[package]] -name = "win32-setctime" -version = "1.1.0" -description = "A small Python utility to set file creation time on Windows" -category = "main" -optional = false -python-versions = ">=3.5" - -[package.extras] -dev = ["pytest (>=4.6.2)", "black (>=19.3b0)"] - [[package]] name = "zipp" version = "3.8.0" @@ -343,7 +317,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "6f58413b9ce81a1018189596be522b1d9745f00c14c78da1016f91eeeda2bdd2" +content-hash = "fe38a7461c5663d78de40c621a6a0f76badf01d1fd4b4beb4207440428b84732" [metadata.files] atomicwrites = [ @@ -413,7 +387,6 @@ kiwisolver = [ {file = "kiwisolver-1.4.3-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:130c6c35eded399d3967cf8a542c20b671f5ba85bd6f210f8b939f868360e9eb"}, {file = "kiwisolver-1.4.3.tar.gz", hash = "sha256:ab8a15c2750ae8d53e31f77a94f846d0a00772240f1c12817411fa2344351f86"}, ] -loguru = [] matplotlib = [ {file = "matplotlib-3.5.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:03bbb3f5f78836855e127b5dab228d99551ad0642918ccbf3067fcd52ac7ac5e"}, {file = "matplotlib-3.5.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:49a5938ed6ef9dda560f26ea930a2baae11ea99e1c2080c8714341ecfda72a89"}, @@ -489,5 +462,4 @@ typing-extensions = [ {file = "typing_extensions-4.3.0-py3-none-any.whl", hash = "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02"}, {file = "typing_extensions-4.3.0.tar.gz", hash = "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6"}, ] -win32-setctime = [] zipp = [] diff --git a/pyproject.toml b/pyproject.toml index 15f9ac6..86a62d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "plotdigitizer" -version = "0.2.2" +version = "0.2.3" description = "Extract raw data from plots images" authors = ["Dilawar Singh "] maintainers = ["Dilawar Singh "] @@ -13,7 +13,6 @@ python = "^3.7" opencv-python = "^4.5.1" numpy = "^1.19.5" matplotlib = "^3.3.4" -loguru = "^0.5.3" [tool.poetry.dev-dependencies] pytest = "^6.2.2"