Example #1
0
 def __init__(self,
              input_keys,
              value_lst,
              power_arr,
              power_unit,
              ct_arr,
              default_value_dict={},
              additional_models=default_additional_models):
     """
     Parameters
     ----------
     input_keys : array_like
         list of ordered input names. First element must be 'ws'
     value_lst : list of array_like
         list of values corresponding to each key in input_keys
     power_arr : array_like
         power array. Shape must be (len(value_lst[0]), .., len(value_lst[-1]))
     power_unit : {'W','kW','MW','GW'}
         unit of power values
     ct_arr : array_like
         ct array. Shape must be (len(value_lst[0]), .., len(value_lst[-1]))
     default_value_dict : dict
         dictionary with default values, e.g. {'Air_density':1.225}
     additional_models : list, optional
         list of additional models.
     """
     self.default_value_dict = default_value_dict
     self.interp = [
         RegularGridInterpolator(value_lst, power_arr),
         RegularGridInterpolator(value_lst, ct_arr)
     ]
     PowerCtFunction.__init__(self, input_keys, self._power_ct, power_unit,
                              default_value_dict.keys(), additional_models)
 def aep4smart_start(X, Y, wt_x, wt_y, type=0):
     sim_res = self.windFarmModel(wt_x, wt_y, type=type, wd=wd, ws=ws)
     x = np.sort(np.unique(X))
     y = np.sort(np.unique(Y))
     aep_map = sim_res.flow_map(HorizontalGrid(x, y)).aep_xy()
     if isinstance(aep_map, xr.DataArray):
         aep_map = aep_map.values[:, :, 0]
     return RegularGridInterpolator((y, x), aep_map)(np.array([Y, X]).T)
 def aep4smart_start(X, Y, wt_x, wt_y):
     x = np.sort(np.unique(X))
     y = np.sort(np.unique(Y))
     X_j, Y_j, aep_map = self.aep_map(x, y, 0, wt_x, wt_y, wd=wd, ws=ws)
     #             import matplotlib.pyplot as plt
     #             c = plt.contourf(X_j, Y_j, aep_map[:, :, 0], 100)
     #             plt.colorbar(c)
     #             plt.show()
     return RegularGridInterpolator((y, x),
                                    aep_map.values)(np.array([Y, X]).T)
Example #4
0
    def get_hcw_j(self, i, l, k, F_ilk, VLT, theta_ilk, x_, y_, hcw_ijl,
                  dw_ijl):
        lambda2p = F_ilk[i, l, k] * \
            np.sum(VLT * [np.cos(theta_ilk[i, l, k]), np.sin(theta_ilk[i, l, k])], -1)
        lambda2 = RegularGridInterpolator(
            (x_, y_), [np.interp(y_, y_ + l2p_x, l2p_x) for l2p_x in lambda2p])

        hcw_j = hcw_ijl[i, :, l].copy()
        m = (hcw_ijl[i, :, l] > y_[0]) & (hcw_ijl[i, :, l] < y_[-1])
        hcw_j[m] -= lambda2((dw_ijl[i, :, l][m], hcw_ijl[i, :, l][m]))
        return hcw_j
Example #5
0
 def aep4smart_start(X, Y, wt_x, wt_y):
     x = np.sort(np.unique(X))
     y = np.sort(np.unique(Y))
     X_j, Y_j, aep_map = self.aep_map(x, y, 0, wt_x, wt_y, wd=wd, ws=ws)
     #             import matplotlib.pyplot as plt
     #             plt.plot(wt_x, wt_y, '2r')
     #             plt.show()
     #             plt.figure()
     #             c = plt.contourf(X_j, Y_j, aep_map, 100)
     #             plt.colorbar(c)
     #             plt.axis('equal')
     return RegularGridInterpolator((y, x), aep_map)(np.array([Y, X]).T)
Example #6
0
    def interp_funcs_initialization(self,
                                    interp_keys=[
                                        'A', 'k', 'f', 'tke', 'spd',
                                        'orog_trn', 'flow_inc', 'elev'
                                    ]):
        """ Initialize interpolating functions using RegularGridInterpolator
        for specified variables defined in interp_keys.
        """

        interp_funcs = {}

        for key in interp_keys:
            try:
                dr = self._ds.data_vars[key]
            except KeyError:
                print(
                    'Warning! {0} is not included in the current'.format(key) +
                    ' WindResourceGrid object.\n')
                continue

            coords = []

            data = dr.data
            for dim in dr.dims:
                # change sector index into wind direction (deg)
                if dim == 'sec':
                    num_sec = len(dr.coords[dim].data)  # number of sectors
                    coords.append(np.linspace(0, 360, num_sec + 1))
                    data = np.concatenate((data, data[:, :, :, :1]), axis=3)
                elif dim == 'z' and len(dr.coords[dim].data) == 1:
                    # special treatment for only one layer of data
                    height = dr.coords[dim].data[0]
                    coords.append(np.array([height - 1.0, height + 1.0]))
                    data = np.concatenate((data, data), axis=2)
                else:
                    coords.append(dr.coords[dim].data)

            interp_funcs[key] = RegularGridInterpolator(coords,
                                                        data,
                                                        bounds_error=False)

        self.interp_funcs.update(interp_funcs)
Example #7
0
    def fn(self, dims):
        """
        Creates an interpolation function on the field (treated as a regular grid in 2 or 3 dimensions)
        The grid is defined by the _dims_ parameter and effectively remaps the field
        dims - ([x_min, x_max], [y_min, y_max])
        """
        n = len(dims)
        if n == 2:
            d0, d1 = dims
            r0 = self.field.shape[0]
            r1 = self.field.shape[1]
            xs = linspace(d0[0], d0[1], r0)
            ys = linspace(d1[0], d1[1], r1)
            f = interpolate.interp2d(xs, ys, self.field, kind="cubic")

            def ret_fn(x, y):
                return f(x, y)[0]

            return ret_fn

        elif n == 3:
            d0, d1, d2 = dims
            r0, r1, r2 = self.field.shape
            xs = linspace(d0[0], d0[1], r0)
            ys = linspace(d1[0], d1[1], r1)
            zs = linspace(d2[0], d2[1], r2)
            f = RegularGridInterpolator((xs, ys, zs),
                                        self.field,
                                        bounds_error=False,
                                        fill_value=0)

            def ret_fn(x, y, z):
                return f((x, y, z)).reshape(1)[0]

            return ret_fn

        raise ValueError("invalid dimensions")
Example #8
0
 def aep4smart_start(X, Y, wt_x, wt_y):
     x = np.sort(np.unique(X))
     y = np.sort(np.unique(Y))
     X_j, Y_j, aep_map = self.aep_map(x, y, 0, wt_x, wt_y, wd=wd, ws=ws)
     return RegularGridInterpolator((y, x), aep_map)(np.array([Y, X]).T)
Example #9
0
 def _set_Phi_dqh_interp(self, value):
     """setter of Phi_dqh_interp"""
     if value == -1:
         value = RegularGridInterpolator()
     check_var("Phi_dqh_interp", value, "RegularGridInterpolator")
     self._Phi_dqh_interp = value