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

Split up IO module #203

Merged
merged 24 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2e8a680
User-friendly error when setting manually ds.sections
bdestombe Aug 14, 2023
07270e3
User-friendly error when setting manually ds.sections
bdestombe Aug 14, 2023
66aa9f0
Revert accidental double implementation of sections.setter
bdestombe Aug 14, 2023
10dfbb4
Update documentation of datastore class
bdestombe Aug 17, 2023
77d9ede
Removed numbagg from dependencies
bdestombe Aug 18, 2023
c18f8ea
Explicitly pass sections to more functions
bdestombe Aug 18, 2023
bb1b477
Format
bdestombe Aug 18, 2023
b453f59
Moving away from calibrate_double_ended() inplace
bdestombe Aug 18, 2023
e884f94
Refactored calibrate_double_ended covariance calculation
bdestombe Aug 18, 2023
a4a1675
Parallel testing
bdestombe Aug 18, 2023
f363413
refactored variance functions
bdestombe Aug 18, 2023
7f795b9
Include pyupgrade flag of ruff
bdestombe Aug 18, 2023
7f3dcad
Refactored single ended routine p_val to params and moved averaging r…
bdestombe Aug 20, 2023
0c427d8
Update .gitignore
bdestombe Aug 21, 2023
43f42c8
Refactored calibration routines
bdestombe Aug 22, 2023
e0db37c
Please ruff
bdestombe Aug 22, 2023
49bbae3
Refactored Datastore class
bdestombe Sep 3, 2023
a515f8b
Updated sections example notebook
bdestombe Sep 3, 2023
39f71c9
Updated example notebooks
bdestombe Sep 3, 2023
a40c810
Add api to docs
bdestombe Sep 3, 2023
cfc4c1b
Unfortenate formatting of notebooks
bdestombe Sep 3, 2023
7dd73e6
Split and move IO routines.
BSchilperoort Oct 14, 2023
62a2c38
Filter out some common warnings.
BSchilperoort Oct 14, 2023
02d73d4
Merge branch 'main' into split-io
bdestombe Oct 16, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/python-publish-dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:
pip install build
- name: Build package
run: python -m build
- name: Test build
- name: Check long description for PyPi
run: twine check --strict dist/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ docs/_build
.appveyor.token
*.bak
.vscode/settings.json
*.code-workspace
7 changes: 7 additions & 0 deletions docs/api/dtscalibration.DataStore.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DataStore
=========

.. currentmodule:: dtscalibration

.. autoclass:: DataStore
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.check_dims.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
check_dims
==========

.. currentmodule:: dtscalibration

.. autofunction:: check_dims
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.check_timestep_allclose.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
check_timestep_allclose
=======================

.. currentmodule:: dtscalibration

.. autofunction:: check_timestep_allclose
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.get_netcdf_encoding.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
get_netcdf_encoding
===================

.. currentmodule:: dtscalibration

.. autofunction:: get_netcdf_encoding
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.merge_double_ended.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
merge_double_ended
==================

.. currentmodule:: dtscalibration

.. autofunction:: merge_double_ended
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.open_datastore.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open_datastore
==============

.. currentmodule:: dtscalibration

.. autofunction:: open_datastore
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.open_mf_datastore.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open_mf_datastore
=================

.. currentmodule:: dtscalibration

.. autofunction:: open_mf_datastore
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.plot_accuracy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plot_accuracy
=============

.. currentmodule:: dtscalibration

.. autofunction:: plot_accuracy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plot_location_residuals_double_ended
====================================

.. currentmodule:: dtscalibration

.. autofunction:: plot_location_residuals_double_ended
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.plot_residuals_reference_sections.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plot_residuals_reference_sections
=================================

.. currentmodule:: dtscalibration

.. autofunction:: plot_residuals_reference_sections
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plot_residuals_reference_sections_single
========================================

.. currentmodule:: dtscalibration

.. autofunction:: plot_residuals_reference_sections_single
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.plot_sigma_report.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plot_sigma_report
=================

.. currentmodule:: dtscalibration

.. autofunction:: plot_sigma_report
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.read_apsensing_files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
read_apsensing_files
====================

.. currentmodule:: dtscalibration

.. autofunction:: read_apsensing_files
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.read_sensornet_files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
read_sensornet_files
====================

.. currentmodule:: dtscalibration

.. autofunction:: read_sensornet_files
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.read_sensortran_files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
read_sensortran_files
=====================

.. currentmodule:: dtscalibration

.. autofunction:: read_sensortran_files
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.read_silixa_files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
read_silixa_files
=================

.. currentmodule:: dtscalibration

.. autofunction:: read_silixa_files
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.shift_double_ended.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
shift_double_ended
==================

.. currentmodule:: dtscalibration

.. autofunction:: shift_double_ended
6 changes: 6 additions & 0 deletions docs/api/dtscalibration.suggest_cable_shift_double_ended.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
suggest_cable_shift_double_ended
================================

