Esempio n. 1
0
 def test_elevation_effect(self):
     self.assertGreater(
         top.elevation_corrected_sw(zenith=45,
                                    grid_sw=500,
                                    lat=50,
                                    lon=-110,
                                    time=datetime.datetime(
                                        year=2020,
                                        month=5,
                                        day=10,
                                        hour=18,
                                        tzinfo=datetime.timezone.utc),
                                    grid_elevation=100,
                                    sub_elevation=2000)[1],
         top.elevation_corrected_sw(zenith=45,
                                    grid_sw=500,
                                    lat=50,
                                    lon=-110,
                                    time=datetime.datetime(
                                        year=2020,
                                        month=5,
                                        day=10,
                                        hour=18,
                                        tzinfo=datetime.timezone.utc),
                                    grid_elevation=100,
                                    sub_elevation=1000)[1])
Esempio n. 2
0
 def test_array(self):
     self.assertEqual(
         3,
         len(
             top.elevation_corrected_sw(zenith=self.zenith,
                                        grid_sw=self.sw,
                                        lat=self.lat,
                                        lon=self.lon,
                                        time=self.time,
                                        grid_elevation=self.ge,
                                        sub_elevation=self.se)[0]))
Esempio n. 3
0
    def SW_Wm2_topo(self, ni=10):
        """
        Short-wave downwelling radiation corrected using a modified version of TOPOscale.
        Partitions into direct and diffuse
        """

        # add variable to ncdf file
        vn_diff = 'SW_topo_diffuse'  # variable name
        var = self.rg.createVariable(vn_diff, 'f4', ('time', 'station'))
        var.long_name = 'TOPOscale-corrected diffuse solar radiation'
        var.units = 'W m-2'
        var.standard_name = 'surface_diffuse_downwelling_shortwave_flux_in_air'

        vn_dir = 'SW_topo_direct'  # variable name
        var = self.rg.createVariable(vn_dir, 'f4', ('time', 'station'))
        var.long_name = 'TOPOscale-corrected direct solar radiation'
        var.units = 'W m-2'
        var.standard_name = 'surface_direct_downwelling_shortwave_flux_in_air'

        # interpolate station by station
        nc_time = self.nc_sf.variables['time']
        py_time = nc.num2date(nc_time[:],
                              nc_time.units,
                              nc_time.calendar,
                              only_use_cftime_datetimes=False)
        py_time = np.array([pytz.utc.localize(t) for t in py_time])
        lat = self.getValues(self.nc_pl, 'latitude', ni)
        lon = self.getValues(self.nc_pl, 'longitude', ni)
        sw = self.getValues(self.nc_sf, 'ssrd',
                            ni) / self.interval_in  # [J m-2] --> [W m-2]
        grid_elev = self.getValues(
            self.nc_to, 'z',
            ni)[0, :] / 9.80665  # z has 2 dimensions from the scaling step
        station_elev = self.getValues(self.nc_pl, 'height', ni)

        svf = self.get_sky_view()
        slope = self.get_slope()
        aspect = self.get_aspect()

        interpolation_time = nc_time[:].astype(np.int64)

        for n, s in enumerate(self.rg.variables['station'][:].tolist()):
            zenith = solar_zenith(lat=lat[n], lon=lon[n], time=py_time)

            diffuse, corrected_direct = elevation_corrected_sw(
                zenith=zenith,
                grid_sw=sw[:, n],
                lat=np.ones_like(sw[:, n]) * lat[n],
                lon=np.ones_like(sw[:, n]) * lon[n],
                time=py_time,
                grid_elevation=np.ones_like(sw[:, n]) * grid_elev[n],
                sub_elevation=np.ones_like(sw[:, n]) * station_elev[n])

            diffuse = diffuse * svf[n]  # apply sky-view factor

            if not np.all(slope == 0):
                azimuth = get_azimuth_fast(lat[n], lon[n], py_time)
                cos_i_sub = illumination_angle(zenith, azimuth, slope[n],
                                               aspect[n])
                cos_i_grid = np.cos(np.radians(zenith))
                corrected_direct = shading_corrected_sw_direct(
                    corrected_direct, cos_i_sub, cos_i_grid)

                sensible_values_mask = np.where(
                    cos_i_grid < 0.001, 0, 1) * np.where(
                        corrected_direct > 1366, 0, 1)
                corrected_direct *= sensible_values_mask

            f = interp1d(interpolation_time * 3600,
                         corrected_direct,
                         kind='linear')
            self.rg.variables[vn_dir][:, n] = f(self.times_out_nc)

            f = interp1d(interpolation_time * 3600, diffuse, kind='linear')
            self.rg.variables[vn_diff][:, n] = f(self.times_out_nc)