diff --git a/wetb/prepost/h2_vs_hs2.py b/wetb/prepost/h2_vs_hs2.py index 5f69fcaced878660ce6177333171c071446d5338..72996d2f885b6819a9dbf3181ea0b6e550609c23 100644 --- a/wetb/prepost/h2_vs_hs2.py +++ b/wetb/prepost/h2_vs_hs2.py @@ -727,7 +727,7 @@ class MappingsH2HS2(object): msg = 'HAWC2 sensor type "%s" is missing, are they defined?' raise ValueError(msg % sensortype) sel.sort_values(['radius'], inplace=True) - tors_e_channels = sel.ch_name.tolist() + tors_e_channels = sel.unique_ch_name.tolist() # find the current case in the statistics DataFrame case = fname.replace('.htc', '') @@ -737,7 +737,7 @@ class MappingsH2HS2(object): # join the stats with the channel descriptions DataFrames, have the # same name on the joining column df_tors_e.set_index('channel', inplace=True) - sel.set_index('ch_name', inplace=True) + sel.set_index('unique_ch_name', inplace=True) # joining happens on the index, and for which the same channel has been # used: the unique HAWC2 channel naming scheme diff --git a/wetb/prepost/misc.py b/wetb/prepost/misc.py index b0bd74982c05a716bea95f61a6c49a122b8ef956..1d3b3aff9e6500720d06b3cc075db32f82c9b3bc 100644 --- a/wetb/prepost/misc.py +++ b/wetb/prepost/misc.py @@ -769,6 +769,13 @@ def check_df_dict(df_dict): """ Verify if the dictionary that needs to be transferred to a Pandas DataFrame makes sense + + Returns + ------- + + collens : dict + Dictionary with df_dict keys as keys, len(df_dict[key]) as column. + In other words: the length of each column (=rows) of the soon to be df. """ collens = {} for col, values in df_dict.items(): @@ -978,6 +985,20 @@ def histfit(hist, bin_edges, xnew): return shape_out, scale_out, pdf_fit +def hist_centers2edges(centers): + """Given the centers of bins, return its edges and bin widths. + """ + + binw_c = centers[1:] - centers[:-1] + edges = np.ndarray((len(centers)+1,)) + edges[0] = centers[0] - binw_c[0]/2.0 + edges[-1] = centers[-1] + binw_c[-1]/2.0 + edges[1:-1] = centers[1:] - binw_c/2.0 + binw_e = edges[1:] - edges[:-1] + + return edges, binw_e + + def df_dict_check_datatypes(df_dict): """ there might be a mix of strings and numbers now, see if we can have