Creating arrays based on NetCDF files

I'm working on a code that creates an array type (nlines, ncolumns, nfiles) with nfiles equal to the number of grids that it has ( k = 1:nfiles), after that I need to calculate the estatistics for each grid, for each value of K, and the statistics for each pixel. Then I need to calculate the average to each pixel e then create a grid to represent the averages of the values.

21 Comments

So, what's the question?
My impression is that OP is informing us of his objective, and will let us know how it turns out!
sorry the question was not well formulated
I dont know how to aproach an array because I have a code that runs and I get the outputs but i dont know how to compile them in an array by pixel average .
my former questions are related to this topic, this question is related to the one that I asked for help 2 weeks ago if I´m not mistaken.
Well, it must not have been well formed either, then, if it got no answers.
We can't answer what isn't asked nor explained, the Crystal Ball Toolbox has yet to be released.
English is not my first language so I'm having trouble putting into words what I want.
I made an array based on longitude, latitude and time if I post it can you give some pointers or indicate me on whether the array was created correctly or not?
We can try, certainly. But, we need as precise a description of the result you're looking for and what you have to start with. If that is a NetCDF file, then we need you to attach it (preferably it is a small(ish) example that illustrates, not a huge one).
Then, probably the easiest way to combat the language barrier is to actually show us from the input what it is that you're trying to create as output, and more importantly, the "HOW/WHY" of why the result is what it is.
I´ll try to sumarise what I need
I'm doing a study on the GRACE mission from NASA and I'm studying the water thickness on a global scale, basically Im researching the changes in water mass on land of the entire time period for the mentioned mission (from 2002-2017) and I was tasked with doing an array or by my coordinator words a "cube" which involves the lon, lat, time encompassing the the average for lwe(water thickness) for each pixel throughout the entire duration of the mission.
Ill attach one NetCDF file of the type of files Im dealing with.
I was able to make the array so now how can I create a plot for this array?
load pixel_media.mat
whos
Name Size Bytes Class Attributes ans 1x79 158 char cmdout 1x33 66 char pixel_media 1x360x180 518400 double
pixel_media=squeeze(pixel_media);
imagesc(pixel_media)
figure
imagesc(pixel_media.')
Well, that's not what you're wanting, either, it would seem! :)
figure
imagesc(pixel_media.')
hAx=gca; hAx.YDir='normal';
Something like that, maybe?
To compute statistics, presuming all the files are over the same coordinates and the same resolution, you'd just create the 3D array of each observation a plane (how many of them are there, you may run into memory issues and need to see about memory saving or other techniques than holding everything in memory at one time); then to compute statistics simply use the optional 'dim' argument for the various statistical functions like mean to operate over the 3rd dimension. "Piece o' cake!" :)
BTW, your English comprehension and grammar seem just fine to me -- far better than my abilities in your native language would be, for sure!
YES this is exactly what I need i just need to switch the x and y axis
And the colormap.
Thank you very much.
dpb
dpb on 15 Aug 2023
Edited: dpb on 15 Aug 2023
NOTA BENE: In MATLAB images go from top LH corner down so to flip the display vertically, set the y-axis direction from bottom up as for an "ordinary" graph instead.
For real, you'll undoubtedly want to use the imagesc(x,y,C) form where x,y are the latitude/longitude associated with the image in order to display on actual coordinates instead of against pixel number.
but the coordinates are correct, they may not be centered but they are correct, is that your worry or I'm getting it wrong and not understading what you mean?
figure(2);
x_valor = 1:size(pixel_media, 2);
y_valor = 1:size(pixel_media, 3);
clevv=-0.5:0.1:0.2;
v = imagesc(x_valor, y_valor, squeeze(pixel_media(1, :, :)));
hAx=gca;
hAx.YDir='normal';
clim([min(clevv), max(clevv)]);
colorbar('eastoutside');
colormap(winter(length(clevv)-1));
figura_1 = fullfile(output, strcat(nome_final, '.png'));
saveas(gca, figura_1);
tried this code but the image still doesnt rotate
and also I want values that are not representated in the clevv to have another color
more especificaly the values for the sea water and NaN
the axis are corrected but the image itself isnt I dont seem to understand the problem
_"... the coordinates are correct, ..."
You sure about that?
load pixel_media.mat
pixel_media=squeeze(pixel_media).'; % go ahead and transpose the data
imagesc(pixel_media)
hAx=gca; hAx.YDir='normal';
[xlim ylim]
ans = 1×4
0.5000 360.5000 0.5000 180.5000
You observe that imagesc scales the image to a midpoint between each pixel, not the actual latitude/longitude of the data points in the array. That the array size happens to be 180 x 360 is just fortuitous matchup to the numbers you expected although the latitude not being centered is unusual representation I'd think in any presentation.
Try
pixel_media=flipud(pixel_media); % flip the latitude direction to match MATLAB image
lat=linspace(-180,180,size(pixel_media,1));
lon=linspace(0,360,size(pixel_media,2));
imagesc(lon,lat,pixel_media)
xlim([lon(1) lon(end)]), ylim([lat(1) lat(end)])
xticks(linspace(lon(1),lon(end),9)), yticks(linspace(lat(1),lat(end),7))
I understand whats you mean now
I need to chnage the lon to a limit [-180;180] and the latitude [-90,90]
I had a code that ran perfectly but trying to merge the xticks and yticks bugged out the code and it doesnt work anymore.
Yeah, my foohpah on the latitude range; was just typing, not thinking.
I dunno where you want the origin to be for longitude; is the present 0 on Greenwich, maybe? Looks like it could be chosen that way is why I left it at 0.
I hadn't seen the plaint about colormap until now; there's where I'm at the limits of my image processing; I've never fully figured out how to neatly manipulate them to do special things; the default with imagesc scales the data over the range linearly.
I think to change the sea color you need to change its value if stay with indexed colors. Limiting the colormap to a range just causes points outside those to be max'ed out at one or the other end.
i got the image with the ocean color being null basically the only problem that im having is merging the code you made with mine so that the xticks works ill send the my base code
I managed to found by chance something thats transforms the values to NaN values but to be honest I still dont understand how it fully works.

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Asked:

on 13 Aug 2023

Commented:

on 15 Aug 2023

Community Treasure Hunt

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

Start Hunting!