Skip to content

Commit

Permalink
notebook for project object
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Nov 20, 2024
1 parent 514cd4c commit f28206a
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 1 deletion.
171 changes: 171 additions & 0 deletions docs/src/tutorials/project.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Project\n",
"This notebook serves to demonstrate some of the functionality of the Project object.\n",
"\n",
"## Setup\n",
"First configure matplotlib to place figures in notebook and import needed modules."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from easyreflectometry import Project\n",
"from easyreflectometry.summary import Summary"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Project object\n",
"\n",
"First we will create a Project object. This project is set be have the current folder at its root and the name (MyNewProject). "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"project = Project()\n",
"project.set_path_project_parent('.')\n",
"project._info['name'] = 'MyNewProject'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will then populate this Project with the default model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"project.default_model()\n",
"print(project.models)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also see which materials that are defined in the Project."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(project._materials)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is possible to save a `Project` object. It will be place in the project folder and the state will be save in the file name `project.json`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"project.save_as_json(overwrite=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also generate a summary of the project. The PDF and HTML files with the summary are also going to be stored in the project filder."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"summary = Summary(project)\n",
"summary.save_pdf_summary(str(project.path / 'summary.pdf'))\n",
"summary.save_html_summary(str(project.path / 'summary.html'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can reset the project to a blank state"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"project.reset()\n",
"print(project.models)\n",
"print(project._materials)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then let us try to load the saved state we saved above."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"project.set_path_project_parent('.')\n",
"project._info['name'] = 'MyNewProject'\n",
"project.load_from_json()\n",
"print(project.models)\n",
"print(project._materials)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ def save_as_json(self, overwrite=False):
print(exception)

def load_from_json(self, path: Optional[Union[Path, str]] = None):
path = Path(path)
if path is None:
path = self.path_json
path = Path(path)
if path.exists():
with open(path, 'r') as file:
project_dict = json.load(file)
Expand Down

0 comments on commit f28206a

Please sign in to comment.