From 441ca1ebe232d330c33c56f94a2d045382b2f2ab Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Wed, 5 Jun 2024 22:46:39 +0100 Subject: [PATCH 1/5] chore: Update dependency to AFMReader With renaming `topofileformats` > `AFMReader` and removing the former from PyPI we had to update the dependency. Currently two tests fail... ``` FAILED tests/test_io.py::test_load_scan_asd - assert -1368044348.3393068 == -71724923530211.84 FAILED tests/test_io.py::test_load_scan_get_data[load_scan_asd-197-image_shape5--673381139990.2344-file_122-2.0] - assert -12843725.967220962 == -673381139990.2344 ``` --- pyproject.toml | 2 +- topostats/io.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 05c3531503..289918d951 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ keywords = [ ] requires-python = ">=3.9" dependencies = [ + "AFMReader", "h5py", "igor2", "matplotlib", @@ -51,7 +52,6 @@ dependencies = [ "seaborn", "snoop", "tifffile", - "topofileformats", "tqdm", ] diff --git a/topostats/io.py b/topostats/io.py index a967f3251b..5679f288d9 100644 --- a/topostats/io.py +++ b/topostats/io.py @@ -19,9 +19,9 @@ import pandas as pd import pySPM import tifffile +from AFMReader import asd from igor2 import binarywave from ruamel.yaml import YAML, YAMLError -from topofileformats import asd from topostats.logs.logs import LOGGER_NAME From 87b998b7888a07afc5bc75d1ee0b3d36a422f9ca Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Wed, 5 Jun 2024 22:48:36 +0100 Subject: [PATCH 2/5] docs(installation): improve installing development instructions --- docs/installation.md | 66 +++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 4d0dc5d6fb..3c2133f21d 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -64,7 +64,7 @@ pip install topostats==2.0.0 For more information on using `pip` to install and manage packages please refer to the [pip documentation](https://pip.pypa.io/en/stable/user_guide/). -### Cloning from GitHub +### Installing from GitHub You may wish to consider cloning and installing TopoStats from GitHub if... @@ -73,42 +73,45 @@ You may wish to consider cloning and installing TopoStats from GitHub if... - If you have found an issue in a released version and want to see if it has been fixed in the unreleased version. - If you wish to develop and extend TopoStats with new features yourself. -If you do not have Git already installed please see [Git](installation#git). If you intend to contribute to the -development of TopoStats please read through the [contributing](contributing) section. +There are two options to install from GitHub, which you use will depend on what you want to do. -If you are familiar with the command line then you can clone and install TopoStats with the following _after_ activating -your virtual environment. +1. Using PyPI to install directly. +2. Clone the repository and install from there. + +If all you want to do is use the development version of TopoStats then you can use option 1. If you wish to change the +underlying code you should use option 2. + +#### Installing from GitHub using PyPI + +[`pip`][pip] supports [installing packages from GitHub][pip_github]. To install the `main` branch of TopoStats use the +following in your Virtual Environment. ```bash -git clone https://github.com/AFM-SPM/TopoStats.git -# If you have SSH access configured to GitHub then you can use -git clone git@github.com:AFM-SPM/TopoStats.git +pip install git+https://github.com/AFM-SPM/TopoStats.git@main ``` -#### Cloning Using GitKraken - -If you are using GitKraken you can clone the repository by selecting "Clone" and then "GitHub.com" and typing -`TopoStats` into the box next to "Repository to Clone" and you should be presented with the option of selecting -"TopoStats" from the AFM-SPM organisation. +You can install any branch on GitHub by modifying the last argument (`@main`) to the branch you wish to install, +e.g. `@another_branch` would install the `another_branch` (if it existed). -Alternatively you can "Clone with URL" and enter `https://github.com/AFM-SPM/TopoStats.git` as the URL to clone from, -selecting a destination to clone to. +#### Cloning the Repository and installing -#### Installing TopoStats from the Cloned Repository +If you do not have Git already installed please see [Git](installation#git). If you intend to contribute to the +development of TopoStats please read through the [contributing](contributing) section. -Once cloned you will have to open a Terminal and navigate to the directory you cloned and _after_ activating your -virtual environment install TopoStats with the following. +If you are familiar with the command line then you can clone and install TopoStats with the following _after_ activating +your virtual environment. By installing in editable mode (with the `-e` flag) switching branches will make the branch +available. ```bash -cd /path/to/where/topostats/was/cloned/TopoStats -pip install . +cd ~/where/to/clone +git clone git@github.com:AFM-SPM/TopoStats.git +cd TopoStats +pip install -e . ``` -If you wish to make changes to the code and test then make a `git branch`, make your changes and install in editable mode, -i.e. `pip install -e .`. - If you plan to contribute to development by adding features or address an existing -[issue](https://github.com/AFM-SPM/TopoStats/issues) please refer to the [contributing](contributing) section. +[issue](https://github.com/AFM-SPM/TopoStats/issues) please refer to the [contributing](contributing) section and pay +particular attention to the section about installing additional dependencies. We include [notebooks](notebooks) which show how to use different aspects of TopoStats. If you wish to try these out the [Jupyter Noteooks](https://jupyter.org/) then you can install the dependencies that are required from the cloned @@ -118,12 +121,19 @@ TopoStats repository using... pip install ".[notebooks]" ``` +#### Cloning Using GitKraken + +If you are using GitKraken you can clone the repository by selecting "Clone" and then "GitHub.com" and typing +`TopoStats` into the box next to "Repository to Clone" and you should be presented with the option of selecting +"TopoStats" from the AFM-SPM organisation. Once cloned follow the above instructions to install with `pip` under your +virtual environment. + ## Tests One of the major changes in the refactoring is the introduction of unit tests. These require certain packages to be installed which are not installed to your virtual environment by [setuptools](https://setuptools.pypa.io/en/latest/setuptools.html) in the above steps. If you are intending to modify or -contribute to the development of TopoStats and making changes to the code base you will likely want to be able to run +contribute to the development of TopoStats or make changes to the code base you will likely want to be able to run the tests. Install the necessary dependencies to do so with... ```bash @@ -135,9 +145,13 @@ pytest ## Git -[Git](https://git.vc) is a version control system for managing software development and is required to be installed on +[Git][git] is a version control system for managing software development and is required to be installed on your computer in order to clone the TopoStats repository. Instructions on installing Git can be found at [Git Guides - install git](https://github.com/git-guides/install-git). A nice Graphical User Interface for working with Git is [GitKraken](https://www.gitkraken.com/) which includes everything you need. + +[git]: https://git.vc +[pip]: https://pypi.org/project/pip/ +[pip_github]: https://pip.pypa.io/en/stable/getting-started/#install-a-package-from-github From 389fb104568d6e28907f985cdbb5e311bd37f9af Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Thu, 6 Jun 2024 09:50:38 +0100 Subject: [PATCH 3/5] tests(io): Updating target array sums for loading asd files As detailed in #851 the sum of the arrays changes on switching from `topofileformats` > `AFMReader`. The issue notes some details of investigation. --- tests/test_io.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_io.py b/tests/test_io.py index 5007b50e75..6f77be663d 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -561,7 +561,7 @@ def test_load_scan_asd(load_scan_asd: LoadScans) -> None: frames, px_to_nm_scaling = load_scan_asd.load_asd() assert isinstance(frames, np.ndarray) assert frames.shape == (197, 200, 200) - assert frames.sum() == -71724923530211.84 + assert frames.sum() == -1368044348.3393068 assert isinstance(px_to_nm_scaling, float) assert px_to_nm_scaling == 2.0 @@ -698,12 +698,14 @@ def test__spm_pixel_to_nm_scaling( @pytest.mark.parametrize( ("load_scan_object", "length", "image_shape", "image_sum", "filename", "pixel_to_nm_scaling"), [ - ("load_scan_spm", 1, (1024, 1024), 30695369.188316286, "minicircle", 0.4940029296875), - ("load_scan_ibw", 1, (512, 512), -218091520.0, "minicircle2", 1.5625), - ("load_scan_jpk", 1, (256, 256), 286598232.9308627, "file", 1.2770176335964876), - ("load_scan_gwy", 1, (512, 512), 33836850.232917726, "file", 0.8468632812499975), - ("load_scan_topostats", 1, (1024, 1024), 184140.8593819073, "file", 0.4940029296875), - ("load_scan_asd", 197, (200, 200), -673381139990.2344, "file_122", 2.0), + pytest.param("load_scan_spm", 1, (1024, 1024), 30695369.188316286, "minicircle", 0.4940029296875, id="spm"), + pytest.param("load_scan_ibw", 1, (512, 512), -218091520.0, "minicircle2", 1.5625, id="ibw"), + pytest.param("load_scan_jpk", 1, (256, 256), 286598232.9308627, "file", 1.2770176335964876, id="jpk"), + pytest.param("load_scan_gwy", 1, (512, 512), 33836850.232917726, "file", 0.8468632812499975, id="gwy"), + pytest.param( + "load_scan_topostats", 1, (1024, 1024), 184140.8593819073, "file", 0.4940029296875, id="topostats" + ), + pytest.param("load_scan_asd", 197, (200, 200), -12843725.967220962, "file_122", 2.0, id="asd"), ], ) def test_load_scan_get_data( From 47f31a9be830c91e231914fddbd62e2695666ac0 Mon Sep 17 00:00:00 2001 From: Max Gamill Date: Thu, 6 Jun 2024 11:26:04 +0100 Subject: [PATCH 4/5] add orig err msg in broad channel try/except --- topostats/io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/topostats/io.py b/topostats/io.py index a967f3251b..903925f08c 100644 --- a/topostats/io.py +++ b/topostats/io.py @@ -1026,6 +1026,7 @@ def get_data(self) -> None: self.image, self.pixel_to_nm_scaling = suffix_to_loader[suffix]() except Exception as e: if "Channel" in str(e) and "not found" in str(e): + LOGGER.warning(e) # log the specific error message LOGGER.warning(f"[{self.filename}] Channel {self.channel} not found, skipping image.") else: raise From 2d9d15a5f6965c7d6bd30ee006e8157a29c1daed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:31:04 +0000 Subject: [PATCH 5/5] [pre-commit.ci] Fixing issues with pre-commit --- topostats/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topostats/io.py b/topostats/io.py index 903925f08c..e4ba7850ec 100644 --- a/topostats/io.py +++ b/topostats/io.py @@ -1026,7 +1026,7 @@ def get_data(self) -> None: self.image, self.pixel_to_nm_scaling = suffix_to_loader[suffix]() except Exception as e: if "Channel" in str(e) and "not found" in str(e): - LOGGER.warning(e) # log the specific error message + LOGGER.warning(e) # log the specific error message LOGGER.warning(f"[{self.filename}] Channel {self.channel} not found, skipping image.") else: raise