<p>Here is a simple 'back of the napkin' idea for Python:</p>

<ol>
<li>Get a shapefile of the borders and use Python to create a polygon of the borders.</li>
<li>Use mpl_toolkits to convert the climate model to X and Y coordinates</li>
<li><a href="https://stackoverflow.com/questions/36399381/whats-the-fastest-way-of-checking-if-a-point-is-inside-a-polygon-in-python">Check to see if the model grid points are within the Polygon</a></li>
</ol>

CC BY-SA 3.0
2018-01-29T15:06:28.883Z
2018-01-29T15:06:28.883Z
BarocliniCplusplus
<p>What is the best method of calculating the number of model grid cells (e.g. of climate models) covering a specific country? For example, if I wanted to know how many 2 degree grid cells are in the United Kingdom, how would I go about it? At present I use the mapping toolbox in matlab and add a 2 degree grid and calculate manually. Is there a better way of doing this? Any advice is appreciated.  </p>

CC BY-SA 3.0
2018-01-29T12:17:34.750Z
I assume you have land mask and borders of the grids. From the whole grid loop over a rectangular shape compassing UK but no other countries and for each cell check the land mask.
Communisty
CC BY-SA 3.0
2018-01-29T14:51:12.090Z
Be aware that some models use non-equirectangular grids.
gerrit
CC BY-SA 3.0
2018-01-29T21:58:06.363Z
Do you have the countries outlines in matlab as a vector? Or an image?
Camilo Rada
CC BY-SA 3.0
2018-01-30T22:36:47.520Z
I would do it in a geographic information system and this question might be better answered in https://gis.stackexchange.com/
haresfur
<models><numerical-modelling><grid-spacing>
Calculate the number of model grid cells covering a specific country
Emma Tebbs
# Calculate the number of model grid cells covering a specific country

(Asked by: username_0 on 2018-01-29)

What is the best method of calculating the number of model grid cells (e.g. of climate models) covering a specific country? For example, if I wanted to know how many 2 degree grid cells are in the United Kingdom, how would I go about it? At present I use the mapping toolbox in matlab and add a 2 degree grid and calculate manually. Is there a better way of doing this? Any advice is appreciated.

**Tags:** models, numerical-modelling, grid-spacing

> **Comments:**
> **username_1**: I assume you have land mask and borders of the grids. From the whole grid loop over a rectangular shape compassing UK but no other countries and for each cell check the land mask.  
> **username_2**: Be aware that some models use non-equirectangular grids.  
> **username_3**: Do you have the countries outlines in matlab as a vector? Or an image?  
> **username_4**: I would do it in a geographic information system and this question might be better answered in https://gis.stackexchange.com/  

---

## 1 answers

### Answer by username_5 on 2018-01-29. Score: 2

Here is a simple 'back of the napkin' idea for Python:

1. Get a shapefile of the borders and use Python to create a polygon of the borders.
2. Use mpl\_toolkits to convert the climate model to X and Y coordinates
3. [Check to see if the model grid points are within the Polygon](https://stackoverflow.com/questions/36399381/whats-the-fastest-way-of-checking-if-a-point-is-inside-a-polygon-in-python)


---

