Coverage for src/susi/base/config/data.py: 96%

28 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-06-13 14:15 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4Module to specify configuration for dir stricture and fle handling 

5 

6@author: hoelken 

7""" 

8from dataclasses import dataclass 

9from ..exceptions import MissConfigurationException 

10 

11 

12@dataclass 

13class Data: 

14 #: Input folder base: root folder for the data to load 

15 root: str = '/home/sunrise/data' 

16 

17 #: Input level: this is the reduction level directory 

18 level: str = 'level_0' 

19 

20 #: Output level. Overrides the default output level wich is given by the pipeline definition (block grouping) 

21 #: Define a list that replaces each level of the pipeline. e.g., if original pipeline has two levels 

22 #: being output by default to /level_0 and /level_1. Then, custom_out_levels = [3, 5] makes the output 

23 #: to be written to /level_3 and /level_5 instead. 

24 custom_out_levels = None 

25 

26 #: Input folder dataset. Also used as output filename: Typically the date/date_hour directory. 

27 dataset: str = None 

28 

29 #: Input folder lookup pattern: The glob pattern to look for files. 

30 #: See https://docs.python.org/3/library/glob.html for supported patterns 

31 pattern: str = '**/*' 

32 

33 #: Prefix in level0 and level0.1 file nameing. Everything before '_YYYYMMDD_...'' 

34 file_prefix: str = 'im' 

35 

36 #: Regex pattern of the file name to identify the date, time and id (these named groups are required!) 

37 file_name_pattern: str = "(?P<pre>\\w*)_(?P<date>\\d{8})_(?P<time>\\d{6})_(?P<id>\\d{7})_(?P<cam>\\w*)\\.(?P<ex>.*)" 

38 

39 #: Input files extension: The extension of the file(s) to read. Supported are `.fits` and `.fits.gz` 

40 ext: str = '.fits.gz' 

41 

42 #: Output files extension: The extension of the file(s) to write. Supported are `.fits` and `.fits.gz` 

43 ext_out: str = '.fits.gz' 

44 

45 #: Output directory. See Config.out_file_path() 

46 out_path: str = None 

47 

48 #: Output pipeline subdirectory. Overrides the default directory wich is identical to the pipeline name 

49 custom_pipeline_dir: str = None 

50 

51 #: Logging directory. 

52 log_dir: str = None 

53 

54 #: Do not skip any module but re-do every processing step from the entry-level. 

55 force_reprocessing: bool = False 

56 

57 #: Generate PDF reports for the metadata 

58 generate_pdf_reports: bool = True 

59 

60 def __repr__(self) -> str: 

61 txt = f'== {self.__class__.__name__} ==\n' 

62 txt += '\n'.join(['{:<21} = {}'.format(k, v) for k, v in self.__dict__.items()]) 

63 return txt 

64 

65 def amend_from_dict(self, data: dict): 

66 """ 

67 Overwrites the parameters with the values from the given dictionary. 

68 All instance variable names are supported as keywords. 

69 All keywords are optional, if the keyword is not present the previous value will be kept. 

70 

71 ### Params 

72 - data: The dictionary to parse. 

73 - c_name: The name of the camera to set defaults for. 

74 

75 ### Returns 

76 the created Config 

77 """ 

78 for k, v in data.items(): 

79 if not hasattr(self, k): 

80 raise MissConfigurationException(f'{self.__class__.__name__} config has no attribute {k}') 

81 setattr(self, k, v)