Exemplo n.º 1
0
def setup_map_generator(database, aircrafts, lengthScales, variance,
                        noiseVariance, wind):

    # Object which is in charge of giving the wind to the gpr kernel.
    windServer = WindMapConstant('WindServer', wind)

    # Kernel to use in the gpr
    params = {}
    params['lengthScales'] = lengthScales
    params['variance'] = variance
    params['noiseVariance'] = noiseVariance

    shallowParams = {}  # this is because of sklean clone function
    shallowParams['windMap'] = windServer
    params['shallowParameters'] = DeepcopyGuard(**shallowParams)
    kernel = WindKernel(**params)

    # Objects in charge of fetch cloud sensor data and voltage data from the
    # database and giving to the gpr calibrated sensor data.
    cloudViews = []
    for aircraft, params in aircrafts.items():
        cloudViews.append(
            CloudSensorProcessing("Cloud data " + aircraft, database,
                                  [aircraft, "cloud_channel_0"],
                                  [aircraft, "energy"], params['alpha'],
                                  params['beta'], params['scaling']))
    # Aggregating the output of these view to a single one for the gpr
    cloudView = DataView("Cloud data", parents=cloudViews)

    # The object in charge of all gpr calculations.
    gpr = GprPredictor("Cloud Map estimator", cloudView, kernel)
    gpr.computeStd = True

    return gpr
Exemplo n.º 2
0
    def load_gpr_map(self, mapId, config):
        """
        load_gpr_map

        Loads a ValueMap from a yaml parsed configuration and add it to the
        self.maps attributes. Depending on the configuration, may also load a
        StdMap with the same GprPredictor.
        """

        if 'kernel' not in config.keys():
            warn("No kernel defined for GprMap '" + str(config['name']) +
                 "'. " + "Cannot instanciate this map.")
            return
        if config['kernel'] not in self.kernels.keys():
            warn("No kernel '" + config['kernel'] + " defined. " +
                 "Cannot instanciate '" + config['name'] + "' map.")
            return

        # gpr = GprPredictor(config['name'], self.database,
        #                 config['database_tags'],
        #                 self.kernels[config['kernel']])
        gpr = GprPredictor(config['name'], self.dataviews[config['data_view']],
                           self.kernels[config['kernel']])

        if 'threshold' in config.keys():
            gpr.threshold = config['threshold']

        if 'data_range' in config.keys():
            gpr.dataRange = (Bounds(config['data_range'][0],
                                    config['data_range'][1]), )
            gpr.updateRange = False

        self.maps[mapId] = ValueMap(config['name'], gpr)

        if 'std_map' in config.keys():
            # If std_map if defined in the config, creating a new StdMap with
            # the same GprPredictor as the above StdMap.
            if mapId + '_std' in self.maps.keys():
                warn("The map '" + mapId +
                     "_std' id is already defined. Cannot " + "instanciate '" +
                     config['std_map'] + "' map.")
            else:
                self.maps[mapId + '_std'] = StdMap(config['std_map'], gpr)

        if 'border_map' in config.keys():
            if mapId + '_border' in self.maps.keys():
                warn("The map '" + mapId +
                     "_std' id is already defined. Cannot " + "instanciate '" +
                     config['border_map'] + "' map.")
            else:
                if mapId + '_std' in self.maps.keys():
                    self.maps[mapId + '_border'] = BorderIncertitude(
                        config['border_map'], self.maps[mapId],
                        self.maps[mapId + '_std'])
                else:
                    self.maps[mapId + '_border'] = BorderRaw(
                        config['border_map'], self.maps[mapId])
