Skip to content

Commit

Permalink
Merge branch 'master' into issue-65
Browse files Browse the repository at this point in the history
  • Loading branch information
yymao authored Jan 30, 2018
2 parents 0380402 + 8d33340 commit 3b509a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
14 changes: 7 additions & 7 deletions descqa/configs/readiness_protoDC2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ relations_to_check:
- '(size_bulge_true != 0) | (stellar_mass_bulge == 0)'
- 'stellar_mass_bulge <= stellar_mass'
- 'stellar_mass_disk <= stellar_mass'
- ['1.0 / magnification', '(1.0 - convergence)**2.0 - shear_1**2.0 - shear_2**2.0']
- ['size_minor_true / size_true', '(1.0 - ellipticity_true) / (1.0 + ellipticity_true)']
- ['size_minor_disk_true / size_disk_true', '(1.0 - ellipticity_disk_true) / (1.0 + ellipticity_disk_true)']
- ['size_minor_bulge_true / size_bulge_true', '(1.0 - ellipticity_bulge_true) / (1.0 + ellipticity_bulge_true)']
- ['ellipticity_1_true ** 2.0 + ellipticity_2_true ** 2.0', 'ellipticity_true ** 2.0']
- ['ellipticity_1_disk_true ** 2.0 + ellipticity_2_disk_true ** 2.0', 'ellipticity_disk_true ** 2.0']
- ['ellipticity_1_bulge_true ** 2.0 + ellipticity_2_bulge_true ** 2.0', 'ellipticity_bulge_true ** 2.0']
- '1.0 / magnification ~== (1.0 - convergence)**2.0 - shear_1**2.0 - shear_2**2.0'
- 'size_minor_true / size_true ~== (1.0 - ellipticity_true) / (1.0 + ellipticity_true)'
- 'size_minor_disk_true / size_disk_true ~== (1.0 - ellipticity_disk_true) / (1.0 + ellipticity_disk_true)'
- 'size_minor_bulge_true / size_bulge_true ~== (1.0 - ellipticity_bulge_true) / (1.0 + ellipticity_bulge_true)'
- 'ellipticity_1_true ** 2.0 + ellipticity_2_true ** 2.0 ~== ellipticity_true ** 2.0'
- 'ellipticity_1_disk_true ** 2.0 + ellipticity_2_disk_true ** 2.0 ~== ellipticity_disk_true ** 2.0'
- 'ellipticity_1_bulge_true ** 2.0 + ellipticity_2_bulge_true ** 2.0 ~== ellipticity_bulge_true ** 2.0'
38 changes: 22 additions & 16 deletions descqa/readiness_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ def evaluate_expression(expression, catalog_instance):
global_dict={})


def check_relation(relation, catalog_instance):
"""
check if *relation* is true in *catalog_instance*
"""
expr1, simeq, expr2 = relation.partition('~==')

if simeq:
expr1 = expr1.strip()
expr2 = expr2.strip()
return np.allclose(
evaluate_expression(expr1, catalog_instance),
evaluate_expression(expr2, catalog_instance),
equal_nan=True,
)

return evaluate_expression(relation, catalog_instance).all()


class CheckQuantities(BaseValidationTest):
"""
Readiness test to check catalog quantities before image simulations
Expand Down Expand Up @@ -187,29 +205,17 @@ def run_on_single_catalog(self, catalog_instance, catalog_name, output_dir):
failed_count += 1

for relation in self.relations_to_check:
if isinstance(relation, (tuple, list)):
assert len(relation) == 2, '`relation` must a single string or a list of *two* strings.'
func = lambda r: np.allclose(
evaluate_expression(r[0], catalog_instance),
evaluate_expression(r[1], catalog_instance),
equal_nan=True
)
relation_expr = '{} ~~ {}'.format(*relation)
else:
func = lambda r: evaluate_expression(r, catalog_instance).all()
relation_expr = relation

try:
result = func(relation)
result = check_relation(relation, catalog_instance)
except Exception as e: # pylint: disable=broad-except
output_header.append('<span class="fail">Not able to evaluate `{}`! {}</span>'.format(relation_expr, e))
output_header.append('<span class="fail">Not able to evaluate `{}`! {}</span>'.format(relation, e))
failed_count += 1
continue

if result:
output_header.append('<span>It is true that `{}`</span>'.format(relation_expr))
output_header.append('<span>It is true that `{}`</span>'.format(relation))
else:
output_header.append('<span class="fail">`{}` not true!</span>'.format(relation_expr))
output_header.append('<span class="fail">`{}` not true!</span>'.format(relation))
failed_count += 1

with open(os.path.join(output_dir, 'SUMMARY.html'), 'w') as f:
Expand Down

0 comments on commit 3b509a4

Please sign in to comment.