Skip to content

Commit

Permalink
Merge branch 'daredevil' of github.com:arafune/arpes into daredevil
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Jan 18, 2024
2 parents 501b9d9 + 9cf5ee3 commit e64082f
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 87 deletions.
12 changes: 6 additions & 6 deletions arpes/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import xarray as xr
from tqdm.notebook import tqdm

from arpes.analysis.sarpes import to_intensity_polarization
from arpes.provenance import update_provenance
from arpes.utilities import lift_dataarray_to_generic
from arpes.utilities.normalize import normalize_to_spectrum
from arpes.utilities.region import normalize_region
from .analysis.sarpes import to_intensity_polarization
from .provenance import update_provenance
from .utilities import lift_dataarray_to_generic
from .utilities.normalize import normalize_to_spectrum
from .utilities.region import normalize_region

if TYPE_CHECKING:
from collections.abc import Callable
Expand All @@ -38,7 +38,7 @@
from _typeshed import Incomplete
from numpy.typing import NDArray

from arpes._typing import DataType
from ._typing import DataType
__all__ = (
"bootstrap",
"estimate_prior_adjustment",
Expand Down
62 changes: 44 additions & 18 deletions arpes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pint

if TYPE_CHECKING:
from arpes._typing import CONFIGTYPE, WORKSPACETYPE, ConfigSettings
from ._typing import CONFIGTYPE, WORKSPACETYPE, ConfigSettings

# pylint: disable=global-statement

Expand Down Expand Up @@ -64,9 +64,20 @@
FIGURE_PATH: str | Path | None = None
DATASET_PATH: str | Path | None = None

CONFIG: CONFIGTYPE = {
"WORKSPACE": {},
"CURRENT_CONTEXT": None,
"ENABLE_LOGGING": True,
"LOGGING_STARTED": False,
"LOGGING_FILE": None,
}


def warn(msg: str) -> None:
"""Conditionally render a warning using `warnings.warn`."""
"""Conditionally render a warning using `warnings.warn`.
ToDo: TEST
"""
if DOCS_BUILD:
return
warnings.warn(msg, stacklevel=2)
Expand Down Expand Up @@ -96,15 +107,6 @@ def update_configuration(user_path: Path | str = "") -> None:
pass


CONFIG: CONFIGTYPE = {
"WORKSPACE": {},
"CURRENT_CONTEXT": None,
"ENABLE_LOGGING": True,
"LOGGING_STARTED": False,
"LOGGING_FILE": None,
}


class WorkspaceManager:
"""A context manager for swapping workspaces temporarily.
Expand All @@ -123,6 +125,8 @@ def __init__(self, workspace: str | None = None) -> None:
Args:
workspace: The name of the workspace to enter temporarily. Defaults to None.
ToDo: TEST
"""
self._cached_workspace: WORKSPACETYPE = {}
self._workspace: str | None = workspace
Expand All @@ -132,6 +136,8 @@ def __enter__(self) -> None:
Raises:
ValueError: If a workspace cannot be identified with the requested name.
ToDo: Test
"""
self._cached_workspace = CONFIG["WORKSPACE"]
if not self._workspace:
Expand All @@ -148,7 +154,10 @@ def __enter__(self) -> None:
raise ValueError(msg)

def __exit__(self, *args: object) -> None:
"""Clean up by resetting the PyARPES workspace."""
"""Clean up by resetting the PyARPES workspace.
ToDo: Test
"""
CONFIG["WORKSPACE"] = self._cached_workspace


Expand All @@ -165,6 +174,8 @@ def workspace_matches(path: str | Path) -> bool:
Returns:
True if the path is a workspace and False otherwise.
ToDo: TEST
"""
contents = os.listdir(path)
return any(sentinel in contents for sentinel in ["data", "Data"])
Expand All @@ -181,6 +192,8 @@ def attempt_determine_workspace(current_path: str | Path = "") -> None:
Args:
current_path: Override for "Path.cwd()". Defaults to None.
ToDo: TEST
"""
pdataset = Path.cwd() if DATASET_PATH is None else DATASET_PATH

Expand Down Expand Up @@ -208,6 +221,8 @@ def load_json_configuration(filename: str) -> None:
Args:
filename: A filename or path containing the settings.
ToDo: TEST
"""
with Path(filename).open() as config_file:
CONFIG.update(json.load(config_file))
Expand All @@ -223,8 +238,11 @@ def load_json_configuration(filename: str) -> None:


def override_settings(new_settings: ConfigSettings) -> None:
"""Deep updates/overrides PyARPES settings."""
from arpes.utilities.collections import deep_update
"""Deep updates/overrides PyARPES settings.
ToDo: TEST
"""
from .utilities.collections import deep_update

deep_update(SETTINGS, new_settings)

Expand All @@ -240,7 +258,7 @@ def load_plugins() -> None:
"""
import importlib

from arpes.endstations import add_endstation, plugin
from .endstations import add_endstation, plugin

skip_modules = {"__pycache__", "__init__"}
plugins_dir = Path(plugin.__file__).parent
Expand All @@ -266,6 +284,8 @@ def is_using_tex() -> bool:
Returns:
True if matplotlib will use LaTeX for plotting and False otherwise.
ToDo: TEST
"""
return mpl.rcParams["text.usetex"]

Expand All @@ -286,14 +306,20 @@ class UseTex:
saved_context: dict[str, Any] = field(default_factory=dict)

def __enter__(self) -> None:
"""Save old settings so we can restore them later."""
"""Save old settings so we can restore them later.
ToDo: TEST
"""
self.saved_context["text.usetex"] = mpl.rcParams["text.usetex"]
self.saved_context["SETTINGS.use_tex"] = SETTINGS.get("use_tex", False)
# temporarily set the TeX configuration to the requested one
use_tex(rc_text_should_use=self.use_tex)

def __exit__(self, *args: object) -> None:
"""Reset configuration back to the cached settings."""
"""Reset configuration back to the cached settings.
ToDo: TEST
"""
SETTINGS["use_tex"] = self.saved_context["use_tex"]
mpl.rcParams["text.usetex"] = self.saved_context["text.usetex"]

Expand Down Expand Up @@ -342,7 +368,7 @@ def setup_logging() -> None:
try:
if CONFIG["ENABLE_LOGGING"] and not CONFIG["LOGGING_STARTED"]:
CONFIG["LOGGING_STARTED"] = True
from arpes.utilities.jupyter import generate_logfile_path
from .utilities.jupyter import generate_logfile_path

log_path = generate_logfile_path()
log_path.parent.mkdir(exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion arpes/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from numpy import pi

if TYPE_CHECKING:
from arpes._typing import SPECTROMETER
from ._typing import SPECTROMETER

# eV, A reasonablish value if you aren't sure for the particular sample
WORK_FUNCTION = 4.3
Expand Down
9 changes: 5 additions & 4 deletions arpes/endstations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

import arpes.config
import arpes.constants
from arpes.endstations.fits_utils import find_clean_coords
from arpes.endstations.igor_utils import shim_wave_note
from arpes.load_pxt import find_ses_files_associated, read_single_pxt
from arpes.provenance import provenance_from_file
from arpes.repair import negate_energy
from arpes.trace import Trace, traceable
from arpes.utilities.dict import case_insensitive_get, rename_dataarray_attrs

if TYPE_CHECKING:
from collections.abc import Callable
from .fits_utils import find_clean_coords
from .igor_utils import shim_wave_note

if TYPE_CHECKING:
from _typeshed import Incomplete

from arpes._typing import SPECTROMETER
Expand Down Expand Up @@ -572,6 +571,8 @@ def load_single_frame(
return xr.Dataset({"spectrum": pxt_data}, attrs=pxt_data.attrs)

def postprocess(self, frame: xr.Dataset) -> Self:
import arpes.xarray_extensions # pylint: disable=unused-import, redefined-outer-name

frame = super().postprocess(frame)
return frame.assign_attrs(frame.S.spectrum.attrs)

Expand Down
1 change: 1 addition & 0 deletions arpes/endstations/plugin/ALG_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np

import arpes.xarray_extensions # pylint: disable=unused-import, redefined-outer-name # noqa: F401
from arpes.endstations import SCANDESC, FITSEndstation, HemisphericalEndstation

if TYPE_CHECKING:
Expand Down
6 changes: 3 additions & 3 deletions arpes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import pandas as pd
import xarray as xr

from arpes.endstations import load_scan
from .endstations import load_scan

if TYPE_CHECKING:
from _typeshed import Incomplete
Expand Down Expand Up @@ -210,7 +210,7 @@ def stitch(
concatenated = xr.concat(loaded, dim=built_axis_name)
if "id" in concatenated.attrs:
del concatenated.attrs["id"]
from arpes.provenance import provenance_multiple_parents
from .provenance import provenance_multiple_parents

provenance_multiple_parents(
concatenated,
Expand Down Expand Up @@ -246,7 +246,7 @@ def _df_or_list_to_files(

def file_for_pickle(name: str) -> Path | str:
here = Path()
from arpes.config import CONFIG
from .config import CONFIG

if CONFIG["WORKSPACE"]:
here = Path(CONFIG["WORKSPACE"]["path"])
Expand Down
2 changes: 1 addition & 1 deletion arpes/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import TYPE_CHECKING

from arpes.config import ureg
from .config import ureg

if TYPE_CHECKING:
import pint
Expand Down
9 changes: 5 additions & 4 deletions arpes/load_pxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import numpy as np
import xarray as xr

from arpes.utilities.string import safe_decode
from .utilities.string import safe_decode

if TYPE_CHECKING:
from _typeshed import Incomplete

from arpes._typing import DataType
from ._typing import DataType
Wave = Any # really, igor.Wave but we do not assume installation

__all__ = (
Expand Down Expand Up @@ -103,7 +103,8 @@ def read_igor_binary_wave(raw_bytes: bytes) -> xr.DataArray:

wave_data = np.fromstring(
raw_bytes[
igor_wave_header_dtype.itemsize + offset : igor_wave_header_dtype.itemsize
igor_wave_header_dtype.itemsize
+ offset : igor_wave_header_dtype.itemsize
+ n_points * point_size
+ offset
],
Expand Down Expand Up @@ -164,7 +165,7 @@ def read_header(header_bytes: bytes) -> dict[str, Any]:

header[first.lower().replace(" ", "_")] = rest

from arpes.utilities import rename_keys
from .utilities import rename_keys

return rename_keys(
header,
Expand Down
2 changes: 1 addition & 1 deletion arpes/plotting/comparison_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import scipy.ndimage.interpolation
import xarray as xr

from arpes.plotting.interactive_utils import BokehInteractiveTool
from .interactive_utils import BokehInteractiveTool
from arpes.utilities.funcutils import Debounce
from arpes.utilities.normalize import normalize_to_spectrum

Expand Down
2 changes: 1 addition & 1 deletion arpes/plotting/curvature_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from arpes.analysis.derivative import curvature, d1_along_axis, d2_along_axis
from arpes.analysis.filters import boxcar_filter, gaussian_filter
from arpes.plotting.interactive_utils import BokehInteractiveTool
from .interactive_utils import BokehInteractiveTool
from arpes.utilities.funcutils import Debounce

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion arpes/plotting/dyn_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np

from arpes.exceptions import AnalysisError
from arpes.plotting.interactive_utils import BokehInteractiveTool, CursorTool
from .interactive_utils import BokehInteractiveTool, CursorTool
from arpes.utilities import Debounce, normalize_to_spectrum

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion arpes/plotting/fit_inspection_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import xarray as xr
from bokeh import events

from arpes.plotting.interactive_utils import BokehInteractiveTool, CursorTool
from .interactive_utils import BokehInteractiveTool, CursorTool

if TYPE_CHECKING:
from _typeshed import Incomplete
Expand Down
2 changes: 1 addition & 1 deletion arpes/plotting/mask_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from arpes.analysis.mask import apply_mask
from arpes.exceptions import AnalysisError
from arpes.plotting.interactive_utils import CursorTool, SaveableTool
from .interactive_utils import CursorTool, SaveableTool
from arpes.utilities import normalize_to_spectrum

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion arpes/plotting/path_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from arpes.analysis.path import select_along_path
from arpes.exceptions import AnalysisError
from arpes.plotting.interactive_utils import CursorTool, SaveableTool
from .interactive_utils import CursorTool, SaveableTool
from arpes.utilities import normalize_to_spectrum

if TYPE_CHECKING:
Expand Down
Loading

0 comments on commit e64082f

Please sign in to comment.