Ejemplo n.º 1
0
def extent_density_3d(x0, y0, z0, dx, dy, dz, target, flash_id_key='flash_id', weight_key=None):
    """ This function assumes a regular grid in x and y with spacing dx, dy
        
        x0, y0 is the x coordinate of the lower left corner of the lower-left grid cell, 
        i.e., the lower left node of the grid mesh in cartesian space
        
        Eliminates duplicate points in gridded space and sends the reduced
        set of points to the target.
    """
    while True:
        # assumes x,y,z are in same order as events
        events, flash, x,y,z = (yield)
        # print('Doing extent density',)
        x_i = np.floor( (x-x0)/dx ).astype('int32')
        y_i = np.floor( (y-y0)/dy ).astype('int32')
        z_i = np.floor( (z-z0)/dz ).astype('int32')
        print(len(x_i))
        if len(x_i) > 0:
            print('extent with points numbering', len(x_i), ' with weights', weight_key)
            unq_idx = unique_vectors(x_i, y_i, z_i, events[flash_id_key])
            # if x[unq_idx].shape[0] > 1:
            if weight_key <> None:
                weight_lookup = dict(list(zip(flash[flash_id_key], flash[weight_key])))
                weights = [weight_lookup[fi] for fi in events[unq_idx]['flash_id']] #puts weights in same order as x[unq_idx], y[unq_idx]
                del weight_lookup
            else:
                weights = None
            target.send((x[unq_idx], y[unq_idx], z[unq_idx], weights)) 
            del weights, unq_idx
        # else:
            # print ''
        del events, flash, x, y, z, x_i, y_i, z_i
Ejemplo n.º 2
0
def extent_density_3d(x0,
                      y0,
                      z0,
                      dx,
                      dy,
                      dz,
                      target,
                      flash_id_key='flash_id',
                      weight_key=None):
    """ This function assumes a regular grid in x and y with spacing dx, dy
        
        x0, y0 is the x coordinate of the lower left corner of the lower-left grid cell, 
        i.e., the lower left node of the grid mesh in cartesian space
        
        Eliminates duplicate points in gridded space and sends the reduced
        set of points to the target.
    """
    while True:
        # assumes x,y,z are in same order as events
        events, flash, x, y, z = (yield)
        # print('Doing extent density',)
        x_i = np.floor((x - x0) / dx).astype('int32')
        y_i = np.floor((y - y0) / dy).astype('int32')
        z_i = np.floor((z - z0) / dz).astype('int32')
        log.debug(len(x_i))
        if len(x_i) > 0:
            log.info(('extent with points numbering', len(x_i),
                      ' with weights', weight_key))
            unq_idx = unique_vectors(x_i, y_i, z_i, events[flash_id_key])
            # if x[unq_idx].shape[0] > 1:
            if weight_key != None:
                weight_lookup = dict(
                    list(zip(flash[flash_id_key], flash[weight_key])))
                weights = [
                    weight_lookup[fi] for fi in events[unq_idx]['flash_id']
                ]  #puts weights in same order as x[unq_idx], y[unq_idx]
                del weight_lookup
            else:
                weights = None
            target.send((x[unq_idx], y[unq_idx], z[unq_idx], weights))
            del weights, unq_idx
        # else:
        # print ''
        del events, flash, x, y, z, x_i, y_i, z_i
Ejemplo n.º 3
0
def footprint_mean_3d(flash_id_key='flash_id', area_key='area'):
    """ Takes x, y, z flash locations and gets 
        Extent density unique pixels, average all flashes 
    """
    while True:
        events, flash, x,y,z = (yield)
        # print 'Doing extent density',
        x_i = np.floor( (x-x0)/dx ).astype('int32')
        y_i = np.floor( (y-y0)/dy ).astype('int32')
        z_i = np.floor( (z-z0)/dz ).astype('int32')
        if len(x_i) > 0:
            footprints = dict(list(zip(flash[flash_id_key], flash[area_key])))
            # print 'with points numbering', len(x_i)
            unq_idx = unique_vectors(x_i, y_i, z_i, events['flash_id'])
            # if x[unq_idx].shape[0] > 1:
            fl_id = events['flash_id'][unq_idx]
            areas = [footprints[fi] for fi in fl_id] #puts areas in same order as x[unq_idx], y[unq_idx]
            # counts normalized by areas 
            target.send((x[unq_idx],y[unq_idx],z[unq_idx],areas))
            del footprints, unq_idx, fl_id, areas
        # else:
            # print ''
        del events, flash, x, y, z, x_i, y_i, z_i
