I am trying to calculate a radius-like quantity from 3 lists containing Cartesian coordinates x, y & z. Below is my minimal code example to reproduce the issue I am facing; The child-class calculates the radius-quantity but returns a zero-value. What is the reason for this, and how can it be fixed?
Script:
# -*- coding: utf-8 -*-
from dataclasses import dataclass, field
from typing import List
@dataclass
class LoadHalo:
x: List = field(default_factory=list)
y: List = field(default_factory=list)
z: List = field(default_factory=list)
def __post_init__(self):
self.x = [1, 2, 3]
self.y = [1, 3, 5]
self.z = [1, 4, 7]
@dataclass
class BinHalo(LoadHalo):
r: List = field(default_factory=list)
def __post_init__(self):
self.r = self.modulus(self.x, self.y, self.z)
def modulus(self, *args):
"""Modulus of vector of arbitrary size."""
return sum([i ** 2 for containers in args for i in containers]) ** .5
halo = BinHalo()
print(f"halo.x: {halo.x}")
print(f"halo.r: {halo.r}")
Which outputs the following values for x and r:
halo.x: []
halo.r: 0.0
super().__post_init__()beforeself.r = self.modulus(self.x, self.y, self.z)