Using scatteredinterpolant instead of griidedinterpolant
7 views (last 30 days)
Show older comments
I have a spatial data of fine resolution in gridded format of a CSV file. I want to use griddedinterpolant function and upscale into a little coarser format. But when I created a meshgrid with the source data lat-lon points, it has become unresponsive stating the generated grid is 28GB memory and MATLAB cannot process such huge data. So is the case when I used interp2. When I tried scatteredinterpolation function, it worked like a charm. Output files have been generated with more or less satisfying results. My question is what to do when we cannot use griddedinterpolant for gridded data of very fine spatial resolution? Is scatteredinterpolant safe to use as an alternative to griddedinterpolant in such cases?
Thank you in advance.
3 Comments
Accepted Answer
Matt J
on 27 Sep 2020
It looks like the latitude and longitude data in your CSV files are already meshgridded. By meshgridding them an additional time, you have created an explosion of unnecessary duplicate latitude and longitude values. See how the memory consumption grows exponentially in the following simplified illustration of what you've done:
>> x=1:30;y=2:31;
>> [X,Y]=meshgrid(x,y);
>> [XX,YY]=meshgrid(X,Y);
>> whos x y X Y XX YY
Name Size Bytes Class Attributes
X 30x30 7200 double
XX 900x900 6480000 double
Y 30x30 7200 double
YY 900x900 6480000 double
x 1x30 240 double
y 1x30 240 double
0 Comments
More Answers (2)
Image Analyst
on 27 Sep 2020
Why not simply use imresize()?
4 Comments
Image Analyst
on 27 Sep 2020
You said " My question is what to do when we cannot use griddedinterpolant for gridded data of very fine spatial resolution?" so do you have gridded data (a 2-D matrix) or not? I always use scatteredInterpolant() because it's the more general of the functions and will work in all cases. Why do you say you can't use griddedIterpolant for very fine spatial resolution? What is en example of that situation?
Matt J
on 27 Sep 2020
Edited: Matt J
on 27 Sep 2020
But when I created a meshgrid with the source data lat-lon points.
You should not create a meshgrid, since it consumes unnecessary memory. You should use the grid vector syntax,
F = griddedInterpolant({x,y},z);
It may also interest you to know that what you are trying to do has already been implemented for you in the File Excahge submission imresizen(),
Unlike imresize(), it requires no toolboxes, but it also doesn't have any of the fancy pre- and post- filtering that imresize uses to improve the quality of the downsampling.
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!