Skip to content

npxpy.nodes.space.Array

Bases: _GatekeeperSpace

Class representing an array node with additional attributes.

Attributes:

Name Type Description
position List[float]

Position of the array [x, y, z].

rotation List[float]

Rotation of the array [psi, theta, phi].

count List[int]

Number of grid points in [x, y] direction.

spacing List[float]

Spacing of the grid in [width, height].

order str

Order of the array ('Lexical' or 'Meander').

shape str

Shape of the array ('Rectangular' or 'Round').

Source code in npxpy/nodes/space.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
class Array(_GatekeeperSpace):
    """
    Class representing an array node with additional attributes.

    Attributes:
        position (List[float]): Position of the array [x, y, z].
        rotation (List[float]): Rotation of the array [psi, theta, phi].
        count (List[int]): Number of grid points in [x, y] direction.
        spacing (List[float]): Spacing of the grid in [width, height].
        order (str): Order of the array ('Lexical' or 'Meander').
        shape (str): Shape of the array ('Rectangular' or 'Round').
    """

    def __init__(
        self,
        name: str = "Array",
        position: List[float] = [0, 0, 0],
        rotation: List[float] = [0.0, 0.0, 0.0],
        count: List[int] = [5, 5],
        spacing: List[float] = [100.0, 100.0],
        order: str = "Lexical",
        shape: str = "Rectangular",
    ):
        """
        Initialize an Array node.
        """
        super().__init__("array", name)
        self.position = position
        self.rotation = rotation
        self.count = count
        self.spacing = spacing
        self.order = order
        self.shape = shape

    # Setters for other attributes
    @property
    def count(self):
        return self._count

    @property
    def count(self):
        return self._count

    @count.setter
    def count(self, value: List[int]):
        if len(value) != 2 or not all(
            isinstance(c, int) and c > 0 for c in value
        ):
            raise ValueError(
                "Count must be a list of exactly two integers greater than zero."
            )
        self._count = value

    @property
    def spacing(self):
        return self._spacing

    @spacing.setter
    def spacing(self, value: List[float]):
        if len(value) != 2 or not all(
            isinstance(s, (int, float)) for s in value
        ):
            raise ValueError(
                "Spacing must be a list of exactly two numeric values."
            )
        self._spacing = value

    @property
    def order(self):
        return self._order

    @order.setter
    def order(self, value: str):
        if value not in ["Lexical", "Meander"]:
            raise ValueError("order must be either 'Lexical' or 'Meander'.")
        self._order = value

    @property
    def shape(self):
        return self._shape

    @shape.setter
    def shape(self, value: str):
        if value not in ["Rectangular", "Round"]:
            raise ValueError("shape must be either 'Rectangular' or 'Round'.")
        self._shape = value

    def set_grid(
        self, count: List[int] = count, spacing: List[float] = spacing
    ):
        """
        Set the count and spacing of the array grid.

        Parameters:
            count (List[int]): The new grid point count.
            spacing (List[float]): The new grid spacing.

        Returns:
            Array: The updated Array object.
        """
        self.count = count
        self.spacing = spacing
        return self

    def to_dict(self) -> Dict:
        """
        Convert the Array object into a dictionary.
        """
        node_dict = super().to_dict()
        node_dict["position"] = self.position
        node_dict["rotation"] = self.rotation
        node_dict["count"] = self.count
        node_dict["spacing"] = self.spacing
        node_dict["order"] = self.order
        node_dict["shape"] = self.shape
        return node_dict

__init__(name='Array', position=[0, 0, 0], rotation=[0.0, 0.0, 0.0], count=[5, 5], spacing=[100.0, 100.0], order='Lexical', shape='Rectangular')

Initialize an Array node.

Source code in npxpy/nodes/space.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
def __init__(
    self,
    name: str = "Array",
    position: List[float] = [0, 0, 0],
    rotation: List[float] = [0.0, 0.0, 0.0],
    count: List[int] = [5, 5],
    spacing: List[float] = [100.0, 100.0],
    order: str = "Lexical",
    shape: str = "Rectangular",
):
    """
    Initialize an Array node.
    """
    super().__init__("array", name)
    self.position = position
    self.rotation = rotation
    self.count = count
    self.spacing = spacing
    self.order = order
    self.shape = shape

set_grid(count=count, spacing=spacing)

Set the count and spacing of the array grid.

Parameters:

Name Type Description Default
count List[int]

The new grid point count.

count
spacing List[float]

The new grid spacing.

spacing

Returns:

Name Type Description
Array

The updated Array object.

Source code in npxpy/nodes/space.py
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def set_grid(
    self, count: List[int] = count, spacing: List[float] = spacing
):
    """
    Set the count and spacing of the array grid.

    Parameters:
        count (List[int]): The new grid point count.
        spacing (List[float]): The new grid spacing.

    Returns:
        Array: The updated Array object.
    """
    self.count = count
    self.spacing = spacing
    return self

to_dict()

Convert the Array object into a dictionary.

Source code in npxpy/nodes/space.py
344
345
346
347
348
349
350
351
352
353
354
355
def to_dict(self) -> Dict:
    """
    Convert the Array object into a dictionary.
    """
    node_dict = super().to_dict()
    node_dict["position"] = self.position
    node_dict["rotation"] = self.rotation
    node_dict["count"] = self.count
    node_dict["spacing"] = self.spacing
    node_dict["order"] = self.order
    node_dict["shape"] = self.shape
    return node_dict