Projects - basics#

This tutorial focuses on working the Project object in plans.

Notebook setup#

For users running this tutorial as a Jupyter Notebook, this cell must be executed first:

import sys
from pathlib import Path
import pprint
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Install `plans` in `google.colab`.
# Use `pip install plans` for other environments.

if "google.colab" in sys.modules:
    import os
    os.system(f"{sys.executable} -m pip install -q plans")

# This avoids warnings related to uninstalled fonts
import logging
# Set the matplotlib font manager logger to only show errors (hides warnings)
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR)

# define output folder
OUTPUT_DIR = Path("outputs/projects")
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"Outputs will be saved to: ./{OUTPUT_DIR}")
Outputs will be saved to: ./outputs/projects

Import plans

import plans

Create a new project#

Set new project details in a python dict:

project_specs = {
    "folder_base": OUTPUT_DIR,
    "name": "newProject",
    "alias": "NPrj",
    "source": "Me",
    "description": "Just a test"
}

Then call the plans.new_project() function:

plans.new_project(specs=project_specs)
<plans.project.Project at 0x7fc9a0535490>

Warning

An error is raised if project already exists

This pattern creates and loads to a variable the plans.Project instance:

project_specs = {
    "folder_base": OUTPUT_DIR,
    "name": "newProject2",
    "alias": "NPrj2",
    "source": "Me",
    "description": "Just a test"
}

prj = plans.new_project(specs=project_specs)

View project structure using the .view() method:

prj.view()
newProject2
├── outputs
└── data
    ├── climate
    │   └── observed
    ├── lulc
    │   └── observed
    │       └── parameters
    ├── soils
    │   └── parameters
    ├── project_info.csv
    ├── topo
    └── basins
        └── main

Load an existing project#

Use the plans.load_project() function for loading an existing project from a folder path.

folder = f"{OUTPUT_DIR}/newProject"
prj = plans.load_project(project_folder=folder)

Inspect the project variable

print(prj)
Project: newProject
Folder base: /home/runner/work/plans/plans/docs/tutorials/outputs/projects
Folder root: /home/runner/work/plans/plans/docs/tutorials/outputs/projects/newProject