Skip to content

Commit

Permalink
constained parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Nov 18, 2024
1 parent 0181639 commit 4c57068
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/easyreflectometry/summary/html_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<body>
<table>
<!-- Summary title -->
<tr>
<td><h1>Summary</h1></td>
Expand All @@ -25,23 +26,23 @@
<!-- Sample -->
<tr>
<td><h3>Sample</h3></td>
<td><h2>Sample</h2></td>
</tr>
sample_section
<tr></tr>
<!-- Experiments -->
<tr>
<td><h3>Experiments</h3></td>
<td><h2>Experiments</h2></td>
</tr>
experiments_section
<tr></tr>
<!-- Analysis -->
<tr>
<td><h3>Refinement</h3></td>
<td><h2>Refinement</h2></td>
</tr>
refinement_section
Expand Down Expand Up @@ -101,8 +102,8 @@
<td>radiation_type</td>
</tr>
<tr>
<td>Measured range: min, max, inc (range_units)</td>
<td>range_min,&nbsp;&nbsp;range_max,&nbsp;&nbsp;range_inc</td>
<td>Measured range: min, max</td>
<td>range_min,&nbsp;&nbsp;range_max,&nbsp;&nbsp</td>
</tr>
<tr>
<td>No. of data points</td>
Expand All @@ -119,10 +120,10 @@
<td>Minimization engine</td>
<td>minimization_engine</td>
</tr>
<tr>
<td>Goodness-of-fit: reduced <i>&chi;</i><sup>2</sup></td>
<td>goodness_of_fit</td>
</tr>
<!-- <tr> -->
<!-- <td>Goodness-of-fit: reduced <i>&chi;</i><sup>2</sup></td> -->
<!-- <td>goodness_of_fit</td> -->
<!-- </tr> -->
<tr>
<td>No. of parameters: total, free, fixed</td>
<td>num_total_params, num_free_params, num_fixed_params</td>
Expand Down
14 changes: 11 additions & 3 deletions src/easyreflectometry/summary/summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from easyscience import global_object

from easyreflectometry import Project
from easyreflectometry.utils import count_fixed_parameters
from easyreflectometry.utils import count_free_parameters
from easyreflectometry.utils import count_parameter_user_constraints

from .html_templates import HTML_DATA_COLLECTION_TEMPLATE
from .html_templates import HTML_PARAMETER_HEADER_TEMPLATE
Expand Down Expand Up @@ -45,7 +48,6 @@ def _project_information_section(self) -> None:
short_description = self._project._info['short_description']
html_project = html_project.replace('project_title', f'{name}')
html_project = html_project.replace('project_description', f'{short_description}')
# html_project = html_project.replace('num_phases', f'{self._project.status.phaseCount}')
html_project = html_project.replace('num_experiments', f'{len(self._project.experiments)}')
return html_project

Expand All @@ -60,7 +62,13 @@ def _sample_section(self) -> None:
html_parameters.append(html_parameter)

for parameter in self._project.parameters:
name = parameter.name
path = global_object.map.find_path(
self._project._models[self._project.current_model_index].unique_name, parameter.unique_name
)
if 0 < len(path):
name = f'{global_object.map.get_item_by_key(path[-2]).name} {global_object.map.get_item_by_key(path[-1]).name}'
else:
name = parameter.name
value = parameter.value
unit = parameter.unit
error = parameter.error
Expand Down Expand Up @@ -157,7 +165,7 @@ def _refinement_section(
num_params = num_free_params + num_fixed_params
# goodness_of_fit = self._project.status.goodnessOfFit
# goodness_of_fit = goodness_of_fit.split(' → ')[-1]
num_constraints = 0
num_constraints = count_parameter_user_constraints(self._project)

html_refinement = html_refinement.replace('calculation_engine', f'{self._project._calculator.current_interface_name}')
html_refinement = html_refinement.replace('minimization_engine', f'{self._project.minimizer.name}')
Expand Down
9 changes: 9 additions & 0 deletions src/easyreflectometry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ def count_fixed_parameters(project) -> int:
if not parameter.free:
count = count + 1
return count


def count_parameter_user_constraints(project) -> int:
count = 0
parameters = project.parameters
for parameter in parameters:
if parameter.constraint:
count = count + len(parameter.user_constraints.keys())
return count

0 comments on commit 4c57068

Please sign in to comment.