Пример #1
0
def make_sample_netcdf(tmpdir):
    """Make a test Geospatial NetCDF file, 4000x4000 int16 random data, in a variable named `sample`.
    Return the GDAL access string."""
    sample_nc = str(tmpdir.mkdir('netcdfs').join('sample.nc'))
    geobox = GeoBox(4000,
                    4000,
                    affine=Affine(25.0, 0.0, 1200000, 0.0, -25.0, -4200000),
                    crs=epsg3577)

    sample_data = np.random.randint(10000, size=(4000, 4000), dtype=np.int16)

    variables = {
        'sample':
        Variable(sample_data.dtype,
                 nodata=-999,
                 dims=geobox.dimensions,
                 units=1)
    }
    nco = create_netcdf_storage_unit(sample_nc,
                                     geobox.crs,
                                     geobox.coordinates,
                                     variables=variables,
                                     variable_params={})

    nco['sample'][:] = sample_data

    nco.close()

    return 'NetCDF:"%s":sample' % sample_nc, geobox, sample_data
Пример #2
0
    def _nco_from_sources(self, sources, geobox, measurements, variable_params, filename):

        coordinates = OrderedDict((name, geometry.Coordinate(coord.values, coord.units))
                                  for name, coord in sources.coords.items())
        coordinates.update(geobox.coordinates)

        variables = OrderedDict((variable['name'], Variable(dtype=numpy.dtype(variable['dtype']),
                                                            nodata=variable['nodata'],
                                                            dims=sources.dims + geobox.dimensions,
                                                            units=variable['units']))
                                for variable in measurements)

        return create_netcdf_storage_unit(filename, crs=geobox.crs, coordinates=coordinates,
                                          variables=variables, variable_params=variable_params,
                                          global_attributes=self.global_attributes)