Source code for viiapackage.analyses.viia_analysis_folder

### ===================================================================================================================
###  FUNCTION to create the analysis folder
### ===================================================================================================================
# Copyright ©VIIA 2024

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from __future__ import annotations
from datetime import datetime
from pathlib import Path
from typing import TYPE_CHECKING, Optional

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_create_folder

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject


### ===================================================================================================================
###   2. Function viia_analysis_folder
### ===================================================================================================================

[docs]def viia_analysis_folder( project: ViiaProject, analysis_nr: str, signal: Optional[str] = None, direction: Optional[str] = None, loadtype: Optional[str] = None, software: Optional[str] = 'diana', time_reference: Optional[str] = None) -> \ Path: """ This function creates the new folder for the current analysis. It creates it in the analysis sub-folder and then a sub-folder with the timestamp and version number. If signals or directions are required, these are sub-folders of the sub-folder with the timestamp and version number. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - analysis_nr (str): Current analysis referencing the numbers in the viiaStatus. For example 'A1'. - signal (str): If a signal name is provided, the folder will be created for this signal inside the analysis folder. The signal number references the VIIA naming convention in viiaStatus, for example 'S1'. - direction (str): If a direction name is provided, the folder will be created for this direction inside the analysis folder. The direction name references the VIIA naming convention in viiaStatus, for example 'X_pos'. - loadtype (str): Type of loading identified as string: e.g. 'modal' or 'uni'. - software (str): The software for which the analysis folder should be created. Specified as 'diana' by default. - time_reference (str): Contains the time stamp that will be used in the name of the sub-folder. If no time-stamp is provided, it will be calculated. Output: - The sub-folder is created, including the parent folders, if not existing. - The folder is set as current analysis folder and returned. - The creation process is logged in the log-file. For example: .. code-block:: python viia_analysis_folder(project=project, analysis_nr='A1') viia_analysis_folder( project=project, analysis_nr='A11', direction='X_neg', loadtype='modal', time_reference=time_reference) viia_analysis_folder(project=project, analysis_nr='A12', signal='S1', time_reference=time_reference) """ # Directory for files for analysis software_settings = getattr(project, f'{software.lower()}_settings') folder = Path.cwd() / software_settings.analysis_settings[analysis_nr]['folder_name'] # Add sub-folder (always) for timestamp and version if not time_reference: time_reference = datetime.now().strftime('%Y%m%d%H%M%S') folder = folder / f"{time_reference}-v{str(project.version).zfill(3)}" # Add sub-folder for signal if required if signal: folder = folder / project.project_specific['signal'][signal] # Add sub-folder for direction if required if direction and not loadtype: folder = folder / direction elif direction and loadtype: folder = folder / f"{direction}_{loadtype}" # Check if signal and direction are collected both, this is not allowed if signal and direction: raise ValueError("ERROR: Analysis folder cannot contain both signal and direction sub-folders.") # Create the folder fem_create_folder(folder) # Set the current analysis status parameter in Project software_settings.current_analysis_folder = folder project.current_analysis_folder = folder # Return the current analysis folder return folder
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================