Skip to content

Commit

Permalink
201 move reporting to the lib (#202)
Browse files Browse the repository at this point in the history
* first summary element

* refinement section

* test rename

* utils with counting

* experiments section

* html summary

* skeleton parameter

* replace in template

* paramaters as table

* html formatting

* html formatting

* summary formatting

* constained parameters

* constraints in summary

* summary

* cleaning project info

* pdf summary

* summary update

* code cleaning

* figures in summary

* only figures when requested

* legends and eps files

* back to jpg

* notebook for project object

* text adjustments project notebook

* link to pdf

* always add project information

* pr response

* reduce code complexity

* trying to understand CodeFactor

* more CodeFactor

* trying to make CodaFactor happy

* CodaFactor problems

* CodeFactor

* codefactor

* cidefactor

* codefactor

* codefactor

* code factor

* codefactor

* code factor

* CodeFactor

* code factor

* code factor

* codefactor

* codafactor not using free

* code factor

* code factor

* code facoter

* count functionality back to utils
  • Loading branch information
andped10 authored Nov 21, 2024
1 parent e64c4b4 commit 0cd7dcb
Show file tree
Hide file tree
Showing 10 changed files with 932 additions and 20 deletions.
315 changes: 315 additions & 0 deletions docs/src/tutorials/project.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
{
"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": 2,
"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. There should only be one such object. The project is follwoing set to have the current folder at its root and the we give it the name: `MyNewProject`. "
]
},
{
"cell_type": "code",
"execution_count": 3,
"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": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"EasyModels:\n",
"- EasyModel:\n",
" scale: 1.0\n",
" background: 1.0e-08\n",
" resolution: 5.0 %\n",
" color: black\n",
" sample:\n",
" EasySample:\n",
" - Superphase:\n",
" Vacuum Layer:\n",
" - Vacuum Layer:\n",
" material:\n",
" Air:\n",
" sld: 0.000e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
" thickness: 0.000 Å\n",
" roughness: 0.000 Å\n",
" - D2O:\n",
" D2O Layer:\n",
" - D2O Layer:\n",
" material:\n",
" D2O:\n",
" sld: 6.335e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
" thickness: 100.000 Å\n",
" roughness: 3.000 Å\n",
" - Subphase:\n",
" Si Layer:\n",
" - Si Layer:\n",
" material:\n",
" Si:\n",
" sld: 2.074e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
" thickness: 0.000 Å\n",
" roughness: 1.200 Å\n",
"\n"
]
}
],
"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": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"EasyMaterials:\n",
"- Air:\n",
" sld: 0.000e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
"- D2O:\n",
" sld: 6.335e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
"- Si:\n",
" sld: 2.074e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
"\n"
]
}
],
"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": 6,
"metadata": {},
"outputs": [],
"source": [
"project.save_as_json(overwrite=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also generate a summary of the project. We are also going to store the PDF and HTML files with the summary in the project folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"WindowsPath('MyNewProject/summary.pdf')"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"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": [
"[Link to PDF summary](MyNewProject/summary.pdf) in `MyNewProject/summary.pdf`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can reset the project to a blank state."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"EasyModels: []\n",
"\n",
"EasyMaterials: []\n",
"\n"
]
}
],
"source": [
"project.reset()\n",
"print(project.models)\n",
"print(project._materials)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then let us try to load the state we saved above."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"EasyModels:\n",
"- EasyModel:\n",
" scale: 1.0\n",
" background: 1.0e-08\n",
" resolution: 5.0 %\n",
" color: black\n",
" sample:\n",
" EasySample:\n",
" - Superphase:\n",
" EasyLayerCollection:\n",
" - Vacuum Layer:\n",
" material:\n",
" Air:\n",
" sld: 0.000e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
" thickness: 0.000 Å\n",
" roughness: 0.000 Å\n",
" - D2O:\n",
" EasyLayerCollection:\n",
" - D2O Layer:\n",
" material:\n",
" D2O:\n",
" sld: 6.335e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
" thickness: 100.000 Å\n",
" roughness: 3.000 Å\n",
" - Subphase:\n",
" EasyLayerCollection:\n",
" - Si Layer:\n",
" material:\n",
" Si:\n",
" sld: 2.074e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
" thickness: 0.000 Å\n",
" roughness: 1.200 Å\n",
"\n",
"EasyMaterials:\n",
"- Air:\n",
" sld: 0.000e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
"- D2O:\n",
" sld: 6.335e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
"- Si:\n",
" sld: 2.074e-6 1/Å^2\n",
" isld: 0.000e-6 1/Å^2\n",
"\n"
]
}
],
"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
}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ dependencies = [
"refnx>=0.1.15",
"refl1d>=0.8.14",
"orsopy>=0.0.4",
"pint==0.23" # Only to ensure that unit is reported as dimensionless rather than empty string
"pint==0.23", # Only to ensure that unit is reported as dimensionless rather than empty string
"xhtml2pdf>=0.2.16"
]

[project.optional-dependencies]
Expand Down
6 changes: 2 additions & 4 deletions src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,8 @@ def remove_material(self, index: int) -> None:

def _default_info(self):
return dict(
name='ExampleProject',
name='DefaultEasyReflectometryProject',
short_description='Reflectometry, 1D',
samples='None',
experiments='None',
modified=datetime.datetime.now().strftime('%d.%m.%Y %H:%M'),
)

Expand All @@ -349,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
3 changes: 3 additions & 0 deletions src/easyreflectometry/summary/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .summary import Summary

__all__ = [Summary]
Loading

0 comments on commit 0cd7dcb

Please sign in to comment.