示例#1
0
    def test_DSG_create_contiguous(self):
        # Define the ragged array values
        ragged_array = numpy.array([1, 3, 4, 3, 6], dtype="float32")
        # Define the count array values
        count_array = [2, 3]

        # Initialise the count variable
        count_variable = cf.Count(data=cf.Data(count_array))
        count_variable.set_property(
            "long_name", "number of obs for this timeseries"
        )

        # Initialise the contiguous ragged array object
        array = cf.RaggedContiguousArray(
            compressed_array=cf.Data(ragged_array),
            shape=(2, 3),
            size=6,
            ndim=2,
            count_variable=count_variable,
        )

        # Initialize the auxiliary coordinate construct with the ragged
        # array and set some properties
        z = cf.AuxiliaryCoordinate(
            data=cf.Data(array),
            properties={
                "standard_name": "height",
                "units": "km",
                "positive": "up",
            },
        )

        self.assertTrue(
            (
                z.data.array
                == numpy.ma.masked_array(
                    data=[[1.0, 3.0, 99], [4.0, 3.0, 6.0]],
                    mask=[[False, False, True], [False, False, False]],
                    fill_value=1e20,
                    dtype="float32",
                )
            ).all()
        )

        self.assertEqual(z.data.get_compression_type(), "ragged contiguous")

        self.assertTrue(
            (
                z.data.compressed_array
                == numpy.array([1.0, 3.0, 4.0, 3.0, 6.0], dtype="float32")
            ).all()
        )

        self.assertTrue(
            (z.data.get_count().data.array == numpy.array([2, 3])).all()
        )
示例#2
0
    def test_DSG_create_contiguous(self):
        if self.test_only and inspect.stack()[0][3] not in self.test_only:
            return

        # Define the ragged array values
        ragged_array = numpy.array([1, 3, 4, 3, 6], dtype='float32')
        # Define the count array values
        count_array = [2, 3]

        # Initialise the count variable
        count_variable = cf.Count(data=cf.Data(count_array))
        count_variable.set_property('long_name',
                                    'number of obs for this timeseries')

        # Initialise the contiguous ragged array object
        array = cf.RaggedContiguousArray(
            compressed_array=cf.Data(ragged_array),
            shape=(2, 3),
            size=6,
            ndim=2,
            count_variable=count_variable)

        # Initialize the auxiliary coordinate construct with the ragged
        # array and set some properties
        z = cf.AuxiliaryCoordinate(data=cf.Data(array),
                                   properties={
                                       'standard_name': 'height',
                                       'units': 'km',
                                       'positive': 'up'
                                   })

        self.assertTrue(
            (z.data.array == numpy.ma.masked_array(data=[[1.0, 3.0, 99],
                                                         [4.0, 3.0, 6.0]],
                                                   mask=[[False, False, True],
                                                         [False, False,
                                                          False]],
                                                   fill_value=1e+20,
                                                   dtype='float32')).all())

        self.assertEqual(z.data.get_compression_type(), 'ragged contiguous')

        self.assertTrue(
            (z.data.compressed_array == numpy.array([1., 3., 4., 3., 6.],
                                                    dtype='float32')).all())

        self.assertTrue(
            (z.data.get_count().data.array == numpy.array([2, 3])).all())
示例#3
0
# Define the ragged array values
ragged_array = cf.Data([280, 281, 279, 278, 279.5])

# Define the count array values
count_array = [1, 4]

# Create the count variable
count_variable = cf.Count(data=cf.Data(count_array))
count_variable.set_property('long_name', 'number of obs for this timeseries')

# Create the contiguous ragged array object, specifying the
# uncompressed shape
array = cf.RaggedContiguousArray(compressed_array=ragged_array,
                                 shape=(2, 4),
                                 size=8,
                                 ndim=2,
                                 count_variable=count_variable)

# Create the field construct with the domain axes and the ragged
# array
T = cf.Field()
T.set_properties({
    'standard_name': 'air_temperature',
    'units': 'K',
    'featureType': 'timeSeries'
})

