def test_orbital_interpolation(): # check to see if we get smooth results when we interpolate # orbital parameters at high temporal frequency kyears = np.linspace(-11, 0, 1001) orb = OrbitalTable.interp(kyear=kyears) S30 = daily_insolation(lat=30, day=172, orb=orb) # there should be no abrupt changes # test if insolation varies by more than 0.1 W/m2 per year assert S30.diff(dim='kyear').max() < 0.1
def test_daily_insolation(): lat = np.linspace(-90., 90., 500.) days = np.linspace(0, const.days_per_year, 365.) Q = daily_insolation(lat, days) # check the range of Q np.testing.assert_almost_equal(Q.max(), 562.0333475) np.testing.assert_almost_equal(Q.min(), 0.0) # check the area integral Q_area_int = (np.sum(np.mean(Q, axis=1) * np.cos(np.deg2rad(lat))) / np.sum(np.cos(np.deg2rad(lat)))) np.testing.assert_almost_equal(Q_area_int, 341.384184481)
def test_daily_insolation(): lat = np.linspace( -90., 90., 500. ) days = np.linspace(0, const.days_per_year, 365. ) Q = daily_insolation(lat, days) # check the range of Q np.testing.assert_almost_equal(Q.max(), 562.0333475) np.testing.assert_almost_equal(Q.min(), 0.0) # check the area integral Q_area_int = (np.sum(np.mean(Q, axis=1) * np.cos(np.deg2rad(lat))) / np.sum(np.cos(np.deg2rad(lat))) ) np.testing.assert_almost_equal(Q_area_int, 341.384184481)
def add_monthly_insolation(ds): month_days = [31,28,31,30,31,30,31,31,30,31,30,31] #list of the number of days in a month day_of_month = [ np.cumsum(month_days) - np.array(month_days), np.cumsum(month_days) ] #list of first and last day of each month day_num = np.arange(1,366) #number of days in a year month_num = np.arange(0,12) #number of months in a year insolation = np.zeros(len(day_num)) #insolation for each day monthly_insol = np.zeros(len(month_num)) #insolation for each month for day in day_num: #calculate daily insolation insolation[day-1] = daily_insolation(lat = -90, day = day) for month in month_num: #calculate monthly mean insolation monthly_insol[month] = insolation[day_of_month[0][month]:day_of_month[1][month]].mean() ds['monthly_insolation'] = xr.DataArray(data = monthly_insol, dims = 'month') #add into our dataset
def _daily_insolation_array(self): lat = self.lat days_of_year = self.time['days_of_year'] orb = self.orb S0 = self.S0 return daily_insolation(lat, days_of_year, orb=orb, S0=S0)
def _daily_insolation(self, day): years = np.linspace(-self.num_years, 0, self.num_years) orb = OrbitalTable.interp(kyear=years) return daily_insolation(lat=self.lat, day=day, orb=orb)
def _daily_insolation(self, day): years = np.linspace(-YEARS_IN_SIMULATION, 0, YEARS_IN_SIMULATION) orb = OrbitalTable.interp(kyear=years) i = daily_insolation(lat=self.latitude, day=day, orb=orb) return i.to_dict()['data']