2

I've written a script that allows a user to read in a raster and provide a cell resolution, and outputs the amount of cells necessary to resample the grid (to provide a pre-processing tool to run the WRF weather model). I am still trying to figure out a test to make sure the cell size actually fits the input grid.

I'm having some difficulty figuring out how to nest grids within a 'master' domain. IDEALLY this would be via user-IO, where multiple grids are selected within themselves. Haven't added this function yet, but the nesting is easy enough with a for loop (though I need to make sure that the nested grids actually fit within the master)

How do I obtain the origin points for each of the nested grids in terms of cells of the master domain (shown in the link above)?

For instance, finding the x,y coordinates of the 0,0 origin of a nested domain WITHIN the larger master-domain.

Here's my code:

#!/bin/python
import numpy as np
from sys import argv

file = argv[1]
grid = np.loadtxt(file)
array_dims = grid.shape
x = array_dims[0]
y = array_dims[1]

cell_size = raw_input("What is the cell size you want? (x,y) \n >")
cell_size = (cell_size.split(","))
cell_size = [int(i) for i in cell_size] #goes through list and turns them to array
print cell_size
cell_x = cell_size[0]
cell_y = cell_size[0]

print "The shape of the grid is %r by %r \n" %(x,y)

e_we = int(round(x/cell_x))
e_sn = int(round(y/cell_y))

print "With that cell size, the WRF-domain is %r by %r cells" %(e_we,e_sn)

center_x = x/2
center_y = y/2

print "The center point is at %r, %r" %(center_x,center_y)
print "This point's value is", grid[center_x,center_y]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.