<p>Note: I'm assuming that the original data are provided in NetCDF format.</p>
<p>There are two (OK, there are more, but I'll focus on these two) relatively quick ways to deal with this issue. Which one to prefer is very much depending on your preference and ability to use the different tools involved.</p>
<p>The fastest approach that comes to my mind is using the Climate Data Operator (CDO): you can find a detailed documentation <a href="https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf" rel="noreferrer">here</a> and an overview <a href="https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial" rel="noreferrer">here</a>.</p>
<p>The approach should be to get the grid description from the highest resolution file:</p>
<pre><code>cdo -griddes imerg.nc
</code></pre>
<p>Then, take the description of the grid and put it in a <code>.txt</code> file and remap the coarser resolution file to match this grid. In this case, you may want to use a conservative remapping methodology to maintain the original values unaltered.</p>
<pre><code>cdo remapcon,imerggrid.txt merra_coarse.nc merra_imerggrid.nc
</code></pre>
<p>In this way you would have the MERRA-2 data in a resolution matching your IMERG grid.</p>
<p>The second approach uses <code>R</code>.
Steps (very quickly):</p>
<ol>
<li>load the two NetCDF files as raster;</li>
<li>make a raster to point transformation (or just extract the coordinates and transform them in a Point Spatial object) of the imerg raster (in this way you would obtain the centroids of the imerg cells);</li>
<li>extract the data from the merra object overlaying the imerg points.
All these passages are well documented in <a href="https://stackoverflow.com/">stackoverflow</a> or <a href="https://gis.stackexchange.com/">gis.stackexchange</a>.</li>
</ol>
<p>This last methodology, however, may result in a very slow process in case of large datasets.</p>

CC BY-SA 4.0
2021-07-27T19:13:47.020Z
After performing the above methodology, it appears that the newly regridded image has lower resolution than before. Is this meant to occur or did I make an error somewhere?
mpletch1
CC BY-SA 4.0
2021-07-28T07:15:00.190Z
the regridded image should have now the same resolution as your imerg data
Nemesi
CC BY-SA 4.0
2021-07-28T18:36:59.167Z
It's odd because the number of points in the regridded image increased to 5,475,600 from 59,040 and the image appears to be less detailed. I'm going to link some images to my initial questions.
mpletch1
CC BY-SA 4.0
2021-07-29T08:08:27.670Z
the reason why the image looks scattered, is due to the conservative remapping. If you want a smoother image, you should use the bilinear interpolation remapping command (remapbil). the reason why I originally suggested the remapcon is because you asked for "I want to find the boundary layer thickness at every point where the rainfall rate exceeds 10 mm/hr"and I thought you wanted the original data. Remapping with a biliniear interpolation will alter the data to make the smoothing.
Nemesi
CC BY-SA 4.0
2021-07-29T10:35:43.487Z
@mpletch1 It looks to me like you're also plotting with contouring/interpolation on, which is why the coarse IMERG data in the lower plot _appears_ smooth and more detailed.  If you are, then I recommend switching it off, as it makes it harder to assess the regridding.
Deditos
CC BY-SA 4.0
2021-07-29T17:16:26.423Z
@Deditos I didn't realize that the IMERG data was already calibrated and interpolated, so that explains the smoothed look of the IMERG data. From NASA's description of IMERG data: "The half-hourly intercalibrated merged PMW estimates are then input to both the Climate Prediction Center (CPC) Morphing-Kalman Filter (CMORPH-KF) Lagrangian time interpolation scheme and the Precipitation Estimation from Remotely Sensed Information using Artificial Neural Networks Cloud Classification System (PERSIANN-CCS) re-calibration scheme."
mpletch1
CC BY-SA 4.0
2021-07-30T07:56:48.833Z
@mpletch1 Ah sorry, I typed IMERG when I meant MERRA, i.e., the PBL height data that you're regridding.
Deditos
CC BY-SA 4.0
2021-08-18T19:52:17.943Z
This definitely helped me to figure out my problem. I used matplotlib's np.where to determine what the PBLH height is at each point where the rainfall rate exceeds 10 mm/hr.
mpletch1
CC BY-SA 4.0
2021-07-27T08:35:44.273Z
2021-07-27T08:35:44.273Z
Nemesi
<p>I have two datasets, each with two differing resolutions. The first dataset is a coarser resolution data set that has 0.5 x 0.625 degree resolution and contains values of MERRA-2 boundary layer thickness. The second, finer resolution dataset has 0.1 x 0.1 degree resolution and contains values of IMERG rainfall rate. I want to find the boundary layer thickness at every point where the rainfall rate exceeds 10 mm/hr. Since the MERRA-2 boundary layer thickness dataset is coarser, I figured that I could create a grid from the latitude and longitude values in the MERRA-2 dataset and check if the IMERG data points lie within any of the MERRA-2 grid boxes. I'm having trouble figuring out where to start with this, and any help is greatly appreciated.</p>
<p>Here is the formatting of the latitude and longitude for each dataset:</p>
<pre><code>MERRA-2 Latitude: [[1.3500000e+01  1.3500000e+01  1.3500000e+01  1.3500000e+01]
MERRA-2 Longitude: [[-51.875 -51.25  -50.625 -50.    -49.375 -48.75  -48.125 -47.5   -46.875]
IMERG Latitude: [-0.05  0.05  0.15  0.25  0.35  0.45  0.55  0.65  0.75  0.85  0.95  1.05]
IMERG Longitude: [-49.95 -49.85 -49.75 -49.65 -49.55 -49.45 -49.35 -49.25 -49.15 -49.05]
</code></pre>
<p>EDIT: I have created a regridded dataset from Nemesi's first methodology (cdo remapcon), and they can be found below. The top image is the regridded data, and the bottom is the original data. Although the number of points in the newly regridded dataset increased from 59,040 to 5,475,600, the image seems to have lower resolution than the original image. The IMERG data also seems to have higher resolution even though both datasets have the same amount of points. Is this due to an error with the data formatting?</p>
<p><a href="https://i.sstatic.net/EyrtK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EyrtK.png" alt="Original dataset" /></a>
<a href="https://i.sstatic.net/TVD6r.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TVD6r.png" alt="Newly regridded dataset" /></a></p>

CC BY-SA 4.0
2021-07-26T19:50:12.657Z
You should use a GIS approach.  You could even use python (e.g. geopandas) really quickly.  In my experience it's much faster to load geospatial data (e.g. the native NetCDF?) because it is time-consuming to recreate grids from the lat/long text outputs.
f.thorpe
CC BY-SA 4.0
2021-07-26T20:35:19.817Z
By GIS approach do you mean nearest neighbor or nearest point interpolation?
mpletch1
CC BY-SA 4.0
2021-07-26T20:47:10.623Z
If it's just a single dataset, you can do what's commonly referred to as an "intersect", which is a type of spatial join.  That would require conversion from raster to polygon, but that would likely be too time consuming if you are dealing with timeseries data.  If you are using time-series data, I would suggest you use the proper raster tool to convert from one grid to the other and get them directly comparable.
f.thorpe
CC BY-SA 4.0
2021-07-29T14:26:27.123Z
Unfortunately, I don't have access to ArcMap software as of now and I'm having trouble installing the geopandas Python library onto my Python environment.
mpletch1
<meteorology><python>
Determining if a fine resolution lat/lon point lies in a coarse resolution lat/lon grid box?
mpletch1
# Determining if a fine resolution lat/lon point lies in a coarse resolution lat/lon grid box?

(Asked by: username_0 on 2021-07-26)

I have two datasets, each with two differing resolutions. The first dataset is a coarser resolution data set that has 0.5 x 0.625 degree resolution and contains values of MERRA-2 boundary layer thickness. The second, finer resolution dataset has 0.1 x 0.1 degree resolution and contains values of IMERG rainfall rate. I want to find the boundary layer thickness at every point where the rainfall rate exceeds 10 mm/hr. Since the MERRA-2 boundary layer thickness dataset is coarser, I figured that I could create a grid from the latitude and longitude values in the MERRA-2 dataset and check if the IMERG data points lie within any of the MERRA-2 grid boxes. I'm having trouble figuring out where to start with this, and any help is greatly appreciated.

Here is the formatting of the latitude and longitude for each dataset:

```
MERRA-2 Latitude: [[1.3500000e+01  1.3500000e+01  1.3500000e+01  1.3500000e+01]
MERRA-2 Longitude: [[-51.875 -51.25  -50.625 -50.    -49.375 -48.75  -48.125 -47.5   -46.875]
IMERG Latitude: [-0.05  0.05  0.15  0.25  0.35  0.45  0.55  0.65  0.75  0.85  0.95  1.05]
IMERG Longitude: [-49.95 -49.85 -49.75 -49.65 -49.55 -49.45 -49.35 -49.25 -49.15 -49.05]

```

EDIT: I have created a regridded dataset from username_2's first methodology (cdo remapcon), and they can be found below. The top image is the regridded data, and the bottom is the original data. Although the number of points in the newly regridded dataset increased from 59,040 to 5,475,600, the image seems to have lower resolution than the original image. The IMERG data also seems to have higher resolution even though both datasets have the same amount of points. Is this due to an error with the data formatting?

[![Original dataset](https://i.sstatic.net/EyrtK.png)](https://i.sstatic.net/EyrtK.png)
[![Newly regridded dataset](https://i.sstatic.net/TVD6r.png)](https://i.sstatic.net/TVD6r.png)

**Tags:** meteorology, python

> **Comments:**
> **username_1**: You should use a GIS approach.  You could even use python (e.g. geopandas) really quickly.  In my experience it's much faster to load geospatial data (e.g. the native NetCDF?) because it is time-consuming to recreate grids from the lat/long text outputs.  
> **username_0**: By GIS approach do you mean nearest neighbor or nearest point interpolation?  
> **username_1**: If it's just a single dataset, you can do what's commonly referred to as an "intersect", which is a type of spatial join.  That would require conversion from raster to polygon, but that would likely be too time consuming if you are dealing with timeseries data.  If you are using time-series data, I would suggest you use the proper raster tool to convert from one grid to the other and get them directly comparable.  
> **username_0**: Unfortunately, I don't have access to ArcMap software as of now and I'm having trouble installing the geopandas Python library onto my Python environment.  

---

## 1 answers

### Answer by username_2 on 2021-07-27. Score: 5 | Accepted answer

Note: I'm assuming that the original data are provided in NetCDF format.

There are two (OK, there are more, but I'll focus on these two) relatively quick ways to deal with this issue. Which one to prefer is very much depending on your preference and ability to use the different tools involved.

The fastest approach that comes to my mind is using the Climate Data Operator (CDO): you can find a detailed documentation [here](https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf) and an overview [here](https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial).

The approach should be to get the grid description from the highest resolution file:

```
cdo -griddes imerg.nc

```

Then, take the description of the grid and put it in a `.txt` file and remap the coarser resolution file to match this grid. In this case, you may want to use a conservative remapping methodology to maintain the original values unaltered.

```
cdo remapcon,imerggrid.txt merra_coarse.nc merra_imerggrid.nc

```

In this way you would have the MERRA-2 data in a resolution matching your IMERG grid.

The second approach uses `R`.
Steps (very quickly):

1. load the two NetCDF files as raster;
2. make a raster to point transformation (or just extract the coordinates and transform them in a Point Spatial object) of the imerg raster (in this way you would obtain the centroids of the imerg cells);
3. extract the data from the merra object overlaying the imerg points.
   All these passages are well documented in [stackoverflow](https://stackoverflow.com/) or [gis.stackexchange](https://gis.stackexchange.com/).

This last methodology, however, may result in a very slow process in case of large datasets.

> **Comments:**
> **username_0**: After performing the above methodology, it appears that the newly regridded image has lower resolution than before. Is this meant to occur or did I make an error somewhere?  
> **username_2**: the regridded image should have now the same resolution as your imerg data  
> **username_0**: It's odd because the number of points in the regridded image increased to 5,475,600 from 59,040 and the image appears to be less detailed. I'm going to link some images to my initial questions.  
> **username_2**: the reason why the image looks scattered, is due to the conservative remapping. If you want a smoother image, you should use the bilinear interpolation remapping command (remapbil). the reason why I originally suggested the remapcon is because you asked for "I want to find the boundary layer thickness at every point where the rainfall rate exceeds 10 mm/hr"and I thought you wanted the original data. Remapping with a biliniear interpolation will alter the data to make the smoothing.  
> **username_3**: @username_0 It looks to me like you're also plotting with contouring/interpolation on, which is why the coarse IMERG data in the lower plot _appears_ smooth and more detailed.  If you are, then I recommend switching it off, as it makes it harder to assess the regridding.  
> **username_0**: @username_3 I didn't realize that the IMERG data was already calibrated and interpolated, so that explains the smoothed look of the IMERG data. From NASA's description of IMERG data: "The half-hourly intercalibrated merged PMW estimates are then input to both the Climate Prediction Center (CPC) Morphing-Kalman Filter (CMORPH-KF) Lagrangian time interpolation scheme and the Precipitation Estimation from Remotely Sensed Information using Artificial Neural Networks Cloud Classification System (PERSIANN-CCS) re-calibration scheme."  
> **username_3**: @username_0 Ah sorry, I typed IMERG when I meant MERRA, i.e., the PBL height data that you're regridding.  
> **username_0**: This definitely helped me to figure out my problem. I used matplotlib's np.where to determine what the PBLH height is at each point where the rainfall rate exceeds 10 mm/hr.  

---

