コード例 #1
0
ファイル: massbalance.py プロジェクト: alexjarosch/oggm
    def get_mb(self, heights, year=None):
        """Returns the mass-balance at given altitudes
        for a given moment in time."""

        y, m = utils.year_to_date(year)

        pok = np.where((self.years == y) & (self.months == m))[0][0]

        # Read timeseries
        itemp = self.temp[pok]
        iprcp = self.prcp[pok]
        igrad = self.grad[pok]

        # For each height pixel:
        # Compute temp and tempformelt (temperature above melting threshold)
        npix = len(heights)
        grad_temp = igrad * (heights - self.ref_hgt)
        temp = np.ones(npix) * itemp + grad_temp
        tempformelt = temp - self.temp_melt
        tempformelt = np.clip(tempformelt, 0, tempformelt.max())

        # Compute solid precipitation from total precipitation
        prcpsol = np.ones(npix) * iprcp
        fac = 1 - (temp - self.temp_all_solid) / \
                  (self.temp_all_liq - self.temp_all_solid)
        prcpsol *= np.clip(fac, 0, 1)

        mb_month = prcpsol - self.mu_star * tempformelt
        return mb_month / SEC_IN_MONTHS[m-1] / cfg.RHO
コード例 #2
0
ファイル: massbalance.py プロジェクト: jlandmann/oggm
    def get_monthly_mb(self, heights, year=None):

        y, m = utils.year_to_date(year)
        pok = np.where((self.years == y) & (self.months == m))[0][0]

        # Read timeseries
        itemp = self.temp[pok] + self.temp_bias
        iprcp = self.prcp[pok]
        igrad = self.grad[pok]

        # For each height pixel:
        # Compute temp and tempformelt (temperature above melting threshold)
        npix = len(heights)
        temp = np.ones(npix) * itemp + igrad * (heights - self.ref_hgt)
        tempformelt = temp - self.t_melt
        tempformelt[:] = np.clip(tempformelt, 0, tempformelt.max())

        # Compute solid precipitation from total precipitation
        prcpsol = np.ones(npix) * iprcp
        fac = 1 - (temp - self.t_solid) / (self.t_liq - self.t_solid)
        prcpsol *= np.clip(fac, 0, 1)

        mb_month = prcpsol - self.mu_star * tempformelt - \
                   self.bias * SEC_IN_MONTHS[m-1] / SEC_IN_YEAR
        return mb_month / SEC_IN_MONTHS[m - 1] / cfg.RHO
コード例 #3
0
ファイル: massbalance.py プロジェクト: MachineAi/oggm
    def get_mb(self, heights, year=None):
        """Returns the mass-balance at given altitudes
        for a given moment in time."""

        y, m = utils.year_to_date(year)

        pok = np.where((self.years == y) & (self.months == m))[0][0]

        # Read timeseries
        itemp = self.temp[pok]
        iprcp = self.prcp[pok]
        igrad = self.grad[pok]

        # For each height pixel:
        # Compute temp and tempformelt (temperature above melting threshold)
        npix = len(heights)
        grad_temp = igrad * (heights - self.ref_hgt)
        temp = np.ones(npix) * itemp + grad_temp
        tempformelt = temp - self.temp_melt
        tempformelt = np.clip(tempformelt, 0, tempformelt.max())

        # Compute solid precipitation from total precipitation
        prcpsol = np.ones(npix) * iprcp
        fac = 1 - (temp - self.temp_all_solid) / \
                  (self.temp_all_liq - self.temp_all_solid)
        prcpsol *= np.clip(fac, 0, 1)

        mb_month = prcpsol - self.mu_star * tempformelt
        return mb_month / SEC_IN_MONTHS[m - 1] / cfg.RHO
