Coverage for qubalab/images/metadata/image_shape.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-31 11:24 +0000

1from __future__ import annotations 

2from dataclasses import dataclass 

3 

4 

5@dataclass 

6class ImageShape: 

7 """ 

8 Simple data class to store an image shape. 

9 

10 :param x: the image width 

11 :param y: the image height 

12 :param t: the number of time points 

13 :param c: the number of channels 

14 :param z: the number of z-stacks 

15 """ 

16 x: int 

17 y: int 

18 t: int = 1 

19 c: int = 1 

20 z: int = 1 

21 

22 def from_tczyx(*args) -> ImageShape: 

23 """ 

24 Create an ImageShape from a list of arguments. 

25  

26 :param args: image width, image height, number of time points, number of channels, number of z-stacks 

27 (in that order) 

28 :returns: an ImageShape corresponding to the arguments 

29 :raises IndexeError: when there are less than five arguments 

30 """ 

31 return ImageShape(t=args[0], c=args[1], z=args[2], y=args[3], x=args[4]) 

32 

33 def as_tuple(self, dims: str = 'tczyx') -> tuple: 

34 """ 

35 Return a tuple describing this ImageShape. 

36 

37 :param dims: the format the resulting tuple should have. Each character must be one of 'tczyx' 

38 :returns: a tuple describing this ImageShape with the specified format 

39 :raises AttributeError: when a character of dims is not in 'tczyx' 

40 """ 

41 return tuple(self.__getattribute__(d) for d in dims)