Ejemplo n.º 4
0
def footprint_mean_3d(flash_id_key='flash_id', area_key='area'):
    """ Takes x, y, z flash locations and gets 
        Extent density unique pixels, average all flashes 
    """
    while True:
        events, flash, x, y, z = (yield)
        # print 'Doing extent density',
        x_i = np.floor((x - x0) / dx).astype('int32')
        y_i = np.floor((y - y0) / dy).astype('int32')
        z_i = np.floor((z - z0) / dz).astype('int32')
        if len(x_i) > 0:
            footprints = dict(list(zip(flash[flash_id_key], flash[area_key])))
            # print 'with points numbering', len(x_i)
            unq_idx = unique_vectors(x_i, y_i, z_i, events['flash_id'])
            # if x[unq_idx].shape[0] > 1:
            fl_id = events['flash_id'][unq_idx]
            areas = [footprints[fi] for fi in fl_id
                     ]  #puts areas in same order as x[unq_idx], y[unq_idx]
            # counts normalized by areas
            target.send((x[unq_idx], y[unq_idx], z[unq_idx], areas))
            del footprints, unq_idx, fl_id, areas
        # else:
        # print ''
        del events, flash, x, y, z, x_i, y_i, z_i
Ejemplo n.º 5
0
def extent_density(x0,
                   y0,
                   dx,
                   dy,
                   target,
                   flash_id_key='flash_id',
                   weight_key=None,
                   event_grid_area_fraction_key=None):
    """ This function assumes a regular grid in x and y with spacing dx, dy
        
        x0, y0 is the x coordinate of the lower left corner of the lower-left grid cell, 
        i.e., the lower left node of the grid mesh in cartesian space
        
        Eliminates duplicate points in gridded space and sends the reduced
        set of points to the target.
    """
    while True:
        # assumes x,y,z are in same order as events
        events, flash, x, y, z = (yield)
        # print 'Doing extent density',
        x_i = np.floor((x - x0) / dx).astype('int32')
        y_i = np.floor((y - y0) / dy).astype('int32')
        test_flash_id = 53735
        if len(x_i) > 0:
            log.info(('extent with points numbering', len(x_i),
                      ' with weights', weight_key))
            unq_idx = unique_vectors(x_i, y_i, events[flash_id_key])
            # if x[unq_idx].shape[0] > 1:
            if weight_key != None:
                weight_lookup = dict(
                    list(zip(flash[flash_id_key], flash[weight_key])))
                #puts weights in same order as x[unq_idx], y[unq_idx]
                weights = np.fromiter(
                    (weight_lookup[fi] for fi in events[unq_idx]['flash_id']),
                    dtype='float64')
                # del weight_lookup
            else:
                weights = None
            if event_grid_area_fraction_key is not None:
                # Each event with a unique index is replicated above
                # with the representative value for the flash (weights = None
                # implies a weight of +1 for each flash). If there is knowledge
                # of how much of the underlying grid cell each event fills
                # (e.g. from pixel-based event detector), then we can modify
                # the weights by how much of the grid cell is filled.
                # The logic here presumes that any of the events in the grid
                # cell cover as much area as any other, i.e., that the pixels
                # doing the event detection don't move during the time of the
                # flash.
                grid_frac = events[unq_idx][event_grid_area_fraction_key]
            else:
                grid_frac = None

            # Diagnostics
            # test_flash_mask = (events['flash_id'] == test_flash_id)
            # test_events = events[test_flash_mask]
            # if (test_flash_mask.sum() > 0) & (weight_key == 'area'):
            #     print("Data for flash {0}".format(test_flash_id))
            #     mesh_xi = test_events['mesh_xi']
            #     mesh_yi = test_events['mesh_yi']
            #     mesh_frac = test_events['mesh_frac']
            #     mesh_t = test_events['time']
            #     for vals in zip(mesh_t, mesh_frac,
            #                     mesh_xi, x_i[test_flash_mask],
            #                     mesh_yi, y_i[test_flash_mask],
            #                     ):
            #         print(vals, weight_lookup[test_flash_id])
            #
            # test_flash_mask = (events[unq_idx]['flash_id'] == test_flash_id)
            # test_events = events[unq_idx][test_flash_mask]
            # if (test_flash_mask.sum() > 0) & (weight_key == 'area'):
            #     print("Unique data for flash {0}".format(test_flash_id))
            #     mesh_xi = test_events['mesh_xi']
            #     mesh_yi = test_events['mesh_yi']
            #     mesh_frac = test_events['mesh_frac']
            #     mesh_t = test_events['time']
            #     for vals in zip(mesh_t, mesh_frac,
            #                     mesh_xi, x_i[unq_idx][test_flash_mask],
            #                     mesh_yi, y_i[unq_idx][test_flash_mask],
            #                     weights[test_flash_mask]):
            #         print(vals, weight_lookup[test_flash_id])

            target.send((x[unq_idx], y[unq_idx], weights, grid_frac))
            del weights, grid_frac, unq_idx
        # else:
        # print ''
        del events, flash, x, y, z, x_i, y_i