I'm trying to convert a 1 dimension lat,lon,data to 2d data . Is this possible?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DIPENDRA007
el 24 de Jul. de 2021
Editada: DIPENDRA007
el 29 de Oct. de 2022
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.
0 comentarios
Respuesta aceptada
Chunru
el 24 de Jul. de 2021
Editada: Chunru
el 25 de Jul. de 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 comentario
Deepshikha Dadhwal
el 22 de Jul. de 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.
Más respuestas (2)
Steven Lord
el 22 de Jul. de 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 comentario
Deepshikha Dadhwal
el 23 de Jul. de 2022
Editada: Deepshikha Dadhwal
el 23 de Jul. de 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.
Basically, if I could get the mean of the data falling into those grids, my problem would be solved.
Bruno Luong
el 23 de Jul. de 2022
Editada: Bruno Luong
el 23 de Jul. de 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 comentarios
Bruno Luong
el 23 de Jul. de 2022
Editada: Bruno Luong
el 23 de Jul. de 2022
Nah the plot is flipped by default when using imagesc, you only need to call
set(gca,'YDir','normal')
This is only visual. The underline data is correct, meaning bin i=1 corrspond to (-90,-89), etc...
I did not (and sillt do not) read what you wrote before sorry.
Deepshikha Dadhwal
el 23 de Jul. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!