Esempio n. 1
0
def extract_info(infiles):

    headers = []

    update_rate = 1. * len(infiles) / Bar.setup()
    for ix, file in enumerate(infiles):
        if ix % update_rate == 0: Bar.update()
        FF = pf.open(file)
        FF[0].header['filename'] = file
        if 'JD' not in FF[0].header:
            #print "Skipping %s" % file
            continue
        headers.append(FF[0].header)

    Bar.done()

    return sorted(headers, key=lambda x: x['JD'])
Esempio n. 2
0
def extract_info(infiles):
    

    headers = []

    update_rate = 1. * len(infiles) / Bar.setup()
    for ix, file in enumerate(infiles):
        if ix % update_rate == 0: Bar.update()
        FF = pf.open(file )
        FF[0].header['filename'] = file
        if 'JD' not in FF[0].header:
            #print "Skipping %s" % file
            continue
        headers.append(FF[0].header)
    
    Bar.done()
    
    return sorted(headers, key=lambda x: x['JD'])
Esempio n. 3
0
def find_segments(segmap=None, obj=None, order=2):
    """Find the segments in obj by tracing ridgelines identified in 
    the segmentation map.

    Args:
        segmap ([int,int]): Segmentation map image, first segment is
                1 .. max(segmap)
        obj ([float,float]): Image data to trace over
        order (int): The order of the polynomial used in coeff_ys

    Returns:
        list of dict: Returns a list with length equal to
        the max(segmap) segmentation map Dictionaries containing::

            {   "seg_cnt": Segment ID number,
                "xs": List of x positions of trace,
                "mean_ys": Measured Y position (average) of the trace,
                "coeff_ys": polyfit coefficients to the mean_ys,
                "trace_sigma": Width of trace in pixels (1 sigma),
                "ok": Trace has more than 50 pixels     }
        
    """
    global segdat, objdat, polyorder, n_done, update_rate

    segdat = segmap[0].data
    objdat = obj[0].data
    polyorder = order

    # First segment begins at 1
    segrange = range(1, max(segdat.flatten())+1)

    n_done = 0
    update_rate = int(len(segrange) / Bar.setup(toolbar_width=74)) + 1
    p = Pool(8)
    traces = p.map(find_segments_helper, segrange)
    p.close()
    Bar.done(mapped=True)
    # print("")

    return traces
Esempio n. 4
0
def extract_info(infiles):

    headers = []

    print("-- Plan2.py: Ingesting headers --")
    update_rate = int(len(infiles) / (Bar.setup() - 1))
    if update_rate <= 0:
        update_rate = 1
    for ix, ifile in enumerate(infiles):
        if ix % update_rate == 0:
            Bar.update()
        FF = pf.open(ifile)
        FF[0].header['filename'] = ifile
        if 'JD' not in FF[0].header:
            # print("Skipping %s" % ifile)
            continue
        headers.append(FF[0].header)
        FF.close()

    Bar.done()

    return sorted(headers, key=lambda x: x['JD'])
Esempio n. 5
0
File: Plan.py Progetto: scizen9/kpy
def extract_info(infiles):

    headers = []

    print "-- Ingesting headers --"
    update_rate = len(infiles) / (Bar.setup() - 1)
    if update_rate <= 0:
        update_rate = 1
    for ix, ifile in enumerate(infiles):
        if ix % update_rate == 0:
            Bar.update()
        FF = pf.open(ifile)
        FF[0].header['filename'] = ifile
        if 'JD' not in FF[0].header:
            # print "Skipping %s" % ifile
            continue
        headers.append(FF[0].header)
        FF.close()

    Bar.done()

    return sorted(headers, key=lambda x: x['JD'])
Esempio n. 6
0
def find_segments_helper(seg_cnt):
    """Trace a single spaxel segment and return the solution

    Args:
        seg_cnt (int): the segment number

    Returns:
        dict: Returns a segmentation map Dictionary
        containing::

            {   "seg_cnt": Segment ID number,
                "xs": List of x positions of trace,
                "mean_ys": Measured Y position (average) of the trace,
                "coeff_ys": polyfit coefficients to the mean_ys,
                "trace_sigma": Width of trace in pixels (1 sigma),
                "ok": Trace has more than 50 pixels     }

    """
    # Global is for inter process communication
    global segdat, objdat, polyorder, n_done, update_rate

    n_done += 1
    if n_done % update_rate == 0:
        Bar.update()

    # Padding in pixels around trace in Y
    PAD = 2

    # Get this segment
    the_seg = (segdat == seg_cnt)

    # Test for tiny segment
    test = the_seg.nonzero()
    # trace data
    tr = {
        "seg_cnt": seg_cnt,
        "xs": np.array(np.nan),
        "mean_ys": np.array(np.nan),
        "coeff_ys": np.array(np.nan),
        "trace_sigma": np.array(np.nan),
        "ok": False,
        "bkg_ok": False
    }
    if len(test[0]) < 10 or len(test[1]) < 10:
        outstr = '\r%4.4i: %4.4i, TINY SEGMENT, %-5s' % (seg_cnt, len(test[0]),
                                                         tr['ok'])
        print(outstr)
        sys.stdout.flush()
    # We are OK
    else:
        # Get segment's geometry
        span = spanrange(the_seg)
        mnsr = np.max((span[0].y - PAD, 0))
        mxsr = np.min((span[1].y + PAD, segdat.shape[1] - 1))
        y_slc = slice(mnsr, mxsr)
        # y_off = (span[0].y + span[1].y) / 2.0

        # How long is it in X?
        n_el = span[1].x - span[0].x

        # How wide is it in Y?
        n_wd = span[1].y - span[0].y

        # Don't fit short traces, but flag them by setting "ok" to False
        if n_el < 50 or n_wd < 3:

            # Flag the sigma with zero
            sig = 0.
            tr["trace_sigma"] = sig

        # Trace is long enough and wide enough, so let's fit it!
        else:

            means = np.zeros(n_el)
            trace_profile = np.zeros(mxsr - mnsr)

            for i in range(n_el):
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore", category=RuntimeWarning)
                    XX = i + span[0].x
                    profile = np.nanmedian(objdat[y_slc, XX - 3:XX + 3], 1)
                    profile -= np.min(profile)

                    trace_profile += profile

                    xs = np.arange(len(profile)) + span[0].y

                    means[i] = np.sum(xs * profile) / np.sum(profile) - PAD

            xs = np.arange(n_el) + span[0].x

            nans = ~np.isfinite(means)
            ok = np.isfinite(means)

            if np.count_nonzero(nans) < 5:
                poly = np.array(np.polyfit(xs[ok], means[ok], polyorder))
            else:
                poly = np.array(np.nan)

            trace_fit = gfit1d(trace_profile,
                               par=[0, len(trace_profile) / 2., 1.7], quiet=1)
            sig = np.abs(trace_fit.params[2])

            tr["xs"] = np.array(xs[ok])
            tr["mean_ys"] = np.array(means[ok])
            tr["coeff_ys"] = poly
            tr["trace_sigma"] = sig
            tr["bkg_ok"] = True
            tr["ok"] = (np.count_nonzero(nans) <= 0 & np.isfinite(poly[0]))

        # outstr = '\r%4.4i: %4.4i, fwhm=%3.2f pix, %-5s' % (seg_cnt, n_el,
        #                                                    sig * 2.355,
        #                                                    tr['ok'])
        # print(outstr, end="")
        # sys.stdout.flush()

    return tr