Example #1
0
def loadProject(projectPath: str, configFile: str = "") -> ProjectData:
    """Load an existing project

    Parameters
    ----------
    projectPath : str
        Path for the project directory
    configFile : str
        Path to a configuration file

    Returns
    -------
    ProjectData
        A project data object
    """
    # search for the .prj file (hopefully only one)
    gl = glob.glob(os.path.join(projectPath, "*.prj"))
    if len(gl) == 0:
        projectError(
            "Unable to find project file in path: {}".format(projectPath))
    projectFile: str = os.path.basename(gl[0])
    projectText("Loading project file: {}".format(
        os.path.join(projectPath, projectFile)))
    projectPaths = loadProjectFile(os.path.join(projectPath, projectFile))

    # check the configuration file
    config = ConfigData(configFile)
    proj = ProjectData(
        projectFile,
        projectPaths["refTime"],
        projectPaths["calPath"],
        projectPaths["timePath"],
        projectPaths["specPath"],
        projectPaths["statPath"],
        projectPaths["maskPath"],
        projectPaths["transFuncPath"],
        projectPaths["imagePath"],
        config=config,
    )
    proj.printInfo()
    proj.config.printInfo()
    return proj
Example #2
0
def newProject(
    projectPath: str,
    refTime: Union[str, datetime],
    configFile: str = "",
    name: str = "mtProj",
) -> ProjectData:
    """Create a new project in project path

    A new project will be created in project path. If the project path directory does not exist, a new one will be made. If a project already exists in project path, this project will be loaded and returned.

    Parameters
    ----------
    projectPath : str
        Path for the project directory
    refTime : datetime
        The reference time for the project
    configFile : str, optional
        Path to a configuration file
    name : str, optional (default is "mtProj")
        The name of the project file

    Returns
    -------
    ProjectData
        A project data object
    """
    # create project path directory
    checkAndMakeDir(projectPath)
    # reference time
    if isinstance(refTime, str):
        refTime = datetime.strptime(refTime, "%Y-%m-%d %H:%M:%S")
    # print info
    textLst = [
        "Creating a new project in path: {}".format(projectPath),
        "Project name: {}".format(name),
    ]
    projectBlock(textLst)

    # create the subdirectories
    projectFile = os.path.join(projectPath, "{}.prj".format(name))
    timePath = os.path.join(projectPath, "timeData")
    specPath = os.path.join(projectPath, "specData")
    statPath = os.path.join(projectPath, "statData")
    maskPath = os.path.join(projectPath, "maskData")
    transFuncPath = os.path.join(projectPath, "transFuncData")
    calPath = os.path.join(projectPath, "calData")
    imagePath = os.path.join(projectPath, "images")
    saveProjectFile(
        projectFile,
        refTime,
        calPath,
        timePath,
        specPath,
        statPath,
        maskPath,
        transFuncPath,
        imagePath,
    )

    # configuration file
    config = ConfigData(configFile)
    proj = ProjectData(
        projectFile,
        refTime,
        calPath,
        timePath,
        specPath,
        statPath,
        maskPath,
        transFuncPath,
        imagePath,
        config=config,
    )
    proj.printInfo()
    proj.config.printInfo()

    return proj