-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Aggregate and Table Operations
- Loading branch information
Showing
12 changed files
with
1,035 additions
and
291 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,27 @@ | ||
Aggregate Operations | ||
======================= | ||
|
||
The following operations are available for iterable collections of measurements: | ||
|
||
* ``sum``: Sum a collection of measurements. | ||
* ``min``: Find the minimum of a collection of measurements. | ||
* ``max``: Find the maximum of a collection of measurements. | ||
* ``average``: Find the average of a collection of measurements (Uncertainty = :math:`\Delta x = \frac{x_{max}-x_{min}}{2\sqrt{n}}`). | ||
|
||
All of these operations return a new measurement object. | ||
|
||
.. testsetup:: * | ||
|
||
from pymeasurement import Measurement as M | ||
|
||
.. doctest:: python | ||
|
||
>>> collection = [M.fromStr('20.23d g'), M.fromStr('13.86d g'), M.fromStr('46.37d g')] | ||
>>> M.sum(collection) | ||
80.46 +/- 0.03 g | ||
>>> M.min(collection) | ||
13.86 +/- 0.01 g | ||
>>> M.max(collection) | ||
46.37 +/- 0.01 g | ||
>>> M.average(collection) | ||
26.82 +/- 9.38 g |
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Table Operations | ||
================ | ||
|
||
pymeasurement can be used with Pandas DataFrames to perform precision-based uncertainty calculations on tables of data. | ||
|
||
**Original Data Table** | ||
|
||
.. exceltable:: | ||
:file: _static\example.xls | ||
:header: 1 | ||
:selection: A1:C7 | ||
|
||
In order to acheive this, the DataFrame is converted into Measurement objects for calculations using the below. | ||
|
||
All data can be normalized in this step as well. | ||
|
||
.. doctest:: python | ||
|
||
>>> import pandas as pd | ||
>>> df = pd.read_excel('_static\example.xlsx') | ||
>>> from pymeasurement import Measurement as M | ||
>>> converted = pd.DataFrame() | ||
>>> converted['Mass (± 0.001 kg)'] = M.importColumn(df['Mass (± 0.001 kg)'], d=True, un='kg', decimals=3) | ||
>>> converted['Average Acceleration (m/s^2)'] = M.importColumn(df['Average Acceleration (m/s^2)'], uncertaintyColumn=df['Average Acceleration Percent Uncertainty (%)'], df=df, up=True, un='m/s^2', decimals=2) | ||
|
||
**Converted Data Table** | ||
|
||
.. exceltable:: | ||
:file: _static\example.xls | ||
:header: 1 | ||
:selection: F1:G7 | ||
|
||
Now calculations can easily be performed on the DataFrame using the Measurement objects. | ||
|
||
.. doctest:: python | ||
|
||
>>> converted['Force (N)'] = converted['Mass (± 0.001 kg)'] * converted['Average Acceleration (m/s^2)'] | ||
|
||
**Calculated Data Table** | ||
|
||
.. exceltable:: | ||
:file: _static\example.xls | ||
:header: 1 | ||
:selection: J1:L7 | ||
|
||
Once the calculations are complete, the DataFrame can be converted back into a numeric types using the below. | ||
|
||
.. doctest:: python | ||
|
||
>>> final_table = converted.copy() | ||
>>> M.exportColumn(final_table, converted['Mass (± 0.001 kg)'], addUncertainty=False) | ||
>>> M.exportColumn(final_table, converted['Average Acceleration (m/s^2)']) | ||
>>> M.exportColumn(final_table, converted['Force (N)'], asPercent=False) | ||
|
||
.. exceltable:: | ||
:file: _static\example.xls | ||
:header: 1 | ||
:selection: O1:S7 |
Oops, something went wrong.