Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds script to import cctbx data to rs #264

Merged
merged 39 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a2a2343
adds script to import cctbx data to rs
dermen Aug 10, 2024
36b5873
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 10, 2024
592007b
removes cctbx dependency
dermen Aug 11, 2024
8db20f9
merged precommit
dermen Aug 11, 2024
cd94855
merged precommit 2
dermen Aug 11, 2024
1233625
rejig to io
dermen Aug 20, 2024
fa209fe
adds mpi support
dermen Aug 20, 2024
f19bae4
addresses review
dermen Aug 25, 2024
0106d9d
removes comment
dermen Aug 25, 2024
45b8ddd
addresses review pt2
dermen Aug 26, 2024
c52719f
uses better names
dermen Aug 26, 2024
d1c4424
cleans up io __init__
dermen Aug 27, 2024
c2d84fd
adds support for more columns
dermen Aug 27, 2024
b2afcb5
adds verbose flag for read_dials_stills
dermen Aug 28, 2024
f315274
more debug statements
dermen Aug 28, 2024
45707ca
Merge remote-tracking branch 'upstream/main'
dermen Sep 3, 2024
5f850e5
unit tests for refl table reader
dermen Sep 3, 2024
b28bd46
adds back in the comma
dermen Sep 3, 2024
c71dd06
cleanup
dermen Sep 3, 2024
d30d18f
more cleanup
dermen Sep 4, 2024
a1e07bb
use tempfile, remove __main__ for production
Sep 10, 2024
37ce079
refactor, add mpi test with dummy comms
Sep 12, 2024
36c3376
Merge pull request #1 from kmdalton/stills
dermen Sep 17, 2024
53f6021
get ray_context
dermen Sep 17, 2024
493630c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
cb7570b
Update common.py
dermen Sep 17, 2024
479104d
Update common.py
dermen Sep 17, 2024
7f7dd26
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
7fd1208
allow nan inference for float64
Sep 18, 2024
a365d34
remove dtype inference from read_dials_stills
Sep 18, 2024
cc1117b
make cell/sg optional. improve docstring
Sep 18, 2024
73e1ed4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2024
8e32b56
fix docstring
Sep 19, 2024
af61760
make dtype inference optional
Sep 19, 2024
bce6f80
test dtype inference toggle
Sep 19, 2024
58b862d
test mtz_dtypes flag and mtz writing
Sep 19, 2024
1fc6f7a
no need for a list of files
Sep 19, 2024
6c248e4
separate test for mtz io
Sep 19, 2024
1d0b88d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reciprocalspaceship/dtypes/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ def round(self: T, decimals: int = 0, *args, **kwargs) -> T:

@wraps(libmissing.is_numeric_na)
def is_numeric_na(values):
allowed_dtypes = ("float32", "int32")
allowed_dtypes = ("float64", "float32", "int32")
if isinstance(values, np.ndarray) and values.dtype in allowed_dtypes:
return np.isnan(values)
return libmissing.is_numeric_na(values)
1 change: 1 addition & 0 deletions reciprocalspaceship/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from reciprocalspaceship.io.ccp4map import write_ccp4_map
from reciprocalspaceship.io.crystfel import read_crystfel
from reciprocalspaceship.io.csv import read_csv
from reciprocalspaceship.io.dials import print_refl_info, read_dials_stills
from reciprocalspaceship.io.mtz import (
from_gemmi,
read_cif,
Expand Down
48 changes: 48 additions & 0 deletions reciprocalspaceship/io/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import logging
import warnings
from contextlib import contextmanager
from importlib.util import find_spec


def set_ray_loglevel(level):
logger = logging.getLogger("ray")
logger.setLevel(level)
for handler in logger.handlers:
handler.setLevel(level)


def check_for_ray():
has_ray = True
if find_spec("ray") is None:
has_ray = False

message = (
"ray (https://www.ray.io/) is not available..." "Falling back to serial."
)
warnings.warn(message, ImportWarning)
return has_ray


def check_for_mpi():
try:
from mpi4py import MPI

return True
except Exception as err:
message = (
f"Failed `from mpi4py import MPI` with {err}. Falling back to serial mode."
)
warnings.warn(message, ImportWarning)
return False


@contextmanager
def ray_context(log_level="DEBUG", **ray_kwargs):
import ray

set_ray_loglevel(log_level)
ray.init(**ray_kwargs)
try:
yield ray
finally:
ray.shutdown()
24 changes: 2 additions & 22 deletions reciprocalspaceship/io/crystfel.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import mmap
import re
from contextlib import contextmanager
from importlib.util import find_spec
from typing import Union

import gemmi
import numpy as np

from reciprocalspaceship import DataSet, concat
from reciprocalspaceship.io.common import check_for_ray, ray_context
from reciprocalspaceship.utils import angle_between, eV2Angstroms

# See Rupp Table 5-2
Expand Down Expand Up @@ -60,17 +59,6 @@
}


@contextmanager
def ray_context(**ray_kwargs):
import ray

ray.init(**ray_kwargs)
try:
yield ray
finally:
ray.shutdown()


class StreamLoader(object):
"""
An object that loads stream files into rs.DataSet objects in parallel.
Expand Down Expand Up @@ -304,15 +292,7 @@ def read_crystfel(

# Check whether ray is available
if use_ray:
if find_spec("ray") is None:
use_ray = False
import warnings

message = (
"ray (https://www.ray.io/) is not available..."
"Falling back to serial stream file parser."
)
warnings.warn(message, ImportWarning)
use_ray = check_for_ray()

with open(self.filename, "r") as f:
memfile = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
Expand Down
Loading