Ejemplo n.º 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)]

    from smooth_continuum import get_smooth_continuum
    s2_list = [get_smooth_continuum(s) 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, s2, ax in zip(mean_order_specs, s2_list, ax_list):
        ax.plot(x, s2)
        #check_order_trace2(ax, x, p)

    return fig_list
Ejemplo n.º 2
0
def check_order_flat(order_flat_json):

    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_json["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)]

    from smooth_continuum import get_smooth_continuum
    s2_list = [get_smooth_continuum(s) 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, s2, ax in zip(mean_order_specs, s2_list, ax_list):
        ax.plot(x, s2)
        #check_order_trace2(ax, x, p)

    return fig_list
Ejemplo n.º 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][0].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:
        # if slices[o-1] is None:
        #     continue
        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)]
    from smooth_continuum import get_smooth_continuum
    s2_list = [get_smooth_continuum(s) for s, (i1, i2) \
               in zip(s_list, i1i2_list)]


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

    fitted_responses = []

    for o, px in zip(orders, s2_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

        d_div = d_sl / px
        px2d = px * np.ones_like(d_div) # better way to broadcast px?
        d_div[px2d < 0.05*px.max()] = 1.
        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, PipelineImageBase([], 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
Ejemplo n.º 4
0
def make_order_flat(flat_normed, flat_mask, orders, order_map):

    # from storage_descriptions import (FLAT_NORMED_DESC,
    #                                   FLAT_MASK_DESC)

    # flat_normed  = flaton_products[FLAT_NORMED_DESC][0].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:
        # if slices[o-1] is None:
        #     continue
        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)]
    from smooth_continuum import get_smooth_continuum
    s2_list = [get_smooth_continuum(s) for s, (i1, i2) \
               in zip(s_list, i1i2_list)]

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

    fitted_responses = []

    for o, px in zip(orders, s2_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

        d_div = d_sl / px
        px2d = px * np.ones_like(d_div)  # better way to broadcast px?
        d_div[px2d < 0.05 * px.max()] = 1.
        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, PipelineImageBase([], 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))

    order_flat_dict = dict(orders=orders,
                           fitted_responses=fitted_responses,
                           i1i2_list=i1i2_list,
                           mean_order_specs=mean_order_specs)

    return flat_im, order_flat_dict