Пример #1
0
def test_build_interpolator_alig():
    targets = [60, 350, 550]
    DATA_Z_ALIG = destagger_array(DATA_Z_STAG, 1)
    ipor = build_interpolator(DATA_Z_ALIG, targets, False)
    assert type(ipor) == Interpolator
    assert ipor.dimension == DIM_BOTTOM_TOP
    assert ipor.max_k == 4  # Don't need 5th since 550m is completely masked out
    assert str(ipor) == 'Interpolator[bottom_top: (60, 350, 550)]'
Пример #2
0
    def z_alig(self):
        LOG.info('        calculate z')
        if self.height_type in (HeightType.above_sea, HeightType.above_ground):
            return destagger_array(self.z_stag(), 1)

        else:
            p, m, n = self.get_var_native('P')
            p = p[self.t_start:self.t_end, ..., m:n, m:n]
            pb, m, n = self.get_var_native('PB')
            pb = pb[self.t_start:self.t_end, ..., m:n, m:n]
            return (p + pb) / 100
Пример #3
0
def test_interpolate_t():
    targets = [60, 350, 550]
    DATA_Z_ALIG = destagger_array(DATA_Z_STAG, 1)
    ipor = build_interpolator(DATA_Z_ALIG, targets, False)

    t_tgt = ipor(DATA_T)
    assert t_tgt[:, 0, 0, 0].tolist() == [-17.10787269681742, -17.40796311818944, -17.70822147651007]
    assert t_tgt[:, 1, 0, 0].tolist() == [-17.7, -18.1, -18.400000000000002]

    # 550m is completely masked out in the aligne interpolator
    assert np.sum(ipor.vics[2].mask) == 48
Пример #4
0
def test_destagger_array_0():
    a = np.array([
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9],
    ])
    b = destagger_array(a, axis=0)
    assert type(b) == np.ndarray
    assert b.tolist() == [
        [2.5, 3.5, 4.5],
        [5.5, 6.5, 7.5],
    ]
Пример #5
0
def test_destagger_array_1():
    a = np.array([
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9],
    ])
    b = destagger_array(a, axis=1)
    assert type(b) == np.ndarray
    assert b.tolist() == [
        [1.5, 2.5],
        [4.5, 5.5],
        [7.5, 8.5],
    ]
Пример #6
0
    def z_stag(self):
        """ Return the heights of the input file's sigma levels as dictated by the height_type """
        LOG.info('        calculate z_stag')

        if self.height_type in (HeightType.above_sea, HeightType.above_ground):
            ph, m, n = self.get_var_native('PH')
            ph = ph[self.t_start:self.t_end, ..., m:n, m:n]
            phb, m, n = self.get_var_native('PHB')
            phb = phb[self.t_start:self.t_end, ..., m:n, m:n]

            z_stag = (ph + phb) * g_inv  # ph and phb are vertically staggered
            if self.height_type == HeightType.above_ground:
                hgt, m, n = self.get_var_native('HGT', 'HGT_M')
                hgt = hgt[0, m:n, m:n]
                z_stag -= hgt
            return z_stag

        else:
            return destagger_array(self.z_alig(), 1)