-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ImperialCollegeLondon/basic-dev-docs
Add intro documentation for developers
- Loading branch information
Showing
4 changed files
with
148 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,71 @@ | ||
.. _creating_a_new_method: | ||
|
||
Creating a New Method | ||
===================== | ||
===================== | ||
In PyProBE :class:`Methods <pyprobe.methods.basemethod.BaseMethod>` are classes that | ||
perform further analysis of the data. They can be peformed on any | ||
:class:`~pyprobe.rawdata.RawData` or :class:`~pyprobe.result.Result` object. | ||
|
||
This document describes the standard format to be used for all PyProBE methods. | ||
Constructing your method in this way ensures compatibility with the rest of the | ||
PyProBE package, while keeping your code clean and easy to read. | ||
|
||
Start by creating your class, and an __init__ method. This is where all of the | ||
variable assignement is performed: | ||
1. Define the input variables to the method using the | ||
:meth:`~pyprobe.methods.basemethod.BaseMethod.variable` method. | ||
2. Perform the calculations using the input variables and any other functions defined | ||
inside this method class. | ||
3. Assign the results to the class attributes, which allows them to be read as | ||
:class:`~pyprobe.result.Result` objects. | ||
|
||
Then you can add any additional functions to perform your calculations. Keep these | ||
simple, defining all inputs as numpy arrays with minimal dimensionality. For instance, | ||
in the example below, current and time are both 1D numpy arrays. The code could have | ||
performed the same calculations using a single 2D array with a column for each variable, | ||
however this would have made the code less readable. | ||
|
||
.. code-block:: python | ||
from pyprobe.methods.basemethod import BaseMethod | ||
class CoulombCounter(BaseMethod): | ||
""""A method for calculating the charge passed."""" | ||
def __init__(self, input_data: Result): | ||
"""Initialise the coulomb counter method. | ||
Args: | ||
data: The input data to the method. | ||
""" | ||
# define input variables to the method | ||
self.current = self.variable("Current [A]") | ||
self.time = self.variable("Time [s]") | ||
# perform the calculations | ||
self.charge = self.coulomb_count(self.current, self.time) | ||
# assign the results, by calling the assign_outputs method on a dictionary | ||
# of the results of your method | ||
self.result = self.assign_outputs({"Charge [C]": self.charge}) | ||
def coulomb_count(self, current, time): | ||
"""Calculate the charge passed. | ||
Args: | ||
current: The current data. | ||
time: The time data. | ||
Returns: | ||
The charge passed. | ||
""" | ||
return np.trapz(current, time) | ||
The result of the method above can be accessed as a result object by calling: | ||
|
||
.. code-block:: python | ||
result = CoulombCounter(data).result | ||
Which can be passed to any other Method or used in the :class:`~pyprobe.plot.Plot` | ||
class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ Developer Guide | |
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
installation | ||
developer_installation | ||
creating_a_new_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Installation | ||
============ | ||
|
||
To install PyProBE you must be running Python 3.11 or later. It is recommended to use a | ||
virtual environment to install PyProBE, for example venv or conda. | ||
|
||
The steps to install PyProBE wih developer settings are as follows: | ||
|
||
1. Enter a directory in which you wish to install PyProBE: | ||
|
||
.. code-block:: bash | ||
cd /path/to/your/directory | ||
2. Clone the repository to your local machine. This can be done either from the | ||
main PyProBE repository or your own fork. This creates a directory called PyProBE. | ||
|
||
.. code-block:: bash | ||
git clone https://github.com/ImperialCollegeLondon/PyProBE.git | ||
cd PyProBE | ||
3. Create and activate a virtual environment. | ||
|
||
.. tabs:: | ||
.. tab:: venv | ||
|
||
In your working directory: | ||
|
||
.. code-block:: bash | ||
python -m venv venv | ||
source .venv/bin/activate | ||
.. tab:: conda | ||
|
||
In any directory: | ||
|
||
.. code-block:: bash | ||
conda create -n pyprobe python=3.12 | ||
conda activate pyprobe | ||
3. Install PyProBE as a package into your virtual environment: | ||
|
||
.. code-block:: bash | ||
cd /path/to/your/directory/PyProBE | ||
pip install -e . | ||
The :code:`-e` flag installs in "editable" mode, which means changes that you | ||
make to the code will be automatically reflected in the package inside your | ||
virtual environment. | ||
|
||
4. Install the developer dependencies: | ||
|
||
.. code-block:: bash | ||
pip install -r requirements-dev.txt | ||
5. Install the pre-commit hooks: | ||
|
||
.. code-block:: bash | ||
pre-commit install |