コード例 #1
0
def find_color_code_naive(h, s, b):
    if check_gray(s, b):
        return 'gray'
    if check_black(s, b):
        return 'black'
    if check_white(s, b):
        return 'white'
    first = find_nearest_idx(HUE_TABLE.values(), h)
    if b > BRIGHTNESS_IMPORTANCE_LEVEL:
        logger.info('Brightness is important')
        second = find_nearest_idx(SATURATION_TABLE, s)
    else:
        logger.info('Saturation is important')
        second = find_nearest_idx(BRIGHTNESS_TABLE, b)
    color = HSVColor(HUE_TABLE[first], SATURATION_TABLE[second]/100.0, BRIGHTNESS_TABLE[second]/100.0)
    color = convert_color(color, sRGBColor)
    return color.get_value_tuple(), (first, second)
コード例 #2
0
ファイル: simulation.py プロジェクト: rihe/pyinduct
 def get_results(self, time_steps, result_key="output"):
     """
     return results from storage for given time steps
     :param time_steps: time points where values are demanded
     :param result_key: type of values to be returned
     """
     # TODO change to more uniform behaviour
     idxs = np.array([find_nearest_idx(self._time_storage, t) for t in time_steps])
     results = np.array(self._value_storage[result_key])[idxs]
     if result_key == "output":
         return EvalData([time_steps], results.flatten(), name=self.name)
     else:
         return results
コード例 #3
0
ファイル: visualization.py プロジェクト: rihe/pyinduct
    def _update_plot(self):
        """
        update plot window
        """
        for idx, data_set in enumerate(self._data):
            # find nearest time index
            t_idx = ut.find_nearest_idx(self.time_data[idx], self._t)

            # TODO draw grey line if value is outdated

            # update data
            self._plot_data_items[idx].setData(x=self.spatial_data[idx],
                                               y=self.state_data[idx][t_idx])

        self._time_text.setText('t= {0:.2f}'.format(self._t))
        self._t += self._dt
        if self._t > self._endtime:
            self._t = 0
コード例 #4
0
    def __init__(self,grid_window=3, comp_method=['Rank'], field_weights=[],
                 lat_bounds=[], lon_bounds=[], forecast_lats=[], forecast_lons=[], lat_inc=1., lon_inc=1.,):
        """
        Initialize the analog object.

        :param grid_window:
            integer, +/- number of grid points (n/s, e/w) around each forecast grid point
            to include in local domain pattern matching.
            For example, if grid_window = 3, we use 49 grid points
            to calculate differences between forecast/training
            data (3*2 + 1)*(3+2 +1).
        :param comp_method
            list, Method with which to pattern match. Options: ['Rank','MAE','RMSE',].
            if n_vars > 1, can use different methods to compare each variable.
        :param lat_bounds/lon_bounds:
            list or NumPy array
            A list/numpy array of all latitude within the forecast and training data.\n
            len(allLats) = forecastData[0] or forecastData[1] if forecastData.shape == 3.
        :param forecast_last/forecast_lons:
            list or NumPy array
            Either a list/numpy array of min/max forecast lats/lons (defining a domain) or a single point.
        :param lat_inc/lon_inc:
            float
            The change in latitude/longitude each grid point (e.g. dx or dy).
        :param forecast_dates:
            float
            The change in latitude/longitude each grid point (e.g. dx or dy).
        :return: self
        """

        # --- Here, we make sure the method(s) selected is/are available, and if it/they is/are then add
        available_methods = ['rank','rmse','mae','corr',]
        self.comp_method = []
        for mthd in comp_method:
            if any(mthd.lower() in avail for avail in available_methods):
                self.comp_method.append(mthd.lower())
            else:
                warnings.warn('Method {} not an option! Reverting to rank method'.format(mthd.lower()))
                self.comp_method.append('rank')

        # --- Passed the check!
        self.grid_window = grid_window
        self.field_weights = field_weights

        # --- Here, we check to make sure everything is copacetic with the domain specifications
        # ---
        if len(forecast_lats) != len(forecast_lons):
            raise ValueError("len(lat_bounds) != len(lon_bounds)\nWe either need to forecast for a point or domain.")

        # --- Everything cool? Ok, let's do this.
        if len(forecast_lats) == 1:
            self.point_fcst = True
        else:
            self.point_fcst = False

        self.all_lats = np.arange(lat_bounds[0], lat_bounds[-1] + 1, lat_inc)
        self.all_lons = np.arange(lon_bounds[0], lon_bounds[-1] + 1, lon_inc)

        # --- If we're dealing with a point forecast, we will find the closest lat/lon grid points to the fcst point.
        if len(forecast_lats) < 1:
            self.closest_lat = self.all_lats[find_nearest_idx(self.all_lats[:], forecast_lats[0])]
            self.closest_lon = self.all_lons[find_nearest_idx(self.all_lons[:], forecast_lons[0])]
        # --- If not, we want to find a starting/stopping lat/lon indices to generate a domain-based forecast
        else:
            self.forecast_lats = forecast_lats
            self.forecast_lons = forecast_lons
            self.start_lat_idx = np.where(forecast_lats[0] == self.all_lats)[0]
            self.start_lon_idx = np.where(forecast_lons[0] == self.all_lons)[0]
            self.stop_lat_idx = np.where(forecast_lats[1] == self.all_lats)[0]
            self.stop_lon_idx = np.where(forecast_lons[1] == self.all_lons)[0]

        # --- Great, it passed! Let's add in some more info for our own edification
        self.lat_bounds = lat_bounds
        self.lon_bounds = lon_bounds
        self.lat_inc = lat_inc
        self.lon_inc = lon_inc