コード例 #4
0
ファイル: massbalance.py プロジェクト: JohannesUIBK/oggm
    def get_monthly_mb(self, heights, year=None):

        y, m = utils.year_to_date(year)
        pok = np.where((self.years == y) & (self.months == m))[0][0]

        # Read timeseries
        itemp = self.temp[pok] + self.temp_bias
        iprcp = self.prcp[pok]
        igrad = self.grad[pok]

        # For each height pixel:
        # Compute temp and tempformelt (temperature above melting threshold)
        npix = len(heights)
        temp = np.ones(npix) * itemp + igrad * (heights - self.ref_hgt)
        tempformelt = temp - self.t_melt
        tempformelt[:] = np.clip(tempformelt, 0, tempformelt.max())

        # Compute solid precipitation from total precipitation
        prcpsol = np.ones(npix) * iprcp
        fac = 1 - (temp - self.t_solid) / (self.t_liq - self.t_solid)
        prcpsol *= np.clip(fac, 0, 1)

        mb_month = prcpsol - self.mu_star * tempformelt - \
                   self.bias * SEC_IN_MONTHS[m-1] / SEC_IN_YEAR
        return mb_month / SEC_IN_MONTHS[m-1] / cfg.RHO
コード例 #5
0
    def test_date_to_year(self):

        r = utils.date_to_year(0, 1)
        self.assertEqual(r, 0)

        r = utils.date_to_year(1, 1)
        self.assertEqual(r, 1)

        r = utils.date_to_year([0, 1], [1, 1])
        np.testing.assert_array_equal(r, [0, 1])

        yr = utils.date_to_year([1998, 1998], [6, 7])
        y, m = utils.year_to_date(yr)
        np.testing.assert_array_equal(y, [1998, 1998])
        np.testing.assert_array_equal(m, [6, 7])

        yr = utils.date_to_year([1998, 1998], [2, 3])
        y, m = utils.year_to_date(yr)
        np.testing.assert_array_equal(y, [1998, 1998])
        np.testing.assert_array_equal(m, [2, 3])

        time = pd.date_range('1/1/1800', periods=300*12, freq='MS')
        yr = utils.date_to_year(time.year, time.month)
        y, m = utils.year_to_date(yr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        myr = utils.monthly_timeseries(1800, 2099)
        y, m = utils.year_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        myr = utils.monthly_timeseries(1800, ny=300)
        y, m = utils.year_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        with self.assertRaises(ValueError):
            utils.monthly_timeseries(1)
コード例 #6
0
    def test_year_to_date(self):

        r = utils.year_to_date(0)
        self.assertEqual(r, (0, 1))

        y, m = utils.year_to_date([0, 1])
        np.testing.assert_array_equal(y, [0, 1])
        np.testing.assert_array_equal(m, [1, 1])

        y, m = utils.year_to_date([0.00001, 1.00001])
        np.testing.assert_array_equal(y, [0, 1])
        np.testing.assert_array_equal(m, [1, 1])

        y, m = utils.year_to_date([0.99999, 1.99999])
        np.testing.assert_array_equal(y, [0, 1])
        np.testing.assert_array_equal(m, [12, 12])

        yr = 1998 + cfg.CUMSEC_IN_MONTHS[2] / cfg.SEC_IN_YEAR
        r = utils.year_to_date(yr)
        self.assertEqual(r, (1998, 4))

        yr = 1998 + (cfg.CUMSEC_IN_MONTHS[2] - 1) / cfg.SEC_IN_YEAR
        r = utils.year_to_date(yr)
        self.assertEqual(r, (1998, 3))
コード例 #7
0
ファイル: massbalance.py プロジェクト: jlandmann/oggm
 def get_monthly_mb(self, heights, year=None):
     ryr, m = utils.year_to_date(year)
     ryr = utils.date_to_year(self.get_state_yr(ryr), m)
     return self.mbmod.get_monthly_mb(heights, year=ryr)
コード例 #8
0
ファイル: massbalance.py プロジェクト: jlandmann/oggm
 def get_monthly_mb(self, heights, year=None):
     yr, m = utils.year_to_date(year)
     return self.interp_m[m - 1](heights)
コード例 #9
0
ファイル: massbalance.py プロジェクト: JohannesUIBK/oggm
 def get_monthly_mb(self, heights, year=None):
     ryr, m = utils.year_to_date(year)
     ryr = utils.date_to_year(self.get_state_yr(ryr), m)
     return self.mbmod.get_monthly_mb(heights, year=ryr)
コード例 #10
0
ファイル: massbalance.py プロジェクト: JohannesUIBK/oggm
 def get_monthly_mb(self, heights, year=None):
     yr, m = utils.year_to_date(year)
     return self.interp_m[m-1](heights)