Skip to content

Commit

Permalink
don't require ncoefs if int_q is False
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelquast committed Nov 27, 2023
1 parent f312819 commit aabb9a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
38 changes: 15 additions & 23 deletions docs/examples/analyzemodel.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/rt1_model/_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def ncoefs(self):
if not hasattr(self, "_ncoefs") or self._ncoefs is None:
raise AttributeError(
"You must specify the number of approximation coefficients for "
f"a {self.__class__.__name__} scattering function "
"in order calculate interaction-terms!"
f"a {self.__class__.__name__} scattering function to calculate "
"first-order corrections! (or use `RT1(..., int_Q=False)` "
"to omit calculating the interaction-term."
)
return self._ncoefs

Expand Down
24 changes: 18 additions & 6 deletions src/rt1_model/plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Class for quick visualization of results and used phasefunctions."""

from itertools import cycle
from contextlib import contextmanager

import numpy as np

Expand Down Expand Up @@ -674,10 +675,7 @@ def __init__(self, R, samples=35, contributions="ts", **parameters):

self._samples = samples

if R.int_Q is False and "i" in contributions:
contributions = contributions.replace("i", "")
_log.warning("Interaction term requires int_Q=True!")

self._contributions = contributions
self._use_contribs = ["tsvi".index(i) for i in contributions]

self._labels = ["Total", "Surface", "Volume", "Interaction"]
Expand All @@ -690,7 +688,7 @@ def __init__(self, R, samples=35, contributions="ts", **parameters):
p_ex = np.deg2rad(np.linspace(-180, 180, self._samples))
t_ex, p_ex = np.meshgrid(t_ex, p_ex)

self._p_0 = np.pi / 2
self._p_0 = 0

self.R.set_bistatic(p_0=self._p_0)
self.R.set_geometry(
Expand Down Expand Up @@ -757,14 +755,28 @@ def _init_figure(self, slider_cols=2):
top=0.98, bottom=0.05, hspace=1, wspace=0.5, left=0.1, right=0.98
)

@contextmanager
def _cx_set_intq(self):
init_int_q = self.R.int_Q

try:
if "i" in self._contributions:
self.R.int_Q = True
else:
self.R.int_Q = False
yield
finally:
self.R.int_Q = init_int_q

def _getvals(self, inc=45):
self.R.set_geometry(
t_0=np.full_like(self.R.t_ex, np.deg2rad(inc)),
t_ex=self.R.t_ex,
p_ex=self.R.p_ex,
)

res = self.R.calc()
with self._cx_set_intq():
res = self.R.calc()

x = res * np.sin(self.R.t_ex) * np.cos(self.R.p_ex)
y = res * np.sin(self.R.t_ex) * np.sin(self.R.p_ex)
Expand Down

0 comments on commit aabb9a3

Please sign in to comment.