Skip to content

Commit

Permalink
mainline dev yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Aug 11, 2024
1 parent d35bb1a commit 537eb2f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 661 deletions.
Empty file removed meteor/TV_filtering/__init__.py
Empty file.
403 changes: 0 additions & 403 deletions meteor/TV_filtering/iterative_tv.py

This file was deleted.

116 changes: 0 additions & 116 deletions meteor/TV_filtering/tv_denoise_map.py

This file was deleted.

52 changes: 0 additions & 52 deletions meteor/dsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,55 +96,3 @@ def map_from_Fs(dataset, Fs, phis, map_res):

return ccp4


def from_gemmi(gemmi_mtz):

"""
Construct DataSet from gemmi.Mtz object
If the gemmi.Mtz object contains an M/ISYM column and contains duplicated
Miller indices, an unmerged DataSet will be constructed. The Miller indices
will be mapped to their observed values, and a partiality flag will be
extracted and stored as a boolean column with the label, ``PARTIAL``.
Otherwise, a merged DataSet will be constructed.
If columns are found with the ``MTZInt`` dtype and are labeled ``PARTIAL``
or ``CENTRIC``, these will be interpreted as boolean flags used to
label partial or centric reflections, respectively.
Parameters
----------
gemmi_mtz : gemmi.Mtz
gemmi Mtz object
Returns
-------
rs.DataSet
"""

dataset = rs.DataSet(spacegroup=gemmi_mtz.spacegroup, cell=gemmi_mtz.cell)

# Build up DataSet
for c in gemmi_mtz.columns:
dataset[c.label] = c.array
# Special case for CENTRIC and PARTIAL flags
if c.type == "I" and c.label in ["CENTRIC", "PARTIAL"]:
dataset[c.label] = dataset[c.label].astype(bool)
else:
dataset[c.label] = dataset[c.label].astype(c.type)
dataset.set_index(["H", "K", "L"], inplace=True)

# Handle unmerged DataSet. Raise ValueError if M/ISYM column is not unique
m_isym = dataset.get_m_isym_keys()
if m_isym and dataset.index.duplicated().any():
if len(m_isym) == 1:
dataset.merged = False
dataset.hkl_to_observed(m_isym[0], inplace=True)
else:
raise ValueError(
"Only a single M/ISYM column is supported for unmerged data"
)
else:
dataset.merged = True

return dataset

Empty file removed meteor/mask.py
Empty file.
27 changes: 11 additions & 16 deletions meteor/validate.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import numpy as np
from scipy.stats import differential_entropy

from . import mask


def negentropy(X):
def negentropy(samples: np.ndarray, tolerance: float = 1e-4) -> float:
"""
Return negentropy (float) of X (numpy array)
"""

# negetropy is the difference between the entropy of samples x
# and a Gaussian with same variance
# http://gregorygundersen.com/blog/2020/09/01/gaussian-entropy/

std = np.std(X)
# neg_e = np.log(std*np.sqrt(2*np.pi*np.exp(1))) - differential_entropy(X)
neg_e = 0.5 * np.log(2.0 * np.pi * std**2) + 0.5 - differential_entropy(X)
# assert neg_e >= 0.0 + 1e-8

return neg_e

The negetropy is defined as the difference between the entropy of a distribution
and a Gaussian with same variance.
citation:
http://gregorygundersen.com/blog/2020/09/01/gaussian-entropy/
"""

std = np.std(samples.flatten())
neg_e = 0.5 * np.log(2.0 * np.pi * std**2) + 0.5 - differential_entropy(samples.flatten())
if not neg_e >= -tolerance:
raise ValueError(f"negentropy is a relatively big negative number {neg_e} that exceeds the tolerance {tolerance} -- something may have gone wrong")

return neg_e
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors = [
{ name = "Thomas Lane", email = "[email protected]" }
]
dependencies = [
"numpy",
"scipy",
"skimage",
"reciprocalspaceship",
]

Expand Down
48 changes: 0 additions & 48 deletions test/test_dsutils.py

This file was deleted.

26 changes: 0 additions & 26 deletions test/test_io.py

This file was deleted.

11 changes: 11 additions & 0 deletions test/unit/test_validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import numpy as np
from meteor import validate

def test_negentropy_gaussian() -> None:
n_samples = 100
samples = np.random.normal(size=n_samples)
negentropy = validate.negentropy(samples)

# negentropy should be small for a Gaussian sample
assert np.abs(negentropy) < 1e-5

0 comments on commit 537eb2f

Please sign in to comment.