Exemplo n.º 3
0
# dtbase = NephelaeDataServer()
# sys.stdout.flush()
# for pos,n in zip(p,noise):
#     dtbase.add_gps(Gps("100", Position(pos[0],pos[1],pos[2],pos[3])))
#     dtbase.add_sample(SensorSample('RCT', '100', pos[0],
#         Position(pos[0],pos[1],pos[2],pos[3]),
#         [rct[pos[0],pos[1],pos[2],pos[3] + n]]))
#     dtbase.add_sample(SensorSample('Wind', '100', pos[0],
#         Position(pos[0],pos[1],pos[2],pos[3]),
#         [ut[pos[0],pos[1],pos[2],pos[3]], vt[pos[0],pos[1],pos[2],pos[3]]]))
# dtbase.save(dtfile, force=True)
dtbase = NephelaeDataServer.load(dtfile)
print("Done !")
sys.stdout.flush()

gprMap = GprPredictor('RCT', dtbase, ['RCT'], kernel0)

profiling = False
# profiling = True
if not profiling:
    fig, axes = plt.subplots(3, 1, sharex=True, sharey=True)
simTime = p0.t
lastTime = time.time()
simSpeed = 50.0

# interp='nearest'
interp = 'bicubic'


def do_update(t):
Exemplo n.º 4
0
database = NephelaeDataServer.load(databasePath)

mesonhDataset = MesonhDataset(mesonhPath)
rct = MesonhMap('Liquid water', mesonhDataset, 'RCT', interpolation='linear')

# Have to define wind by hand for now.
wind = np.array([8.5, 0.9])
windMap = WindMapConstant('Wind', wind)

# Kernel for liquid water content
processVariance = 1.0e-8
noiseStddev = 0.1 * np.sqrt(processVariance)
lengthScales = [70.0, 80.0, 80.0, 60.0]

rctKernel0 = WindKernel(lengthScales, processVariance, noiseStddev**2, windMap)
rctGpr = GprPredictor('RCT', database, ['RCT'], rctKernel0)

# coordinates of the map you want to generate/extract
t = 160.0
x = [12.5, 6387.5]
y = [1837.5, 2712.5]
z = 1100.0

# getting some mesonh data
mesonhSlice = rct[t, x[0]:x[1], y[0]:y[1], z].data
# predicting with gpr
gprSlice = rctGpr[t, x[0]:x[1], y[0]:y[1], z][0].data[:, :, 0]

# the GPR prediction resolution depends on the kernel length scale so it is not
# necessarily the same as the mesonh. Although they represent the same region
# of space, the array sizes might differ. If you want to compare mesonh data
Exemplo n.º 5
0
# ut  = MesonhMap("UT Map",  dataset, 'UT')
# vt  = MesonhMap("VT Map",  dataset, 'VT')

# Kernel
v0 = np.array([8.5, 0.9])
processVariance    = 1.0e-8
noiseStddev = 0.1 * np.sqrt(processVariance)
# kernel0 = WindKernel(lengthScales, processVariance, noiseStddev**2, v0)
# lengthScales = [70.0, 60.0, 60.0, 60.0]
lengthScales = [70.0, 80.0, 80.0, 60.0]
kernel0 = WindKernel(lengthScales, processVariance, noiseStddev**2, WindMapConstant('Wind',v0))

dtfile = 'output/wind_data04.neph'
dtbase = NephelaeDataServer.load(dtfile)

gpr = GprPredictor(dtbase, ['RCT'], kernel0)
map_gpr = ValueMap('RCT_gpr', gpr)
std_gpr = StdMap('RCT_gpr', gpr)

t0 = 200.0
z0 = 1100.0
b = [Bounds(0.0, 715), Bounds(12.5, 6387.5), Bounds(1837.5, 2712.5), Bounds(12.5, 3987)]

mesonhSlice = rct[t0, b[1].min:b[1].max, b[2].min:b[2].max, z0]
r2 = map_gpr.resolution()[1] / 2.0
gprSlice    = map_gpr[t0, b[1].min+r2:b[1].max-r2, b[2].min+r2:b[2].max-r2, z0]

# gprCenter0 = compute_com(gprSlice)
# gprSlice.data[gprSlice.data < 0] = 0.0
# gprCenter1 = compute_com(gprSlice)