Exemplo n.º 1
0
 def _predict_dir(self, x_dir):
     sec_veer = []
     for i in range(1, self.sectors + 1):
         sec_veer.append(self.params[i]['average_veer'])
     # Add additional entry for first sector
     sec_veer.append(self.params[1]['average_veer'])
     if self.direction_bin_array is None:
         veer_bins = [
             i * (360 / self.sectors) for i in range(0, self.sectors + 1)
         ]
     else:
         veer_bins = [
             self.direction_bin_array[i] +
             self.direction_bin_array[i + 1] / 2.0
             for i in range(0,
                            len(self.direction_bin_array) - 1)
         ]
     x = pd.concat([
         x_dir.dropna().rename('dir'),
         _binned_direction_series(
             x_dir.dropna(), self.sectors,
             direction_bin_array=veer_bins).rename('veer_bin')
     ],
                   axis=1,
                   join='inner')
     x['sec_mid_pt'] = [veer_bins[i - 1] for i in x['veer_bin']]
     x['ratio'] = (x['dir'] - x['sec_mid_pt']) / (360.0 / self.sectors)
     x['sec_veer'] = [sec_veer[i - 1] for i in x['veer_bin']]
     x['multiply_factor'] = [
         sec_veer[i] - sec_veer[i - 1] for i in x['veer_bin']
     ]
     x['adjustment'] = x['sec_veer'] + (x['ratio'] * x['multiply_factor'])
     return (x['dir'] + x['adjustment']).sort_index().apply(
         utils._range_0_to_360)
Exemplo n.º 2
0
    def _predict(self, x_spd, x_dir):
        x = pd.concat([
            x_spd.dropna().rename('spd'),
            _binned_direction_series(x_dir.dropna(),
                                     self.sectors,
                                     direction_bin_array=self.
                                     direction_bin_array).rename('ref_dir_bin')
        ],
                      axis=1,
                      join='inner')
        prediction = pd.DataFrame()
        first = True
        for sector, data in x.groupby(['ref_dir_bin']):
            if first is True:
                first = False
                prediction = self.speed_model[sector].sector_predict(
                    data['spd'])
            else:
                prediction = pd.concat([
                    prediction, self.speed_model[sector].sector_predict(
                        data['spd'])
                ],
                                       axis=0)

        return prediction.sort_index()
Exemplo n.º 3
0
    def __init__(self, ref_spd, ref_dir, target_spd, target_dir, averaging_prd, coverage_threshold=0.9, sectors=12,
                 direction_bin_array=None, lt_ref_speed=None, preprocess=True):
        CorrelBase.__init__(self, ref_spd, target_spd, averaging_prd, coverage_threshold, ref_dir=ref_dir,
                            target_dir=target_dir, preprocess=preprocess)
        self.sectors = sectors
        self.direction_bin_array = direction_bin_array
        if direction_bin_array is not None:
            self.sectors = len(direction_bin_array)-1
        if lt_ref_speed is None:
            self.lt_ref_speed = momm(self.data['ref_spd'])
        else:
            self.lt_ref_speed = lt_ref_speed
        self.cutoff = min(0.5 * self.lt_ref_speed, 4.0)
        self.ref_veer_cutoff = self._get_veer_cutoff(self.data['ref_spd'])
        self.target_veer_cutoff = self._get_veer_cutoff((self.data['target_spd']))
        self._randomize_calm_periods()
        self._get_overall_veer()
        # for low ref_speed and high target_speed recalculate direction sector
        self._adjust_low_reference_speed_dir()

        self.ref_dir_bins = _binned_direction_series(self.data['ref_dir'], sectors,
                                                     direction_bin_array=self.direction_bin_array).rename('ref_dir_bin')
        self.data = pd.concat([self.data, self.ref_dir_bins], axis=1, join='inner')
        self.data = self.data.dropna()
        self.params = 'not run yet'