-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwf_BIDS2SQLite.py
More file actions
53 lines (46 loc) · 1.91 KB
/
Copy pathwf_BIDS2SQLite.py
File metadata and controls
53 lines (46 loc) · 1.91 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from ETL.Extract.extract import extract_sidecar_data
from ETL.Transform.transform import transform_sidecar_data
from ETL.Load.load import load_sidecar_data, database_setup
from ETL.PostTransform.post_transformation import update_subject_ids, update_transformation_id, backpropation
import logging
# Main Workflow function
def workflow_BIDS2SQLite():
"""
This function is the workflow of the ETL process.
It calls the extract_sidecar_data, transform_sidecar_data, and load_data functions.
"""
# Log the start of the workflow
workflow_logger.info("Workflow started.")
# Extract data
extracted_data = extract_sidecar_data()
workflow_logger.info("Data extracted successfully.")
# Transform data
transform_sidecar_data(extracted_data)
workflow_logger.info("Data transformed successfully.")
# Create database
database_setup()
# Load data
load_sidecar_data()
# Populate subject_id in files table after load
update_subject_ids()
update_transformation_id()
backpropation()
workflow_logger.info("Workflow finished successfully.")
# Main program
if __name__ == "__main__":
"""
This is the main program that will be executed when the script is run.
It calls the main_workflow function to execute the ETL process.
1) Extract data from BIDS sidecar files
2) Transform the data, according to the mapping rules.
3) Load the transformed data into the destination database. SQLite in this case.
"""
# Configure logger
workflow_logger = logging.getLogger('workflow_logger')
workflow_logger.setLevel(logging.INFO)
file_handler1 = logging.FileHandler('Workflow-debug.log')
formatter = logging.Formatter('%(asctime)-20s - %(levelname)-10s - %(filename)-25s - %(funcName)-25s %(message)-50s')
file_handler1.setFormatter(formatter)
workflow_logger.addHandler(file_handler1)
# Execute the main workflow
workflow_BIDS2SQLite()