예제 #1
0
def test_from_chips():
    chips = list()
    chips.append({'data': np.int_([[11, 12, 13], [14, 15, 16], [17, 18, 19]])})
    chips.append({'data': np.int_([[21, 22, 23], [24, 25, 26], [27, 28, 29]])})
    chips.append({'data': np.int_([[31, 32, 33], [34, 35, 36], [37, 38, 39]])})
    pillar = rods.from_chips(chips)
    assert pillar.shape[0] == chips[0]['data'].shape[0]
    assert pillar.shape[1] == chips[0]['data'].shape[1]
    assert pillar.shape[2] == len(chips)

    # going to flatten both the chips arrays and the pillar array
    # then perform black magic and verify that the values wound up
    # where they belonged in the array positions.
    # using old style imperative code as double insurance
    # happiness is not doing this and relying on functional principles only
    # because direct manipulation of memory locations is error prone and
    # very difficult to think about.
    # We're mapping array locations between two things that look like this:
    # [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ...]
    # [11, 21, 31, 12, 22, 32, 13, 23, 33, 14, 24, 34, 15, 25, 35, 16, 26 ...]
    # This alone should serve as all the evidence needed to prove that
    # imperative programming is bad for everyone involved.  I am very sorry.
    fchips = list(f.flatten([c['data'].flatten() for c in chips]))
    jump = reduce(lambda accum, v: accum + v, pillar.shape)  # 9
    modulus = pillar.shape[0]  # 3
    for i, val in enumerate(pillar.flatten()):
        factor = i % modulus  # 0 1 2
        group = i // modulus  # 0 1 2
        assert val == fchips[(factor * jump) + group]
def detection(ctx, cfg):

    with workers(cfg) as w:
        if get('test_detection_exception', ctx, None) is not None:
            return merge(ctx, exception(msg='test_detection_exception', http_status=500))
        else:
            return merge(ctx, {'detections': list(flatten(w.map(detect, take(ctx['test_pixel_count'], ctx['timeseries']))))})
예제 #3
0
def data(ctx, cfg):
    '''Retrieve training data for all chips in parallel'''
    
    p = partial(pipeline,
                tx=ctx['tx'],
                ty=ctx['ty'],
                date=ctx['date'],
                acquired=ctx['acquired'],
                cfg=cfg)

    with workers(cfg) as w:
        return assoc(ctx, 'data', numpy.array(list(flatten(w.map(p, ctx['chips']))), dtype=numpy.float32))
def _bounds(b):
    """Checks bounds as supplied by cmdline

    Args:
        b (tuple): ('123,456', '222,333')

    Returns:
        bool: True or Exception
    """

    if (len(b) > 0 and all(map(lambda x: x.find(',') != -1, b)) and all(
            map(lambda x: functions.isnumeric(x),
                functions.flatten(map(lambda i: i.split(','), b))))):
        return True
    raise Exception("Invalid bounds specified:".format(b))
예제 #5
0
def pyccd(x, y, locations, dates_fn, specmap, chipmap):
    """Builds inputs for the pyccd algorithm.

    Args:
        x: x projection coordinate of chip
        y: y projection coordinate of chip
        locations: chip shaped 2d array of projection coordinates
        dates_fn (fn): returns dates that should be included in time series
        specmap (dict): mapping of keys to specs
        chipmap (dict): mapping of keys to chips

    Returns:
        A tuple of tuples.

    The pyccd format key is ```(chip_x, chip_y, x, y)``` with a
    dictionary of sorted numpy arrays representing each spectra plus an
    additional sorted dates array.

    >>> pyccd_format(*args)
        (((chip_x, chip_y, x1, y1), {"dates":  [],  "reds": [],
                                     "greens": [],  "blues": [],
                                     "nirs1":  [],  "swir1s": [],
                                     "swir2s": [],  "thermals": [],
                                     "qas":    []}),
         ((chip_x, chip_y, x1, y2), {"dates":  [],  "reds": [],
                                     "greens": [],  "blues": [],
                                     "nirs1":  [],  "swir1s": [],
                                     "swir2s": [],  "thermals": [],
                                     "qas":    []}))
        ...
    """
    
    _index   = specs.index(list(functions.flatten(specmap.values())))
    _dates   = dates_fn(datemap=dates.mapped(chipmap))
    _creator = partial(rods.create, x=x, y=y, dateseq=_dates, locations=locations, spec_index=_index)
    _flipped = partial(functions.flip_keys, {k: _creator(chipseq=v) for k, v in chipmap.items()})
    
    _rods = functions.insert_into_every(key='dates',
                                        value=list(map(dates.to_ordinal, dates.rsort(_dates))),
                                        dods=_flipped())
                                 
    return tuple((k, v) for k, v in _rods.items())
예제 #6
0
def standard_format(segmap):
    return list(
        flatten([
            get('nlcdtrn', segmap),
            get('aspect', segmap),
            get('posidex', segmap),
            get('slope', segmap),
            get('mpw', segmap),
            get('dem', segmap),
            get('blcoef', segmap), [get('blrmse', segmap)],
            [get('blar', segmap)],
            get('grcoef', segmap), [get('grrmse', segmap)],
            [get('grar', segmap)],
            get('nicoef', segmap), [get('nirmse', segmap)],
            [get('niar', segmap)],
            get('recoef', segmap), [get('rermse', segmap)],
            [get('rear', segmap)],
            get('s1coef', segmap), [get('s1rmse', segmap)],
            [get('s1ar', segmap)],
            get('s2coef', segmap), [get('s2rmse', segmap)],
            [get('s2ar', segmap)],
            get('thcoef', segmap), [get('thrmse', segmap)],
            [get('thar', segmap)]
        ]))
예제 #7
0
def test_flatten():
    result = [1, 2, 3, 4, 5, [6, 7]]
    assert list(f.flatten([[1, 2], [3, 4], [5, [6, 7]]])) == result