Skip to content

Commit a8579c9

Browse files
committed
Linting fixes
Signed-off-by: Nicola VIGANO <nicola.vigano@esrf.fr>
1 parent 7c493ff commit a8579c9

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

corrct/alignment/cone_beam.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def __str__(self) -> str:
6262
The human readable representation of the object.
6363
"""
6464
descr = "AcquisitionGeometry(\n"
65-
for f, v in self.__dict__.items():
66-
descr += f" {f} = {v}"
67-
if f.lower()[-3:] == "rad":
68-
descr += f" ({np.rad2deg(v)} deg)"
65+
for field, value in self.__dict__.items():
66+
descr += f" {field} = {value}"
67+
if field.lower()[-3:] == "deg":
68+
descr += f" ({value} deg)"
6969
descr += ",\n"
7070
return descr + ")"
7171

@@ -203,7 +203,7 @@ def to_json(self) -> str:
203203
"""
204204
return _class_to_json(self)
205205

206-
def from_json(self, data: str) -> None:
206+
def from_json(self, data_json: str) -> None:
207207
"""
208208
Load instance from JSON.
209209
@@ -217,17 +217,20 @@ def from_json(self, data: str) -> None:
217217
ValueError
218218
In case we were to load more than one instance, or different classes.
219219
"""
220-
d = json.loads(data)
221-
if len(d.keys()) > 1:
220+
data_tree = json.loads(data_json)
221+
if len(data_tree.keys()) > 1:
222222
raise ValueError("Initialization from JSON: More than one class instance passed.")
223-
class_name = list(d.keys())[0]
224-
if list(d.keys())[0] != self.__class__.__name__:
223+
224+
class_name = list(data_tree.keys())[0]
225+
if list(data_tree.keys())[0] != self.__class__.__name__:
225226
raise ValueError(
226-
f"Initialization from JSON: expecting {self.__class__.__name__} class instance, but {d.keys()[0]} passed."
227+
f"Initialization from JSON: expecting {self.__class__.__name__} class instance,"
228+
f" but {data_tree.keys()[0]} passed."
227229
)
228-
d = d[class_name]
229-
for k in self.__dict__.keys():
230-
self.__dict__[k] = d[k]
230+
231+
data_dict = data_tree[class_name]
232+
for key in self.__dict__.keys():
233+
self.__dict__[key] = data_dict[key]
231234

232235

233236
class FitConeBeamGeometry:
@@ -238,6 +241,8 @@ class FitConeBeamGeometry:
238241
doi: 10.1088/0031-9155/45/11/327
239242
"""
240243

244+
acq_geom: ConeBeamGeometry
245+
241246
def __init__(
242247
self,
243248
prj_size_vu: Union[ArrayLike, NDArray],
@@ -267,6 +272,7 @@ def __init__(
267272
"""
268273
self.prj_size_vu = np.array(prj_size_vu)
269274
self.center_vu = self.prj_size_vu[:, None] / 2
275+
self.prj_origin_vu = None
270276

271277
self.points_ell1 = np.array(points_ell1) - self.center_vu
272278
self.points_ell2 = np.array(points_ell2) - self.center_vu
@@ -280,9 +286,12 @@ def __init__(
280286
self.verbose = verbose
281287
self.plot_result = plot_result and verbose
282288

283-
self._pre_fit()
289+
self.z1 = np.array([])
290+
self.z2 = np.array([])
291+
292+
self._initialize()
284293

285-
def _pre_fit(self, use_least_squares: bool = False) -> None:
294+
def _initialize(self, use_least_squares: bool = False) -> None:
286295
self.ell1_acq = fitting.Ellipse(self.points_ell1, least_squares=use_least_squares)
287296
self.ell2_acq = fitting.Ellipse(self.points_ell2, least_squares=use_least_squares)
288297

@@ -398,26 +407,26 @@ def get_zeta(bk, ak, ck, D, sign_zk) -> float:
398407

399408
self.acq_geom.phi_deg = np.rad2deg(np.arcsin(-c1 / (2 * a1) * zeta1 - c2 / (2 * a2) * zeta2))
400409

401-
R1 = r / rho1
402-
R2 = r / rho2
410+
R_e1 = r / rho1
411+
R_e2 = r / rho2
403412

404-
self.z1 = R1 * zeta1
405-
self.z2 = R2 * zeta2
413+
self.z1 = R_e1 * zeta1
414+
self.z2 = R_e2 * zeta2
406415

407416
z_full = self.z1 - self.z2
408417

409418
self.acq_geom.theta_deg = 0.0
410419
# self.acq_geom.theta_rad = np.arcsin((R1 - R2) / z_full) / np.mean(self.prj_size_vu)
411420

412-
self.acq_geom.R = (-self.z2 * R1 + self.z1 * R2) / z_full
421+
self.acq_geom.R = (-self.z2 * R_e1 + self.z1 * R_e2) / z_full
413422

414423
if self.prj_origin_vu is None:
415424
self.prj_origin_vu = (-self.z2 * self.ell1_prj_center_vu + self.z1 * self.ell2_prj_center_vu) / z_full
416425
if self.verbose:
417426
print(f"Projected origin on the detector (pix): {self.prj_origin_vu}")
418427

419428
if self.verbose:
420-
print(f"Fitted distances between source and rotation axis (pix):\n- R1={R1}, R={self.acq_geom.R}, R2={R2}")
429+
print(f"Fitted distances between source and rotation axis (pix):\n- R1={R_e1}, R={self.acq_geom.R}, R2={R_e2}")
421430
print(f"Fitted heights of the two ellipses, with respect to the source (pix): z1={self.z1}, z2={self.z2}")
422431
print(f"Fitted polar angle of the detector (phi deg): {self.acq_geom.phi_deg}")
423432
print(f"Fitted azimuthal angle of the detector (theta deg): {self.acq_geom.theta_deg}")

0 commit comments

Comments
 (0)