# Create the domain axis constructs for the uncompressed array
X = T.set_construct(cf.DomainAxis(4))
Y = T.set_construct(cf.DomainAxis(2))
示例#4
0
    def test_DSG_contiguous(self):
        f = cf.read(self.contiguous, verbose=0)

        self.assertEqual(len(f), 2)

        # Select the specific humidity field
        q = [
            g
            for g in f
            if g.get_property("standard_name") == "specific_humidity"
        ][0]

        self.assertTrue(q._equals(q.data.array.mask, self.a.mask))

        self.assertTrue(
            q._equals(self.a, q.data.array),
            "\nself.a=\n" + str(self.a) + "\nq.array=\n" + str(q.array),
        )

        cf.write(f, tmpfile, verbose=0)
        g = cf.read(tmpfile)

        self.assertEqual(len(g), len(f))

        for i in range(len(f)):
            self.assertTrue(g[i].equals(f[i], verbose=2))

        # ------------------------------------------------------------
        # Test creation
        # ------------------------------------------------------------
        # Define the ragged array values
        ragged_array = numpy.array(
            [280, 282.5, 281, 279, 278, 279.5], dtype="float32"
        )

        # Define the count array values
        count_array = [2, 4]

        # Create the count variable
        count_variable = cf.Count(data=cf.Data(count_array))
        count_variable.set_property(
            "long_name", "number of obs for this timeseries"
        )

        # Create the contiguous ragged array object
        array = cf.RaggedContiguousArray(
            compressed_array=cf.Data(ragged_array),
            shape=(2, 4),
            size=8,
            ndim=2,
            count_variable=count_variable,
        )

        # Create the field construct with the domain axes and the ragged
        # array
        tas = cf.Field()
        tas.set_properties(
            {
                "standard_name": "air_temperature",
                "units": "K",
                "featureType": "timeSeries",
            }
        )

        # Create the domain axis constructs for the uncompressed array
        X = tas.set_construct(cf.DomainAxis(4))
        Y = tas.set_construct(cf.DomainAxis(2))

        # Set the data for the field
        tas.set_data(cf.Data(array), axes=[Y, X])

        cf.write(tas, tmpfile)
示例#5
0
    def test_DSG_contiguous(self):
        if self.test_only and inspect.stack()[0][3] not in self.test_only:
            return

        f = cf.read(self.contiguous, verbose=0)

        self.assertEqual(len(f), 2)

        # Select the specific humidity field
        q = [g for g in f
             if g.get_property('standard_name') == 'specific_humidity'][0]

        self.assertTrue(q._equals(q.data.array.mask, self.a.mask))

        self.assertTrue(q._equals(self.a, q.data.array),
                        '\nself.a=\n'+str(self.a)+'\nq.array=\n'+str(q.array))

        cf.write(f, tmpfile, verbose=0)
        g = cf.read(tmpfile)

        self.assertEqual(len(g), len(f))

        for i in range(len(f)):
            self.assertTrue(g[i].equals(f[i], verbose=2))

        # ------------------------------------------------------------
        # Test creation
        # ------------------------------------------------------------
        # Define the ragged array values
        ragged_array = numpy.array([280, 282.5, 281, 279, 278, 279.5],
                                   dtype='float32')

        # Define the count array values
        count_array = [2, 4]

        # Create the count variable
        count_variable = cf.Count(data=cf.Data(count_array))
        count_variable.set_property(
            'long_name', 'number of obs for this timeseries')

        # Create the contiguous ragged array object
        array = cf.RaggedContiguousArray(
            compressed_array=cf.Data(ragged_array),
            shape=(2, 4), size=8, ndim=2,
            count_variable=count_variable)

        # Create the field construct with the domain axes and the ragged
        # array
        tas = cf.Field()
        tas.set_properties({'standard_name': 'air_temperature',
                            'units': 'K',
                            'featureType': 'timeSeries'})

        # Create the domain axis constructs for the uncompressed array
        X = tas.set_construct(cf.DomainAxis(4))
        Y = tas.set_construct(cf.DomainAxis(2))

        # Set the data for the field
        tas.set_data(cf.Data(array), axes=[Y, X])

        cf.write(tas, tmpfile)