Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

201 move reporting to the lib #202

Merged
merged 51 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ff1980c
first summary element
andped10 Nov 15, 2024
b23a342
refinement section
andped10 Nov 15, 2024
4c3a0d7
test rename
andped10 Nov 15, 2024
779fdda
Merge branch 'develop' into 201-move-reporting-to-the-lib
andped10 Nov 15, 2024
efbc9e5
utils with counting
andped10 Nov 15, 2024
edb273e
experiments section
andped10 Nov 18, 2024
b8dbe1b
html summary
andped10 Nov 18, 2024
7506932
skeleton parameter
andped10 Nov 18, 2024
4167271
replace in template
andped10 Nov 18, 2024
02ec5ab
paramaters as table
andped10 Nov 18, 2024
2b9f8a7
html formatting
andped10 Nov 18, 2024
ec22bc2
html formatting
andped10 Nov 18, 2024
0181639
summary formatting
andped10 Nov 18, 2024
4c57068
constained parameters
andped10 Nov 18, 2024
70ca601
constraints in summary
andped10 Nov 18, 2024
837089b
summary
andped10 Nov 18, 2024
9c2f3b6
cleaning project info
andped10 Nov 18, 2024
2e45144
pdf summary
andped10 Nov 18, 2024
cdfcef1
summary update
andped10 Nov 18, 2024
489e1ab
code cleaning
andped10 Nov 18, 2024
b3d1c72
figures in summary
andped10 Nov 18, 2024
f1f95db
only figures when requested
andped10 Nov 20, 2024
2768a35
legends and eps files
andped10 Nov 20, 2024
514cd4c
back to jpg
andped10 Nov 20, 2024
f28206a
notebook for project object
andped10 Nov 20, 2024
bb4f21c
text adjustments project notebook
andped10 Nov 20, 2024
1c69d5f
link to pdf
andped10 Nov 20, 2024
60b0e14
always add project information
andped10 Nov 21, 2024
c169b8d
pr response
andped10 Nov 21, 2024
2afb8dc
reduce code complexity
andped10 Nov 21, 2024
600e4ff
trying to understand CodeFactor
andped10 Nov 21, 2024
3dfeeb9
more CodeFactor
andped10 Nov 21, 2024
497e978
trying to make CodaFactor happy
andped10 Nov 21, 2024
10d3927
CodaFactor problems
andped10 Nov 21, 2024
c49469e
CodeFactor
andped10 Nov 21, 2024
c2a69ca
codefactor
andped10 Nov 21, 2024
6c522ef
cidefactor
andped10 Nov 21, 2024
ef48a0c
codefactor
andped10 Nov 21, 2024
d6c62b3
codefactor
andped10 Nov 21, 2024
b1ed9bd
code factor
andped10 Nov 21, 2024
1542bee
codefactor
andped10 Nov 21, 2024
fa73379
code factor
andped10 Nov 21, 2024
01f8adb
CodeFactor
andped10 Nov 21, 2024
47602d9
code factor
andped10 Nov 21, 2024
2b1032b
code factor
andped10 Nov 21, 2024
fe36b1b
codefactor
andped10 Nov 21, 2024
eaf4caa
codafactor not using free
andped10 Nov 21, 2024
32333e0
code factor
andped10 Nov 21, 2024
d5ac329
code factor
andped10 Nov 21, 2024
334152e
code facoter
andped10 Nov 21, 2024
0286c6e
count functionality back to utils
andped10 Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading