Skip to content

Commit

Permalink
🔥 fix wrong assert
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Oct 11, 2023
1 parent 618f38a commit e3e5ac5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2,017 deletions.
1,997 changes: 0 additions & 1,997 deletions arpes/all_imports

This file was deleted.

9 changes: 5 additions & 4 deletions arpes/fits/fit_models/x_model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import operator
import warnings
from logging import DEBUG, Formatter, StreamHandler, getLogger
from typing import TYPE_CHECKING
from logging import DEBUG, INFO, Formatter, StreamHandler, getLogger
from typing import TYPE_CHECKING, reveal_type

import lmfit as lf
import numpy as np
Expand All @@ -21,7 +21,7 @@
__all__ = ["XModelMixin", "gaussian_convolve"]


LOGLEVEL = DEBUG
LOGLEVEL = (DEBUG, INFO)[0]
logger = getLogger(__name__)
fmt = "%(asctime)s %(levelname)s %(name)s :%(message)s"
formatter = Formatter(fmt)
Expand Down Expand Up @@ -112,7 +112,8 @@ def guess_fit(
"""
if params is not None and not isinstance(params, lf.Parameters):
params = dict_to_parameters(params)
assert isinstance(params, lf.Parameters)
param_type_ = f"params type : {reveal_type(params)}"
logger.debug(param_type_)
coord_values = {}
if "x" in kwargs:
coord_values["x"] = kwargs.pop("x")
Expand Down
28 changes: 21 additions & 7 deletions arpes/utilities/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def __add__(self, other: MappableDict) -> MappableDict:
if set(self.keys()) != set(other.keys()):
msg = "You can only add two MappableDicts with the same keys."
raise ValueError(msg)

return MappableDict({k: self.get(k) + other.get(k) for k in self})

def __sub__(self, other: MappableDict):
def __sub__(self, other: MappableDict) -> MappableDict:
"""Applies `-` onto values."""
if set(self.keys()) != set(other.keys()):
msg = "You can only subtract two MappableDicts with the same keys."
Expand Down Expand Up @@ -80,12 +79,27 @@ def deep_update(destination: dict[str, Any], source: dict[str, Any]) -> dict[str
return destination


def deep_equals(a: Any, b: Any) -> bool | None:
def deep_equals(
a: float
| str
| list[float | str]
| tuple[str, ...]
| tuple[float, ...]
| set[str | float]
| dict[str, float | str],
b: float
| str
| list[float | str]
| tuple[str, ...]
| tuple[float, ...]
| set[str | float]
| dict[str, float | str],
) -> bool | None:
"""An equality check that looks into common collection types."""
if not isinstance(b, type(a)):
return False

if isinstance(a, int | str | float):
if isinstance(a, str | float):
return a == b

if a is None:
Expand All @@ -100,14 +114,14 @@ def deep_equals(a: Any, b: Any) -> bool | None:
msg,
)

if isinstance(a, set):
if isinstance(a, set) and isinstance(b, set):
for item in a:
if item not in b:
return False

return all(item in a for item in b)

if isinstance(a, list | tuple):
if isinstance(a, list | tuple) and isinstance(b, list | tuple):
if len(a) != len(b):
return False

Expand All @@ -119,7 +133,7 @@ def deep_equals(a: Any, b: Any) -> bool | None:

return True

if isinstance(a, dict):
if isinstance(a, dict) and isinstance(b, dict):
if set(a.keys()) != set(b.keys()):
return False

Expand Down
10 changes: 6 additions & 4 deletions arpes/xarray_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import warnings
from collections import OrderedDict
from collections.abc import Sequence
from logging import INFO, Formatter, StreamHandler, getLogger
from typing import TYPE_CHECKING, Any, Literal, Self, TypeAlias, Unpack
from logging import DEBUG, INFO, Formatter, StreamHandler, getLogger
from typing import TYPE_CHECKING, Any, Literal, Self, TypeAlias, Unpack, reveal_type

import lmfit
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -102,7 +102,7 @@

ANGLE_VARS = ("alpha", "beta", "chi", "psi", "phi", "theta")

LOGLEVEL = INFO
LOGLEVEL = (DEBUG, INFO)[0]
logger = getLogger(__name__)
fmt = "%(asctime)s %(levelname)s %(name)s :%(message)s"
formatter = Formatter(fmt)
Expand Down Expand Up @@ -3189,7 +3189,9 @@ def mean_square_error(self) -> xr.DataArray:
def safe_error(model_result_instance: lmfit.model.ModelResult | None) -> float:
if model_result_instance is None:
return np.nan
assert isinstance(model_result_instance.residual, lmfit.model.ModelResult)
model_result_instance_residual_type_ = f"model_result_instance_residual_type: {reveal_type(model_result_instance.residual)}"
logger.debug(model_result_instance_residual_type_)
assert isinstance(model_result_instance.residual, np.ndarray)
return (model_result_instance.residual**2).mean()

return self._obj.G.map(safe_error)
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/converting-to-kspace.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"\n",
"**Note**: We will use Fermi edge corrected data for conversion. The function `load_energy_corrected` below handles this. You can see the document on Fermi edge corrections for more details.\n",
"\n",
"**Imports note**: This example uses a lot of imports, we have been explicit about them here so you know where to look in the code if you want to learn more, but you can also import more or less everything you need for day-to-day analysis with\n",
"~~**Imports note**: This example uses a lot of imports, we have been explicit about them here so you know where to look in the code if you want to learn more, but you can also import more or less everything you need for day-to-day analysis with~~\n",
"\n",
"```python\n",
"from arpes.all import *\n",
"```\n",
"~~```python~~\n",
"~~from arpes.all import *~~\n",
"~~```~~\n",
"\n",
"## Converting Volumetric Data\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/fermi-edge-correction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"outputs": [],
"source": [
"from arpes.io import example_data\n",
"from arpes.all import broadcast_model, AffineBroadenedFD\n",
"from arpes.fits import broadcast_model, AffineBroadenedFD\n",
"\n",
"photon_energy = example_data.photon_energy"
]
Expand Down

0 comments on commit e3e5ac5

Please sign in to comment.