Skip to content

Commit

Permalink
#214 Migrate from Poetry to PDM (5)
Browse files Browse the repository at this point in the history
Fix pytests
  • Loading branch information
dostuffthatmatters committed Jan 9, 2024
1 parent a704a18 commit 28d448d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-python-codebase-on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
- name: Run Pytests
run: |
source .venv/bin/activate
pdm run -v pytest -m "ci" --cov=packages tests
pytest -m "ci" --cov=packages tests
coverage report
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test-tmp/
hidden/
packages/docs/docs/api-reference/ui
cli.sh
.pdm-python

# runtime data
pids
Expand Down
4 changes: 3 additions & 1 deletion packages/core/threads/helios_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def take_image(
for _ in range(retries + 1):
ret, frame = self.camera.read()
if ret:
if trow_away_white_images and np.mean(frame) > 240:
if trow_away_white_images and np.mean(
frame # type: ignore
) > 240:
# image is mostly white
continue
return np.array(frame)
Expand Down
19 changes: 12 additions & 7 deletions packages/core/utils/helios_image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _get_binary_mask(frame: np.ndarray[Any, Any]) -> np.ndarray[Any, Any]:
_, kmeans_labels, kmeans_centers = cv.kmeans(
data=np.array(blurred_image.flatten(), dtype=np.float32),
K=2,
bestLabels=None,
bestLabels=None, # type: ignore
criteria=(
cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 10, 1.0
),
Expand Down Expand Up @@ -123,7 +123,7 @@ def _get_circle_location(

# get the circle that is closest to the image center
x, y, r = min(
np.round(circles[0, :]).astype("int"),
np.round(circles[0, :]).astype("int"), # type: ignore
key=lambda c: math.pow(c[0] -
(image_width * 0.5), 2) # type: ignore
+ pow(c[1] - (image_height * 0.5), 2),
Expand Down Expand Up @@ -226,17 +226,22 @@ def get_edge_fraction(
)

# blacken the outer 10% of the circle radius
edges_only_dilated *= HeliosImageProcessing._get_circle_mask(
edges_only_dilated.shape, round(circle_r * 0.9), circle_cx,
circle_cy
edges_only_dilated *= HeliosImageProcessing._get_circle_mask( # type: ignore
edges_only_dilated.shape, # type: ignore
round(circle_r * 0.9),
circle_cx,
circle_cy,
)

# determine how many pixels inside the circle are made up of "edge pixels"
pixels_inside_circle: int = np.sum(3.141592 * pow(circle_r * 0.9, 2))
edge_fraction: float = 0
if pixels_inside_circle != 0:
edge_fraction = round((np.sum(edges_only_dilated) / 255) /
pixels_inside_circle, 6)
edge_fraction = round(
(np.sum(edges_only_dilated) / 255) / # type: ignore
pixels_inside_circle,
6
)

if save_images_to_archive or save_current_image:
now = datetime.datetime.now()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ spaces_around_subscript_colon = true
[tool.mypy]
strict = true
implicit_reexport = true
warn_unused_ignores = false
plugins = ["pydantic.mypy"]

[[tool.mypy.overrides]]
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_astronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_astronomy(sample_config: types.Config) -> None:
sample_config, lat=48.137154, lon=11.576124, alt=515
)
assert isinstance(e2, float)
assert abs(e1 - e2) < 1e-3
assert abs(e1 - e2) < 1e-2

# generate a random datetime for every year between 2020 and 2050
# and test whether the elevation is correctly computed
Expand Down

0 comments on commit 28d448d

Please sign in to comment.