예제 #1
0
 def flatAxes(self):
     """Return (flatlat, flatlon) where flatlat is a 1D NumPy array
     having the same length as the number of cells in the grid, similarly
     for flatlon."""
     if self._flataxes_ is None:
         import MV2 as MV
         alat = MV.filled(self.getLatitude())
         alon = MV.filled(self.getLongitude())
         self._flataxes_ = (alat, alon)
     return self._flataxes_
def select_CF(sCF, wCF, idx, *i):
    if idx == 1.:
        masked_sCF = np.ceil(sCF)
        masked_wCF = np.ceil(wCF)
        s_avg_tmp = cdutil.averager(sCF, axis='yx')
        w_avg_tmp = cdutil.averager(wCF, axis='yx')
    elif idx == 2.:
        # set threshold;
        # you can change this values based on needs;
        s_thresholds = 0.26
        w_thresholds = 0.26
        # set grids with values lower than the threshold to 0;
        sCF[sCF < s_thresholds] = 0.
        wCF[wCF < w_thresholds] = 0.
        # mask grids with a value of 0 (grids that are not needed);
        masked_sCF = set_axes(MV.masked_equal(sCF, 0.) * 0. + 1)
        masked_wCF = set_axes(MV.masked_equal(wCF, 0.) * 0. + 1)
        s_avg_tmp = cdutil.averager(masked_sCF * sCF, axis='yx')
        w_avg_tmp = cdutil.averager(masked_wCF * wCF, axis='yx')
    elif idx == 3.:
        # set threshold, top X%;
        # you can change this values based on needs;
        p_threshold_s = 0.25
        p_threshold_w = 0.25
        # sort all grids, values for grids that are
        # outside the interested region are set to -1;
        s_reshape = np.sort(np.array(MV.filled(sCF, -1)).ravel())[::-1]
        w_reshape = np.sort(np.array(MV.filled(wCF, -1)).ravel())[::-1]
        # remove grids with values of -1;
        s_no_minus1 = s_reshape[s_reshape != -1]
        w_no_minus1 = w_reshape[w_reshape != -1]
        # find the threshold for the top X%
        num_s = int(len(s_no_minus1) * p_threshold_s)
        num_w = int(len(w_no_minus1) * p_threshold_w)
        s_thresholds = s_no_minus1[num_s - 1]
        w_thresholds = w_no_minus1[num_w - 1]
        # mask grids with a value lower than the derived thresholds (grids that are not needed);
        masked_sCF = set_axes(MV.masked_less(sCF, s_thresholds) * 0. + 1)
        masked_wCF = set_axes(MV.masked_less(wCF, w_thresholds) * 0. + 1)
        s_avg_tmp = cdutil.averager(masked_sCF * sCF, axis='yx')
        w_avg_tmp = cdutil.averager(masked_wCF * wCF, axis='yx')
    print(
        f"For method {idx}, averaged solar capacity factor for the filtered grids is: {s_avg_tmp}"
    )
    print(
        f"For method {idx}, averaged wind capacity factor for the filtered grids is: {w_avg_tmp}"
    )
    print(
        f"Selected grid cells solar {np.ceil(masked_sCF).sum()}\nSelected grid cells wind {np.ceil(masked_wCF).sum()}"
    )
    return masked_sCF, masked_wCF
예제 #3
0
 def getMesh(self, transpose=None):
     """Generate a mesh array for the meshfill graphics method.
     'transpose' is for compatibility with other grid types, is ignored."""
     import MV2 as MV
     if self._mesh_ is None:
         LAT=0
         LON=1
         latbounds, lonbounds = self.getBounds()
         if latbounds is None or lonbounds is None:
             raise CDMSError, 'No boundary data is available for grid %s'%self.id
         nvert = latbounds.shape[-1]
         mesh = numpy.zeros((self.size(),2,nvert),latbounds.dtype.char)
         mesh[:,LAT,:] = MV.filled(latbounds)
         mesh[:,LON,:] = MV.filled(lonbounds)
         self._mesh_ = mesh
     return self._mesh_
def select_CF(sCF, wCF, idx, *i):
    if idx == 1.:
        s_avg_tmp = cdutil.averager(sCF, axis='yx')
        w_avg_tmp = cdutil.averager(wCF, axis='yx')

    elif idx == 2.:
        # The numbers of 0.15 for solar and wind come from Sterl et al., 2018
        # The numders of 0.01 for solar 0.10 for wind come from Jacobson et al., 2017
        s_thresholds = 0.10
        w_thresholds = 0.10
        sCF[sCF < s_thresholds] = 0.
        wCF[wCF < w_thresholds] = 0.
        masked_sCF = set_axes(MV.masked_equal(sCF, 0.))
        masked_wCF = set_axes(MV.masked_equal(wCF, 0.))
        s_avg_tmp = cdutil.averager(masked_sCF, axis='yx')
        w_avg_tmp = cdutil.averager(masked_wCF, axis='yx')

    elif idx == 3.:
        # thresholds are selected to produce similar US annual mean values with EIA data
        p_threshold_s = (int(i[0]) + 1) * 0.1
        p_threshold_w = (int(i[0]) + 1) * 0.1
        print p_threshold_s, p_threshold_w

        s_reshape = np.sort(np.array(MV.filled(sCF, 0)).ravel())[::-1]
        w_reshape = np.sort(np.array(MV.filled(wCF, 0)).ravel())[::-1]
        s_no_zero = s_reshape[s_reshape != 0.]
        w_no_zero = w_reshape[w_reshape != 0.]
        num_s = int(len(s_no_zero) * p_threshold_s)
        num_w = int(len(w_no_zero) * p_threshold_w)
        s_thresholds = s_no_zero[num_s - 1]
        w_thresholds = w_no_zero[num_w - 1]
        sCF[sCF < s_thresholds] = 0.
        wCF[wCF < w_thresholds] = 0.
        masked_sCF = set_axes(MV.masked_equal(sCF, 0.))
        masked_wCF = set_axes(MV.masked_equal(wCF, 0.))
        s_avg_tmp = cdutil.averager(masked_sCF, axis='yx')
        w_avg_tmp = cdutil.averager(masked_wCF, axis='yx')

        masked_sCF2 = MV.array(masked_sCF / masked_sCF)
        masked_sCF2.id = 'us_mask_sCF_' + str(p_threshold_s)
        masked_wCF2 = MV.array(masked_wCF / masked_wCF)
        masked_wCF2.id = 'us_mask_wCF_' + str(p_threshold_w)

        g.write(masked_sCF2)
        g.write(masked_wCF2)

    return s_avg_tmp, w_avg_tmp
