Skip to content

Commit

Permalink
WIP commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewoldag committed Jan 17, 2024
1 parent eaaf54d commit df3bf80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/rail/evaluation/dist_to_point_evaluator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from ceci.config import StageParameter as Param
from qp.metrics.base_metric_classes import MetricOutputType
from qp.metrics.concrete_metric_classes import DistToPointMetric

from rail.core.data import Hdf5Handle, QPHandle, TableHandle
Expand Down Expand Up @@ -63,9 +64,11 @@ def run(self):

self._output_handle.finalize_write()

#pylint: disable=too-many-arguments
def _process_chunk(self, start, end, estimate_data, reference_data, first):
out_table = {}
for metric in self.config.metrics:

if metric not in self._metric_dict:
#! Make the following a logged error instead of bailing out of the stage.
# raise ValueError(
Expand All @@ -74,7 +77,19 @@ def _process_chunk(self, start, end, estimate_data, reference_data, first):
continue

this_metric = self._metric_dict[metric](**self.config.to_dict())
out_table[metric] = this_metric.evaluate(estimate_data, reference_data[self.config.reference_dictionary_key])

if this_metric.metric_output_type == MetricOutputType.single_value:
print(f"We can't calculate a value for {this_metric.metric_name} right now.")
continue

if this_metric.metric_output_type == MetricOutputType.single_distribution:
print(f"We can't calculate a value for {this_metric.metric_name} right now.")
continue

out_table[metric] = this_metric.evaluate(
estimate_data,
reference_data[self.config.reference_dictionary_key]
)

out_table_to_write = {key: np.array(val).astype(float) for key, val in out_table.items()}

Expand Down
11 changes: 10 additions & 1 deletion src/rail/evaluation/testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"source": [
"ensemble = DS.read_file(key='pdfs_data', handle_class=QPHandle, path=pdfs_file)\n",
"ztrue_data = DS.read_file('ztrue_data', TableHandle, ztrue_file)\n",
"truth = DS.add_data('truth', ztrue_data()['photometry'], TableHandle, path=ztrue_file)\n"
"truth = DS.add_data('truth', ztrue_data()['photometry'], TableHandle, path=ztrue_file)\n",
"truth_points = DS.add_data('truth_points', ztrue_data()['photometry']['redshift'], TableHandle, path=ztrue_file)"
]
},
{
Expand Down Expand Up @@ -159,6 +160,7 @@
"stage_dict = dict(\n",
" metrics=['point_stats_ez'],\n",
" _random_state=None,\n",
" hdf5_groupname='redshift',\n",
")\n",
"ptp_stage = PointToPointEvaluator.make_stage(name='SillyPoopfish', **stage_dict)"
]
Expand All @@ -171,6 +173,13 @@
"source": [
"ptp_results = ptp_stage.evaluate(truth, truth)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit df3bf80

Please sign in to comment.