Skip to content

Commit

Permalink
should fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Nov 15, 2024
1 parent 92d706a commit b5c88e2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 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, Literal, overload, Final

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

NUMBER_OF_DIMENSIONS_IN_UNIVERSE: Final[int] = 3

Check failure on line 24 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (I001)

meteor/rsmap.py:3:1: I001 Import block is un-sorted or un-formatted

Check failure on line 24 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Ruff (I001)

meteor/rsmap.py:3:1: I001 Import block is un-sorted or un-formatted


class MissingUncertaintiesError(AttributeError): ...

Expand Down Expand Up @@ -106,6 +108,7 @@ def __init__(
if self.has_uncertainties:
self.uncertainties = self._verify_uncertainty_type(self.uncertainties, fix=True)


@property
def _constructor(self) -> Callable[[Any], Map]:
def constructor_fxn(*args: Any, **kwargs: Any) -> Map:
Expand Down Expand Up @@ -210,7 +213,20 @@ 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
if self.index.names == ["H", "K", "L"]:
hkls = self.index.to_frame().to_numpy(dtype=np.int32)
else:
# 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 ["H", "K", "L"] ]).T

Check failure on line 224 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (W293)

meteor/rsmap.py:224:1: W293 Blank line contains whitespace

Check failure on line 224 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Ruff (W293)

meteor/rsmap.py:224:1: W293 Blank line contains whitespace
if not hkls.shape[-1] == NUMBER_OF_DIMENSIONS_IN_UNIVERSE:

Check failure on line 225 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (SIM201)

meteor/rsmap.py:225:12: SIM201 Use `hkls.shape[-1] != NUMBER_OF_DIMENSIONS_IN_UNIVERSE` instead of `not hkls.shape[-1] == NUMBER_OF_DIMENSIONS_IN_UNIVERSE`

Check failure on line 225 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Ruff (SIM201)

meteor/rsmap.py:225:12: SIM201 Use `hkls.shape[-1] != NUMBER_OF_DIMENSIONS_IN_UNIVERSE` instead of `not hkls.shape[-1] == NUMBER_OF_DIMENSIONS_IN_UNIVERSE`
msg = f"something went wrong, HKL array has a funny shape: {hkls.shape}"
raise RuntimeError(msg)

Check failure on line 228 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (W293)

meteor/rsmap.py:228:1: W293 Blank line contains whitespace

Check failure on line 228 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Ruff (W293)

meteor/rsmap.py:228:1: W293 Blank line contains whitespace
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 +452,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 All @@ -450,7 +465,7 @@ def from_3d_numpy_map(
high_resolution_limit=high_resolution_limit,
)

def to_ccp4_map(self, *, map_sampling: int) -> gemmi.Ccp4Map:
def to_ccp4_map(self, *, map_sampling: int) -> gemmi.Ccp4Map:

Check failure on line 468 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (W291)

meteor/rsmap.py:468:66: W291 Trailing whitespace

Check failure on line 468 in meteor/rsmap.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Ruff (W291)

meteor/rsmap.py:468:66: W291 Trailing whitespace
map_coefficients_gemmi_format = self.to_gemmi()
ccp4_map = gemmi.Ccp4Map()
ccp4_map.grid = map_coefficients_gemmi_format.transform_f_phi_to_map(
Expand Down

0 comments on commit b5c88e2

Please sign in to comment.