I'm trying to convert a 1 dimension lat,lon,data to 2d data without interpolating (without griddata command). Is this possible?

11 views (last 30 days)
I have a one dimensional latitude,longitude, data. Essentially all are in one dimension. However I want to create a 2D plot with the data. So, what I want is the data should be in 2D format without using the griddate which uses interpolation. So, in 2D format of data there should be original value of 1D data present at every original latitude, longitude point and other points it will be NaN or zero.

Accepted Answer

Chunru
Chunru on 24 Jul 2021
Edited: Chunru on 25 Jul 2021
Updated solution:
T1 = readtable('chiranjit Das DAY_1.xlsx');
dg = 1;
longrid = (-180:dg:180);
latgrid = (-90:dg:90);
z = nan(length(latgrid), length(longrid));
for ilat=1:length(latgrid)
for ilon=1:length(longrid)
ii = T1.LATITUDE-latgrid(ilat)>=-dg/2 & T1.LATITUDE-latgrid(ilat)<dg/2 & ...
T1.LONGITUDE-longrid(ilon)>=-dg/2 & T1.LONGITUDE-longrid(ilon)<dg/2;
z(ilat, ilon) = mean(T1.DATA(ii));
end
end
figure
imagesc(longrid, latgrid, z);
axis xy
xlabel('lon');
ylabel('lat');
colorbar
figure;
cmap = turbo(1024); cmap = cmap(257:768,:);
ax = axesm('MapProjection','apianus','MapLatLimit',[-90 90], 'MapLonLimit', [-180 180]);
[lon, lat] = meshgrid(longrid, latgrid);
geoshow(ax, lat, lon, z, cmap , 'DisplayType', 'image')
Your description of the problem is not detailed. Is this what you want?
n = 100;
lat = rand(n, 1);
lon = rand(n, 1);
z = rand(n, 1);
figure
stem3(lon, lat, z);
xlabel('lon'); ylabel('lat'); zlabel('z');
  1 Comment
Deepshikha Dadhwal
Deepshikha Dadhwal on 22 Jul 2022
Hello Chunru,
I tried plotting TROPOMI data using the code you provided here but I am unable to store the data in the 'z' variable. TROPOMI data is originally in 2D format and I converted it into 1D to fit into the code.
I tried regridding with "Griddata" function as well but while going for coarser resolutions, the griddata function gives fewer and fewer data points. Both the codes are attached and the a single datafile could be downloaded from the following link as I could not attach my own due to size issues.
My aim is to regrid the data from original resolution to a desired resolution (ex. 2.5x2.5 degree) and count the number of data points falling per grid.

Sign in to comment.

More Answers (2)

Steven Lord
Steven Lord on 22 Jul 2022
My aim is to regrid the data from original resolution to a desired resolution (ex. 2.5x2.5 degree) and count the number of data points falling per grid.
Based on this comment you made on the answer by @Chunru I think you may not need or want to convert your data from a list of points to something approximating a grid. Instead I think you just need to call histogram2.
  1 Comment
Deepshikha Dadhwal
Deepshikha Dadhwal on 23 Jul 2022
Edited: Deepshikha Dadhwal on 23 Jul 2022
Hello Steven,
I used histogram2 function and I could count the number of datapoints within the specified equally no. of grids, but it only works when my desired no. of Latitude-Longitude coordinates are equal, but that still solves problem number 2 but problem no.1 still remains as
1.) I am not able to change the resolution in "Griddata" method, the coarser resolution gives fewer data points.
2.) Unable to store the same data using @Chunru's method.
Basically, if I could get the mean of the data falling into those grids, my problem would be solved.

Sign in to comment.


Bruno Luong
Bruno Luong on 23 Jul 2022
Edited: Bruno Luong on 23 Jul 2022
T = readtable('chiranjit Das DAY_1.xlsx');
A = table2array(T);
lat=A(:,1);
lon=A(:,2);
data=A(:,3);
longrid = -180:180;
latgrid = -90:90;
[~,~,~,i,j] = histcounts2(lat,lon,latgrid,longrid);
B = accumarray([i,j],data,[length(latgrid),length(longrid)]-1,@mean,NaN);
imagesc(longrid,latgrid,B);
  3 Comments
Deepshikha Dadhwal
Deepshikha Dadhwal on 23 Jul 2022
This is the data I am working on. I am attaching the code as well which I tried to run for it. (I did the griddata and the histogram2/histcounts2 separately).
I could count the no. of data points inside the grids using Histcounts2.
I could not
a) Regrid to a coarser resolution or
b) collect and take the mean in this case and count the data falling into those grids together in the same code.
Your code works well for 1D data that I work with but it seems to create errors while working with this data.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by