Using scatteredinterpolant instead of griidedinterpolant

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

Is scatteredinterpolant safe to use as an alternative to griddedinterpolant in such cases?
scatteredInterpolant() is wrong as an alternative for 2 reasons.
(1) It is generally slower and more computationally demanding than gridded interpolation.
(2) You will now go around falsely believing that griddedInterpolant works poorly, just because you had an easier time getting scatteredInterpolant to work.
I have understood the mistake from your explanation of space occupied by using mesh grid again and again. I've realized the mistake I'm making.
Can you put the space occupied comment as another answer so that I can accept it as an answer?

Sign in to comment.

 Accepted Answer

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

More Answers (2)

Why not simply use imresize()?

4 Comments

One of those tools that I would automatically assume requiires the IPT. It is part of MATLAB proper though.
I have the data in .CSV format. I should have mentioned that. It's a mistake from my end. I'm gonna add that in my question.
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?
I have a fine resolution data in .CSV format in the format as atatched in the image. To use griddedinterpolant or interp2, a meshgrid or ndgrid needs to be created using lat, lon values. When I did that step, command window shows " Requested 61890x61890 (28.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive.". I need data at coarser resolution for a work.

Sign in to comment.

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);
where x and y are grid vectors, not meshgrids.
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.

Categories

Asked:

on 27 Sep 2020

Answered:

on 27 Sep 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!