Skip to content

Commit

Permalink
Ruff formatting for most files. Black for notebooks
Browse files Browse the repository at this point in the history
Matplotlib inline is not needed enymore with recent versions of jupyter and was conflicting with black formatter
  • Loading branch information
bdestombe committed Nov 4, 2023
1 parent d7d6036 commit 07adb9c
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 76 deletions.
2 changes: 1 addition & 1 deletion docs/notebooks/03Define_sections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"outputs": [],
"source": [
"# The following command adds the .dts accessor to the xarray Dataset.\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"\n",
"print(ds.dts.get_timeseries_keys()) # list the available timeseeries\n",
"ds.probe1Temperature.plot(figsize=(12, 8))"
Expand Down
6 changes: 2 additions & 4 deletions docs/notebooks/04Calculate_variance_Stokes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
"warnings.simplefilter(\"ignore\") # Hide warnings to avoid clutter in the notebook\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"from matplotlib import pyplot as plt\n",
"\n",
"%matplotlib inline"
"from matplotlib import pyplot as plt"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions docs/notebooks/07Calibrate_single_ended.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
"import os\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down
5 changes: 2 additions & 3 deletions docs/notebooks/08Calibrate_double_ended.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
" suggest_cable_shift_double_ended,\n",
" shift_double_ended,\n",
")\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"warnings.simplefilter(\"ignore\") # Hide warnings to avoid clutter in the notebook\n",
"%matplotlib inline"
"warnings.simplefilter(\"ignore\") # Hide warnings to avoid clutter in the notebook"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/12Datastore_from_numpy_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"import xarray as xr\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant"
]
},
Expand Down
4 changes: 1 addition & 3 deletions docs/notebooks/13Fixed_parameter_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
"import os\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"\n",
"filepath = os.path.join(\"..\", \"..\", \"tests\", \"data\", \"single_ended\")\n",
"\n",
"ds = read_silixa_files(directory=filepath, timezone_netcdf=\"UTC\", file_ext=\"*.xml\")\n",
Expand Down
6 changes: 2 additions & 4 deletions docs/notebooks/14Lossy_splices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@
"import os\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions docs/notebooks/15Matching_sections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
"import os\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions docs/notebooks/16Averaging_temperatures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
"import os\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"import os\n",
"\n",
"from dtscalibration import read_silixa_files\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration import DtsAccessor # noqa: E401\n",
"from dtscalibration.variance_stokes import variance_stokes_constant\n",
"import matplotlib.pyplot as plt\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ features = ["dev"]
[tool.hatch.envs.default.scripts]
lint = [
"ruff check src/ tests/ examples/",
"black --check src/ tests/ examples/",
"black --check docs/notebooks",
"isort --check-only --diff src/ tests/ examples/",
"mypy src/",
]
format = ["isort src/ tests/ examples/", "ruff check src/ tests/ examples/ --fix", "ruff format src/ tests/ examples/", "black src/ tests/ examples/", "lint",]
format = ["isort src/ tests/ examples/", "ruff check src/ tests/ examples/ --fix", "ruff format src/ tests/ examples/", "black docs/notebooks", "lint",]
test = ["pytest ./src/ ./tests/",]
fast-test = ["pytest ./tests/ -m \"not slow\"",]
coverage = [
Expand Down
40 changes: 14 additions & 26 deletions src/dtscalibration/calibrate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ def calibration_single_ended_solver( # noqa: MC0001

w = (
1
/ (
ds_sec.st**-2 * st_var_sec + ds_sec.ast**-2 * ast_var_sec
).values.ravel()
/ (ds_sec.st**-2 * st_var_sec + ds_sec.ast**-2 * ast_var_sec).values.ravel()
)

if np.any(matching_indices):
Expand Down Expand Up @@ -1232,15 +1230,10 @@ def calibrate_double_ended_solver( # noqa: MC0001
rst_var_sec = parse_st_var(ds.rst, rst_var).isel(x=ix_sec).values
rast_var_sec = parse_st_var(ds.rast, rast_var).isel(x=ix_sec).values

w_F = (
1
/ (ds_sec.st**-2 * st_var_sec + ds_sec.ast**-2 * ast_var_sec).values.ravel()
)
w_F = 1 / (ds_sec.st**-2 * st_var_sec + ds_sec.ast**-2 * ast_var_sec).values.ravel()
w_B = (
1
/ (
ds_sec.rst**-2 * rst_var_sec + ds_sec.rast**-2 * rast_var_sec
).values.ravel()
/ (ds_sec.rst**-2 * rst_var_sec + ds_sec.rast**-2 * rast_var_sec).values.ravel()
)

if not np.any(matching_indices):
Expand Down Expand Up @@ -1369,12 +1362,8 @@ def calibrate_double_ended_solver( # noqa: MC0001
rast_var_mnc = parse_st_var(ds.rast, rast_var).isel(x=ix_match_not_cal).values

w_eq1 = 1 / (
(
ds_hix.st**-2 * st_var_hix + ds_hix.ast**-2 * ast_var_hix
).values.ravel()
+ (
ds_tix.st**-2 * st_var_tix + ds_tix.ast**-2 * ast_var_tix
).values.ravel()
(ds_hix.st**-2 * st_var_hix + ds_hix.ast**-2 * ast_var_hix).values.ravel()
+ (ds_tix.st**-2 * st_var_tix + ds_tix.ast**-2 * ast_var_tix).values.ravel()
)
w_eq2 = 1 / (
(
Expand Down Expand Up @@ -2346,16 +2335,15 @@ def match_sections(ds, matching_sections):
hxs = ds.x.sel(x=hslice).size
txs = ds.x.sel(x=tslice).size

assert (
hxs == txs
), "the two sections do not have matching " "number of items: " + str(
hslice
) + "size: " + str(
hxs
) + str(
tslice
) + "size: " + str(
txs
assert hxs == txs, (
"the two sections do not have matching "
"number of items: "
+ str(hslice)
+ "size: "
+ str(hxs)
+ str(tslice)
+ "size: "
+ str(txs)
)

hix = ds.dts.ufunc_per_section(
Expand Down
14 changes: 6 additions & 8 deletions src/dtscalibration/datastore_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ def check_dims(
assert len(labels) > 1, "Define the correct dimensions"

for li in labels[1:]:
assert (
ds[labels[0]].dims == ds[li].dims
), li + " does not have the correct dimensions." " Should be " + str(
ds[labels[0]].dims
assert ds[labels[0]].dims == ds[li].dims, (
li + " does not have the correct dimensions."
" Should be " + str(ds[labels[0]].dims)
)
else:
for li in labels:
assert (
ds[li].dims == correct_dims
), li + " does not have the correct dimensions. " "Should be " + str(
correct_dims
assert ds[li].dims == correct_dims, (
li + " does not have the correct dimensions. "
"Should be " + str(correct_dims)
)


Expand Down
6 changes: 3 additions & 3 deletions src/dtscalibration/io/apsensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def read_apsensing_files(
filepathlist = sorted(Path(directory).glob(file_ext))

# Make sure that the list of files contains any files
assert (
len(filepathlist) >= 1
), "No measurement files found in provided " "directory: \n" + str(directory)
assert len(filepathlist) >= 1, (
"No measurement files found in provided " "directory: \n" + str(directory)
)

# Make sure that the list of files contains any files
assert len(filepathlist) >= 1, (
Expand Down
7 changes: 4 additions & 3 deletions src/dtscalibration/io/sensortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def read_sensortran_files(
filepathlist_dts = sorted(Path(directory).glob("*BinaryRawDTS.dat"))

# Make sure that the list of files contains any files
assert (
len(filepathlist_dts) >= 1
), "No RawDTS measurement files found " "in provided directory: \n" + str(directory)
assert len(filepathlist_dts) >= 1, (
"No RawDTS measurement files found "
"in provided directory: \n" + str(directory)
)

filepathlist_temp = [
Path(str(f).replace("RawDTS", "Temp")) for f in filepathlist_dts
Expand Down
6 changes: 3 additions & 3 deletions src/dtscalibration/io/silixa.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def read_silixa_files(
filepathlist = sorted(Path(directory).glob(file_ext))

# Make sure that the list of files contains any files
assert (
len(filepathlist) >= 1
), "No measurement files found in provided " "directory: \n" + str(directory)
assert len(filepathlist) >= 1, (
"No measurement files found in provided " "directory: \n" + str(directory)
)

elif filepathlist is None and zip_handle:
filepathlist = ziphandle_to_filepathlist(fh=zip_handle, extension=file_ext)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,6 @@ def test_merge_double_ended_times(inotinfw, inotinbw, inotinout):
plot_result=False,
verbose=False,
)
assert ds.time.size == len(iout) and np.all(
ds.st.isel(x=0) == iout
assert (
ds.time.size == len(iout) and np.all(ds.st.isel(x=0) == iout)
), f"FW:{ifw} & BW:{ibw} should lead to {iout} but instead leads to {ds.st.isel(x=0).values}"

0 comments on commit 07adb9c

Please sign in to comment.