コード例 #1
0
    def test_write(self):

        ncvariable = NcVariable("Prcp", "mm", constant=5)
        bounds = Polygon(((0, 0), (10, 0), (10, 15), (0, 15)))
        res = 5
        ncspatial = NcSpatial(bounds, res)
        rng = [datetime.datetime(2007, 10, 1), datetime.datetime(2007, 10, 3)]
        interval = datetime.timedelta(days=1)
        nctime = NcTime(rng, interval)
        ncw = NcWrite(ncvariable, ncspatial, nctime)
        path = get_temp_path(suffix='.nc')
        rootgrp = ncw.get_rootgrp(path)
        self.assertEquals(rootgrp.variables["Prcp"][:].shape, (3, 4, 3))
        ncw = NcWrite(ncvariable, ncspatial, nctime, nlevels=4)
        path = get_temp_path(suffix='.nc')
        rootgrp = ncw.get_rootgrp(path)
        self.assertEquals(rootgrp.variables["Prcp"][:].shape, (3, 4, 4, 3))
        ## check spatial dimensions
        self.assertEqual(ncw.ncspatial.dim_col.shape[0], 3)
        self.assertEqual(ncw.ncspatial.dim_row.shape[0], 4)
        ## write to a file
        ncw.write()
コード例 #2
0
    def get_uri(self, constant=5, nlevels=1):
        """
        constant=5 -- provides a constant value when generating data to fill
            a NC variable. set to None to generate random values.
        nlevels=1 -- a value greater than 1 will create a NC with a fourth level
            dimension. the input values determines the number of levels.
        """
        bounds = Polygon(((0, 0), (10, 0), (10, 15), (0, 15)))
        res = 5
        ncspatial = NcSpatial(bounds, res)

        rng = [datetime.datetime(2007, 10, 1), datetime.datetime(2007, 10, 3)]
        interval = datetime.timedelta(days=1)
        nctime = NcTime(rng, interval)

        ncvariable = NcVariable("Prcp", "mm", constant=constant)

        ncw = NcWrite(ncvariable, ncspatial, nctime, nlevels=nlevels)
        uri = ncw.write()
        return (uri)