.. currentmodule:: dtscalibration

.. autofunction:: suggest_cable_shift_double_ended
31 changes: 4 additions & 27 deletions docs/notebooks/03Define_sections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"outputs": [],
"source": [
"print(ds.timeseries_keys) # list the available timeseeries\n",
"ds.probe1Temperature.plot(figsize=(12, 8)); # plot one of the timeseries"
"ds.probe1Temperature.plot(figsize=(12, 8))\n",
"# plot one of the timeseries"
]
},
{
Expand Down Expand Up @@ -115,24 +116,7 @@
"sections = {\n",
" \"probe1Temperature\": [slice(7.5, 17.0), slice(70.0, 80.0)], # cold bath\n",
" \"probe2Temperature\": [slice(24.0, 34.0), slice(85.0, 95.0)], # warm bath\n",
"}\n",
"ds.sections = sections"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-06T08:09:10.309314Z",
"iopub.status.busy": "2022-04-06T08:09:10.308985Z",
"iopub.status.idle": "2022-04-06T08:09:10.323444Z",
"shell.execute_reply": "2022-04-06T08:09:10.322874Z"
}
},
"outputs": [],
"source": [
"ds.sections"
"}"
]
},
{
Expand All @@ -141,13 +125,6 @@
"source": [
"NetCDF files do not support reading/writing python dictionaries. Internally the sections dictionary is stored in `ds._sections` as a string encoded with yaml, which can be saved to a netCDF file. Each time the sections dictionary is requested, yaml decodes the string and evaluates it to the Python dictionary. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -166,7 +143,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.11"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down
7 changes: 3 additions & 4 deletions docs/notebooks/04Calculate_variance_Stokes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
"sections = {\n",
" \"probe1Temperature\": [slice(7.5, 17.0), slice(70.0, 80.0)], # cold bath\n",
" \"probe2Temperature\": [slice(24.0, 34.0), slice(85.0, 95.0)], # warm bath\n",
"}\n",
"ds.sections = sections"
"}"
]
},
{
Expand Down Expand Up @@ -120,7 +119,7 @@
},
"outputs": [],
"source": [
"I_var, residuals = ds.variance_stokes_constant(st_label=\"st\")\n",
"I_var, residuals = ds.variance_stokes_constant(sections=sections, st_label=\"st\")\n",
"print(\n",
" \"The variance of the Stokes signal along the reference sections \"\n",
" \"is approximately {:.2f} on a {:.1f} sec acquisition time\".format(\n",
Expand Down Expand Up @@ -187,7 +186,7 @@
"x = np.linspace(mean - 3 * sigma, mean + 3 * sigma, 100)\n",
"approximated_normal_fit = scipy.stats.norm.pdf(x, mean, sigma)\n",
"residuals.plot.hist(bins=50, figsize=(12, 8), density=True)\n",
"plt.plot(x, approximated_normal_fit);"
"plt.plot(x, approximated_normal_fit)"
]
},
{
Expand Down
16 changes: 8 additions & 8 deletions docs/notebooks/07Calibrate_single_ended.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"outputs": [],
"source": [
"ds = ds.sel(x=slice(-30, 101)) # dismiss parts of the fiber that are not interesting\n",
"ds.sections = {\n",
"sections = {\n",
" \"probe1Temperature\": [slice(20, 25.5)], # warm bath\n",
" \"probe2Temperature\": [slice(5.5, 15.5)], # cold bath\n",
"}"
Expand Down Expand Up @@ -119,8 +119,8 @@
},
"outputs": [],
"source": [
"st_var, resid = ds.variance_stokes_constant(st_label=\"st\")\n",
"ast_var, _ = ds.variance_stokes_constant(st_label=\"ast\")"
"st_var, resid = ds.variance_stokes_constant(sections=sections, st_label=\"st\")\n",
"ast_var, _ = ds.variance_stokes_constant(sections=sections, st_label=\"ast\")"
]
},
{
Expand All @@ -136,7 +136,7 @@
"metadata": {},
"outputs": [],
"source": [
"resid.plot(figsize=(12, 4));"
"resid.plot(figsize=(12, 4))"
]
},
{
Expand All @@ -160,7 +160,7 @@
},
"outputs": [],
"source": [
"ds.calibration_single_ended(st_var=st_var, ast_var=ast_var)"
"ds.calibration_single_ended(sections=sections, st_var=st_var, ast_var=ast_var)"
]
},
{
Expand All @@ -177,7 +177,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds.tmpf.plot(figsize=(12, 4));"
"ds.tmpf.plot(figsize=(12, 4))"
]
},
{
Expand All @@ -189,7 +189,7 @@
"ds1 = ds.isel(time=0)\n",
"ds1.tmpf.plot(figsize=(12, 4))\n",
"(ds1.tmpf_var**0.5).plot(figsize=(12, 4))\n",
"plt.ylabel(\"$\\sigma$ ($^\\circ$C)\");"
"plt.ylabel(\"$\\sigma$ ($^\\circ$C)\")"
]
},
{
Expand Down Expand Up @@ -217,7 +217,7 @@
"outputs": [],
"source": [
"ds1.st.plot(figsize=(12, 8))\n",
"ds1.ast.plot();"
"ds1.ast.plot()"
]
},
{
Expand Down
22 changes: 12 additions & 10 deletions docs/notebooks/08Calibrate_double_ended.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds.sections = {\n",
"sections = {\n",
" \"probe1Temperature\": [slice(7.5, 17.0), slice(70.0, 80.0)], # cold bath\n",
" \"probe2Temperature\": [slice(24.0, 34.0), slice(85.0, 95.0)], # warm bath\n",
"}"
Expand Down Expand Up @@ -186,10 +186,10 @@
},
"outputs": [],
"source": [
"st_var, resid = ds.variance_stokes_constant(st_label=\"st\")\n",
"ast_var, _ = ds.variance_stokes_constant(st_label=\"ast\")\n",
"rst_var, _ = ds.variance_stokes_constant(st_label=\"rst\")\n",
"rast_var, _ = ds.variance_stokes_constant(st_label=\"rast\")"
"st_var, resid = ds.variance_stokes_constant(sections=sections, st_label=\"st\")\n",
"ast_var, _ = ds.variance_stokes_constant(sections=sections, st_label=\"ast\")\n",
"rst_var, _ = ds.variance_stokes_constant(sections=sections, st_label=\"rst\")\n",
"rast_var, _ = ds.variance_stokes_constant(sections=sections, st_label=\"rast\")"
]
},
{
Expand All @@ -212,7 +212,7 @@
},
"outputs": [],
"source": [
"resid.plot(figsize=(12, 4));"
"resid.plot(figsize=(12, 4))"
]
},
{
Expand All @@ -237,6 +237,7 @@
"outputs": [],
"source": [
"ds.calibration_double_ended(\n",
" sections=sections,\n",
" st_var=st_var,\n",
" ast_var=ast_var,\n",
" rst_var=rst_var,\n",
Expand All @@ -257,7 +258,7 @@
},
"outputs": [],
"source": [
"ds.tmpw.plot(figsize=(12, 4));"
"ds.tmpw.plot(figsize=(12, 4))"
]
},
{
Expand Down Expand Up @@ -295,7 +296,7 @@
"ds.tmpw_var.plot(figsize=(12, 4))\n",
"ds1 = ds.isel(time=-1) # take only the first timestep\n",
"(ds1.tmpw_var**0.5).plot(figsize=(12, 4))\n",
"plt.gca().set_ylabel(\"Standard error ($^\\circ$C)\");"
"plt.gca().set_ylabel(\"Standard error ($^\\circ$C)\")"
]
},
{
Expand Down Expand Up @@ -323,6 +324,7 @@
"outputs": [],
"source": [
"ds.conf_int_double_ended(\n",
" sections=sections,\n",
" st_var=st_var,\n",
" ast_var=ast_var,\n",
" rst_var=rst_var,\n",
Expand All @@ -331,7 +333,7 @@
" mc_sample_size=500,\n",
") # < increase sample size for better approximation\n",
"\n",
"ds.tmpw_mc_var.plot(figsize=(12, 4));"
"ds.tmpw_mc_var.plot(figsize=(12, 4))"
]
},
{
Expand Down Expand Up @@ -380,7 +382,7 @@
"(ds1.tmpb_var**0.5).plot()\n",
"(ds1.tmpw_var**0.5).plot()\n",
"(ds1.tmpw_mc_var**0.5).plot()\n",
"plt.ylabel(\"$\\sigma$ ($^\\circ$C)\");"
"plt.ylabel(\"$\\sigma$ ($^\\circ$C)\")"
]
},
{
Expand Down
9 changes: 4 additions & 5 deletions docs/notebooks/12Datastore_from_numpy_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@
" \"temp1\": [slice(20, 25.5)], # warm bath\n",
" \"temp2\": [slice(5.5, 15.5)], # cold bath\n",
"}\n",
"ds.sections = sections\n",
"\n",
"st_var, resid = ds.variance_stokes_constant(st_label=\"st\")\n",
"ast_var, _ = ds.variance_stokes_constant(st_label=\"ast\")\n",
"ds.calibration_single_ended(st_var=st_var, ast_var=ast_var)\n",
"st_var, resid = ds.variance_stokes_constant(sections=sections, st_label=\"st\")\n",
"ast_var, _ = ds.variance_stokes_constant(sections=sections, st_label=\"ast\")\n",
"ds.calibration_single_ended(sections=sections, st_var=st_var, ast_var=ast_var)\n",
"\n",
"ds.isel(time=0).tmpf.plot();"
"ds.isel(time=0).tmpf.plot()"
]
},
{
Expand Down
Loading
Loading