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

chore: Update dependency to AFMReader #852

Merged
merged 6 commits into from
Jun 6, 2024
Merged
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
66 changes: 40 additions & 26 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ keywords = [
]
requires-python = ">=3.9"
dependencies = [
"AFMReader",
"h5py",
"igor2",
"matplotlib",
Expand All @@ -51,7 +52,6 @@ dependencies = [
"seaborn",
"snoop",
"tifffile",
"topofileformats",
"tqdm",
]

Expand Down
16 changes: 9 additions & 7 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion topostats/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading