create_analysis_tree.py 2.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Create the directory structure for an analysis.
    Change the default value for the Parent folder in the argparse
    
        Parent_Folder
        └──DL1
            ├── source
            │   └── night
            │      └── version
            │           └── cleaning
            DL2
            ├── source
            │   └── night
            │      └── version
            │           └── cleaning
            DL3
            └── source
                └── night
                   └── version
                        └── cleaning
"""

import os
import argparse
from argparse import RawTextHelpFormatter


def makedir(name):
    """
    Create folder if non-existent and output OS error if any.

    Parameters
    ----------
    name : str
        Name of the analysis.
    """

    # Create target Directory if don't exist
    if not os.path.exists(name):
        os.makedirs(name)
Alice Donini's avatar
Alice Donini committed
40
        print("Directory ", name, " created ")
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    else:
        print("Directory ", name, " already exists")
    return None


def main():
    # define command-line arguments
    description = 'Create a directory structure'

    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=RawTextHelpFormatter
    )

    parser.add_argument(
        '--main_dir', type=str, required=False, dest='main_dir',
        default='/fefs/aswg/workspace/alice.donini/Analysis/data',
        help='Path to parent folder'
    )

    parser.add_argument(
        '--source', type=str, required=True, dest='source',
        help='Source name'
    )

    parser.add_argument(
Alice Donini's avatar
Alice Donini committed
67
        '--night', nargs='+', type=int, required=True, dest='night',
68
69
70
71
72
        help='Night date'
    )

    parser.add_argument(
        '--version', type=str, required=False, dest='version',
Alice Donini's avatar
Alice Donini committed
73
        default='v0.9.2', help='lstchain version (default: %(default)s)'
74
75
76
77
    )

    parser.add_argument(
        '--cleaning', type=str, required=False, dest='cleaning',
Alice Donini's avatar
Alice Donini committed
78
        default='tailcut84', help='Cleaning type (default: %(default)s)'
79
80
81
82
83
84
    )

    args = parser.parse_args()
    
    # Define analysis directories and subdirectories
    data_dir = ['DL1', 'DL2', 'DL3']
Alice Donini's avatar
Alice Donini committed
85
    nights = args.night
86

Alice Donini's avatar
Alice Donini committed
87
88
89
90
91
    for night in nights:
        structure = f'{args.source}/{night}/{args.version}/{args.cleaning}'
        for folder in data_dir:
            dirName = os.path.join(f'{args.main_dir}', str(folder), structure)
            makedir(dirName)
92

Alice Donini's avatar
Alice Donini committed
93
    print(f'Directory structure for analysis on {args.source} was created.')
94
95
96
97


if __name__ == "__main__":
    main()