From 88b17dc99040f722c1886b55dc970cfb8bb321a3 Mon Sep 17 00:00:00 2001 From: Mark Nestor Costantini Date: Mon, 12 Jun 2023 17:55:51 +0100 Subject: [PATCH 1/4] fix bug due to pd.groupby alphabetical ordering --- validphys2/src/validphys/pseudodata.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index f5d6fb0389..20f8588ae6 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -369,15 +369,21 @@ def make_level1_data(data, level0_commondata_wc, filterseed, experiments_index, indexed_level1_data = indexed_make_replica(experiments_index, level1_data) + dataset_order = [cd.setname for cd in level0_commondata_wc] + # ===== create commondata instances with central values given by pseudo_data =====# level1_commondata_dict = {c.setname: c for c in level0_commondata_wc} level1_commondata_instances_wc = [] + # note that groupby sorts alphabetically for xx, grp in indexed_level1_data.groupby('dataset'): level1_commondata_instances_wc.append( level1_commondata_dict[xx].with_central_value(grp.values) ) - + # sort back so as to mantain same order as in level0_commondata_wc + level1_commondata_instances_wc = sorted( + level1_commondata_instances_wc, key=lambda obj: dataset_order.index(obj.setname) + ) return level1_commondata_instances_wc From e868a239168a7d980fbd54d3d2a37c212f91485e Mon Sep 17 00:00:00 2001 From: Mark Nestor Costantini Date: Thu, 22 Jun 2023 09:33:41 +0100 Subject: [PATCH 2/4] ordering done with dictionary --- validphys2/src/validphys/pseudodata.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index 20f8588ae6..847df753cf 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -369,7 +369,7 @@ def make_level1_data(data, level0_commondata_wc, filterseed, experiments_index, indexed_level1_data = indexed_make_replica(experiments_index, level1_data) - dataset_order = [cd.setname for cd in level0_commondata_wc] + dataset_order = {cd.setname: i for i, cd in enumerate(level0_commondata_wc)} # ===== create commondata instances with central values given by pseudo_data =====# level1_commondata_dict = {c.setname: c for c in level0_commondata_wc} @@ -381,9 +381,8 @@ def make_level1_data(data, level0_commondata_wc, filterseed, experiments_index, level1_commondata_dict[xx].with_central_value(grp.values) ) # sort back so as to mantain same order as in level0_commondata_wc - level1_commondata_instances_wc = sorted( - level1_commondata_instances_wc, key=lambda obj: dataset_order.index(obj.setname) - ) + level1_commondata_instances_wc.sort(key=lambda x: dataset_order[x.setname]) + return level1_commondata_instances_wc From f266993c8816a76afe6a2a72a302461375e76558 Mon Sep 17 00:00:00 2001 From: Mark Nestor Costantini Date: Mon, 26 Jun 2023 20:44:12 +0100 Subject: [PATCH 3/4] fixed bug in make level1 data due to experiments_index --- validphys2/src/validphys/pseudodata.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index 851fc6fc95..00524114ea 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -371,8 +371,6 @@ def make_level1_data(data, level0_commondata_wc, filterseed, data_index, sep_mul dataset_order = {cd.setname: i for i, cd in enumerate(level0_commondata_wc)} - dataset_order = {cd.setname: i for i, cd in enumerate(level0_commondata_wc)} - # ===== create commondata instances with central values given by pseudo_data =====# level1_commondata_dict = {c.setname: c for c in level0_commondata_wc} level1_commondata_instances_wc = [] From c538371a69b975ca26ea37fd85f470a0b9a9b39d Mon Sep 17 00:00:00 2001 From: Mark Nestor Costantini Date: Mon, 26 Jun 2023 20:50:41 +0100 Subject: [PATCH 4/4] black for formatting --- validphys2/src/validphys/pseudodata.py | 4 ++-- validphys2/src/validphys/results.py | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index 00524114ea..1fd0a5233d 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -369,7 +369,7 @@ def make_level1_data(data, level0_commondata_wc, filterseed, data_index, sep_mul indexed_level1_data = indexed_make_replica(data_index, level1_data) - dataset_order = {cd.setname: i for i, cd in enumerate(level0_commondata_wc)} + dataset_order = {cd.setname: i for i, cd in enumerate(level0_commondata_wc)} # ===== create commondata instances with central values given by pseudo_data =====# level1_commondata_dict = {c.setname: c for c in level0_commondata_wc} @@ -382,7 +382,7 @@ def make_level1_data(data, level0_commondata_wc, filterseed, data_index, sep_mul ) # sort back so as to mantain same order as in level0_commondata_wc level1_commondata_instances_wc.sort(key=lambda x: dataset_order[x.setname]) - + return level1_commondata_instances_wc diff --git a/validphys2/src/validphys/results.py b/validphys2/src/validphys/results.py index 629c04b988..e5a23c9dd4 100644 --- a/validphys2/src/validphys/results.py +++ b/validphys2/src/validphys/results.py @@ -156,11 +156,11 @@ def data_index(data): """ Given a core.DataGroupSpec instance, return pd.MultiIndex with the following levels: - + 1. experiment 2. datasets 3. datapoints indices (cuts already applied to) - + Parameters ---------- @@ -173,9 +173,7 @@ def data_index(data): """ tuples = [] - for ds in data.datasets: - experiment = get_info(ds).experiment for i in ds.cuts.load():