Skip to content

Commit

Permalink
Merge branch 'main' into tjlane/big-tv-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Nov 16, 2024
2 parents 834cce6 + 624fd28 commit 457aa0d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: ${{ vars.BUILD_PYTHON_VERSION }}

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: ${{ vars.BUILD_PYTHON_VERSION }}

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ${{ fromJSON(vars.PYTHON_VERSIONS) }}

steps:
- name: Cancel Previous Runs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ${{ fromJSON(vars.PYTHON_VERSIONS) }}

steps:
- name: Cancel Previous Runs
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version:
- '3.11'
python-version: ${{ fromJSON(vars.PYTHON_VERSIONS) }}
platform:
- ubuntu-latest
- macos-latest
Expand Down
26 changes: 22 additions & 4 deletions meteor/rsmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from collections.abc import Callable
from pathlib import Path
from typing import Any, ClassVar, Literal, overload
from typing import Any, ClassVar, Final, Literal, overload

import gemmi
import numpy as np
Expand All @@ -21,6 +21,8 @@
numpy_array_to_map,
)

NUMBER_OF_DIMENSIONS_IN_UNIVERSE: Final[int] = 3


class MissingUncertaintiesError(AttributeError): ...

Expand Down Expand Up @@ -210,7 +212,24 @@ def drop(self, labels: Any, *, inplace: bool = False) -> None | Map:

def get_hkls(self) -> np.ndarray:
# overwrite rs implt'n, return w/o modifying self -> same behavior, under testing - @tjlane
return self.index.to_frame().to_numpy(dtype=np.int32)
# this is a rather horrible thing to do and we should fix it
# best is to push changes upstream
hkl_names = ["H", "K", "L"]
if self.index.names == hkl_names:
hkls = self.index.to_frame().to_numpy(dtype=np.int32)
elif all(col in self.columns for col in hkl_names):
# we need to pull out each column as a separate DataSeries so that we don't try to
# create a new Map object without F, PHI
hkls = np.vstack([self[col].to_numpy(dtype=np.int32) for col in hkl_names]).T
else:
msg = f"cannot find `H`, `K`, and `L` columns in index or columns {self.columns}"
raise ValueError(msg)

if hkls.shape[-1] != NUMBER_OF_DIMENSIONS_IN_UNIVERSE:
msg = f"something went wrong, HKL array has a funny shape: {hkls.shape}"
raise RuntimeError(msg)

return hkls

def compute_dHKL(self) -> rs.DataSeries: # noqa: N802, caps from reciprocalspaceship
# rs adds a "dHKL" column to the DataFrame
Expand Down Expand Up @@ -436,8 +455,7 @@ def from_3d_numpy_map(
--------
For information about Gemmi data layout: https://gemmi.readthedocs.io/en/latest/grid.html
"""
number_of_dimensions_in_universe = 3
if len(map_grid.shape) != number_of_dimensions_in_universe:
if len(map_grid.shape) != NUMBER_OF_DIMENSIONS_IN_UNIVERSE:
msg = "`map_grid` should be a 3D array representing a realspace map"
raise ValueError(msg)
ccp4 = numpy_array_to_map(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"scikit-image >= 0.24.0",
"reciprocalspaceship >= 1.0.2",
"structlog >= 24.4.0",
"setuptools >= 75.5.0",
]

[project.optional-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def test_iterative_tv_denoiser(
noisy_error = diffmap_realspace_rms(very_noisy_map, noise_free_map)
denoised_error = diffmap_realspace_rms(denoised_map, noise_free_map)

# insist on 1% or better improvement
assert 1.01 * denoised_error < noisy_error
# insist on improvement
assert denoised_error < noisy_error

# insist that the negentropy and phase change decrease (or stay approx same) at every iteration
negentropy_change = metadata["negentropy_after_tv"].diff().to_numpy()
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_tv_denoise_zero_weight(random_difference_map: Map) -> None:
)
random_difference_map.canonicalize_amplitudes()
output.canonicalize_amplitudes()
pd.testing.assert_frame_equal(random_difference_map, output, atol=1e-2, rtol=1e-2)
pd.testing.assert_frame_equal(random_difference_map, output, atol=0.1, rtol=0.1)


def test_tv_denoise_nan_input(random_difference_map: Map) -> None:
Expand Down

0 comments on commit 457aa0d

Please sign in to comment.