예제 #5
0
    def model_projections(self, solver=None):
        if solver is None:
            make_own_solver = True
        else:
            make_own_solver = False
        if solver is None:
            to_proj = mask_data(self.model, self.solver.eofs()[0].mask)
        else:
            to_proj = cmip5.cdms_clone(MV.filled(self.model, fill_value=0),
                                       self.model)
            to_proj = mask_data(to_proj, solver.eofs()[0].mask)
        P = MV.zeros(to_proj.shape[:2])
        for i in range(to_proj.shape[0]):
            tp = to_proj[i]
            if make_own_solver:
                mma_mask = mask_data(self.mma, tp[0].mask)

                solver = Eof(mma_mask, weights='area')
            fac = da.get_orientation(solver)

            P[i] = solver.projectField(tp)[:, 0] * fac
        P.setAxisList(to_proj.getAxisList()[:2])
        return P
예제 #6
0
        lat = f.getAxis('lat')
        lon = f.getAxis('lon')
        if len(lat) != lat_num or len(lon) != lon_num:
            print('lat/lon number error')
            sys.exit

        u50m_tmp = f('U50M')
        v50m_tmp = f('V50M')
        u10m_tmp = f('U10M')
        v10m_tmp = f('V10M')
        ws10m = np.hypot(u10m_tmp, v10m_tmp)
        ws50m = np.hypot(u50m_tmp, v50m_tmp)
        wsc = (np.log(ws50m) - np.log(ws10m)) / (np.log(50.) - np.log(10.))
        ws100m_tmp = ws10m * (100. / 10.)**wsc
        ws100m = MV.filled(ws100m_tmp, 0.)

        for hr_idx in range(24):
            # wind_speed < u_ci = 0.
            # wind_speed > u_co = 0.
            # wind_speed >= u_ci and wind_speed < u_r = v**3/u_r**2
            # wind_speed >= u_r and wind_speed <= 1.
            wcf[position + hr_idx, ws100m[hr_idx] < u_ci] = 0.
            wcf[position + hr_idx, (ws100m[hr_idx] >= u_ci) &
                (ws100m[hr_idx] < u_r)] = ws100m[hr_idx,
                                                 (ws100m[hr_idx] >= u_ci) &
                                                 (ws100m[hr_idx] < u_r)]**3 / (
                                                     u_r**3)
            wcf[position + hr_idx,
                (ws100m[hr_idx] >= u_r) & (ws100m[hr_idx] <= u_co)] = 1.
            wcf[position + hr_idx, ws100m[hr_idx] > u_co] = 0.
예제 #7
0
        if file[:-8] == case_name and file[-4:]=='.nc4':
            f=cdms.open(data_path+file)
            month = int(file[-8:-6])
            days = int(file[-6:-4])
            if month == 1:
                days_ord = 0 + days
                position = (0 + (days-1)) *24
            else:
                days_ord = (np.sum(month_days_array[:month-1]) + days)
                position = (np.sum(month_days_array[:month-1]) + (days-1)) *24
            print (month, days, days_ord, position)
            
            # get data
            lat = f.getAxis('lat')
            lon = f.getAxis('lon')
            swgdn_tmp = MV.filled(f('SWGDN',squeeze=1),0.)
            swtdn_tmp = MV.filled(f('SWTDN',squeeze=1),0.)
            t = f('TS',squeeze=1)-273.15 # convert from degree to kelvin

            if len(lat) != lat_num or len(lon) != lon_num:
                print ('lat/lon number error')
                sys.exit
            
            # separate direct and diffuse, based on Erbs et al., 1982[1] and https://pvlib-python.readthedocs.io/en/latest/
            # [1] D. G. Erbs, S. A. Klein and J. A. Duffie, Estimation of the diffuse radiation fraction for hourly, 
            # daily and monthly-average global radiation, Solar Energy 28(4), pp 293-302, 1982. Eq. 1
            kt = np.zeros([24,lat_num,lon_num])
            kt[swtdn_tmp != 0.] = (swgdn_tmp[swtdn_tmp != 0.]/swtdn_tmp[swtdn_tmp != 0.])
            kt[kt<0.] = 0.
            df = np.zeros([24,lat_num,lon_num]) # error1
            df = np.where( kt<= 0.22, 1 - 0.09 * kt, df)