Beispiel #1
0
def check_order_flat(order_flat_products):

    from trace_flat import (prepare_order_trace_plot,
                            check_order_trace1, check_order_trace2)

    from storage_descriptions import ORDER_FLAT_JSON_DESC

    mean_order_specs = order_flat_products[ORDER_FLAT_JSON_DESC]["mean_order_specs"]

    from trace_flat import (get_smoothed_order_spec,
                            get_order_boundary_indices,
                            get_order_flat1d)

    # these are duplicated from make_order_flat
    s_list = [get_smoothed_order_spec(s) for s in mean_order_specs]
    i1i2_list = [get_order_boundary_indices(s, s0) \
                 for s, s0 in zip(mean_order_specs, s_list)]
    p_list = [get_order_flat1d(s, i1, i2) for s, (i1, i2) \
              in zip(s_list, i1i2_list)]

    fig_list, ax_list = prepare_order_trace_plot(s_list)
    x = np.arange(2048)
    for s, i1i2, ax in zip(mean_order_specs, i1i2_list, ax_list):
        check_order_trace1(ax, x, s, i1i2)

    for s, p, ax in zip(mean_order_specs, p_list, ax_list):
        check_order_trace2(ax, x, p)

    return fig_list
Beispiel #2
0
def check_order_flat(order_flat_products):

    from trace_flat import (prepare_order_trace_plot, check_order_trace1,
                            check_order_trace2)

    from storage_descriptions import ORDER_FLAT_JSON_DESC

    mean_order_specs = order_flat_products[ORDER_FLAT_JSON_DESC][
        "mean_order_specs"]

    from trace_flat import (get_smoothed_order_spec,
                            get_order_boundary_indices, get_order_flat1d)

    # these are duplicated from make_order_flat
    s_list = [get_smoothed_order_spec(s) for s in mean_order_specs]
    i1i2_list = [get_order_boundary_indices(s, s0) \
                 for s, s0 in zip(mean_order_specs, s_list)]
    p_list = [get_order_flat1d(s, i1, i2) for s, (i1, i2) \
              in zip(s_list, i1i2_list)]

    fig_list, ax_list = prepare_order_trace_plot(s_list)
    x = np.arange(2048)
    for s, i1i2, ax in zip(mean_order_specs, i1i2_list, ax_list):
        check_order_trace1(ax, x, s, i1i2)

    for s, p, ax in zip(mean_order_specs, p_list, ax_list):
        check_order_trace2(ax, x, p)

    return fig_list
Beispiel #3
0
def make_order_flat(flaton_products, orders, order_map):

    from storage_descriptions import (FLAT_NORMED_DESC,
                                      FLAT_MASK_DESC)

    flat_normed  = flaton_products[FLAT_NORMED_DESC].data
    flat_mask = flaton_products[FLAT_MASK_DESC].data

    import scipy.ndimage as ni
    slices = ni.find_objects(order_map)

    mean_order_specs = []
    mask_list = []
    for o in orders:
        sl = (slices[o-1][0], slice(0, 2048))
        d_sl = flat_normed[sl].copy()
        d_sl[order_map[sl] != o] = np.nan

        f_sl = flat_mask[sl].copy()
        f_sl[order_map[sl] != o] = np.nan
        ff = np.nanmean(f_sl, axis=0)
        mask_list.append(ff)

        mmm = order_map[sl] == o
        ss = [np.nanmean(d_sl[2:-2][:,i][mmm[:,i][2:-2]]) \
              for i in range(2048)]
        mean_order_specs.append(ss)


    from trace_flat import (get_smoothed_order_spec,
                            get_order_boundary_indices,
                            get_order_flat1d)

    s_list = [get_smoothed_order_spec(s) for s in mean_order_specs]
    i1i2_list = [get_order_boundary_indices(s, s0) \
                 for s, s0 in zip(mean_order_specs, s_list)]
    p_list = [get_order_flat1d(s, i1, i2) for s, (i1, i2) \
              in zip(s_list, i1i2_list)]

    # make flat
    x = np.arange(len(s))
    flat_im = np.empty(flat_normed.shape, "d")
    flat_im.fill(np.nan)

    fitted_responses = []

    for o, p in zip(orders, p_list):
        sl = (slices[o-1][0], slice(0, 2048))
        d_sl = flat_normed[sl].copy()
        msk = (order_map[sl] == o)
        d_sl[~msk] = np.nan

        px = p(x)
        flat_im[sl][msk] = (d_sl / px)[msk]
        fitted_responses.append(px)

    flat_im[flat_im < 0.5] = np.nan


    from storage_descriptions import (ORDER_FLAT_IM_DESC,
                                      ORDER_FLAT_JSON_DESC)

    r = PipelineProducts("order flat")
    r.add(ORDER_FLAT_IM_DESC, PipelineImage([], flat_im))
    r.add(ORDER_FLAT_JSON_DESC,
          PipelineDict(orders=orders,
                       fitted_responses=fitted_responses,
                       i1i2_list=i1i2_list,
                       mean_order_specs=mean_order_specs))

    return r
Beispiel #4
0
def make_order_flat(flaton_products, orders, order_map):

    from storage_descriptions import (FLAT_NORMED_DESC, FLAT_MASK_DESC)

    flat_normed = flaton_products[FLAT_NORMED_DESC].data
    flat_mask = flaton_products[FLAT_MASK_DESC].data

    import scipy.ndimage as ni
    slices = ni.find_objects(order_map)

    mean_order_specs = []
    mask_list = []
    for o in orders:
        sl = (slices[o - 1][0], slice(0, 2048))
        d_sl = flat_normed[sl].copy()
        d_sl[order_map[sl] != o] = np.nan

        f_sl = flat_mask[sl].copy()
        f_sl[order_map[sl] != o] = np.nan
        ff = np.nanmean(f_sl, axis=0)
        mask_list.append(ff)

        mmm = order_map[sl] == o
        ss = [np.nanmean(d_sl[2:-2][:,i][mmm[:,i][2:-2]]) \
              for i in range(2048)]
        mean_order_specs.append(ss)

    from trace_flat import (get_smoothed_order_spec,
                            get_order_boundary_indices, get_order_flat1d)

    s_list = [get_smoothed_order_spec(s) for s in mean_order_specs]
    i1i2_list = [get_order_boundary_indices(s, s0) \
                 for s, s0 in zip(mean_order_specs, s_list)]
    p_list = [get_order_flat1d(s, i1, i2) for s, (i1, i2) \
              in zip(s_list, i1i2_list)]

    # make flat
    x = np.arange(len(s))
    flat_im = np.empty(flat_normed.shape, "d")
    flat_im.fill(np.nan)

    fitted_responses = []

    for o, p in zip(orders, p_list):
        sl = (slices[o - 1][0], slice(0, 2048))
        d_sl = flat_normed[sl].copy()
        msk = (order_map[sl] == o)
        d_sl[~msk] = np.nan

        px = p(x)
        flat_im[sl][msk] = (d_sl / px)[msk]
        fitted_responses.append(px)

    flat_im[flat_im < 0.5] = np.nan

    from storage_descriptions import (ORDER_FLAT_IM_DESC, ORDER_FLAT_JSON_DESC)

    r = PipelineProducts("order flat")
    r.add(ORDER_FLAT_IM_DESC, PipelineImage([], flat_im))
    r.add(
        ORDER_FLAT_JSON_DESC,
        PipelineDict(orders=orders,
                     fitted_responses=fitted_responses,
                     i1i2_list=i1i2_list,
                     mean_order_specs=mean_order_specs))

    return r