Skip to content

Create a 'template' raster of 0.1 resolution #741

Answered by snowman2
JimShady asked this question in Q&A
Discussion options

You must be logged in to vote

I believe this should do what you want:

import numpy
import xarray
import rioxarray

resolution = 0.1
y_coords = numpy.arange(90, -90, -resolution)
x_coords = numpy.arange(-180, 180, resolution)
data = xarray.DataArray(
    dims=("y", "x"),
    coords={
        "y": y_coords,
        "x": x_coords,
    },
    data=numpy.random.randint(
        low=1,
        high=10,
        size=(y_coords.size, x_coords.size),
        dtype=numpy.uint16,
    )
).rio.write_crs(
    "EPSG:4326", inplace=True
).rio.write_coordinate_system(inplace=True)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by snowman2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants