Extract SST data in a polygon from average monthly netcdf file
8 visualizaciones (últimos 30 días)
Simbarashe Chidzambwa el 3 de Mzo. de 2023
I am trying to extract sst data from a netcdf file in a lat/lon polygon of 25:45S and 145-215E using a script below. I have attached the text file which I created ('sst2') from the original netcdf ('202210.sst.avg.nc') file because I could not upload the original netcdf file due to unaccepted file format. When I run the script I only get an empty cell "Poly = ". Can someone help please?
% Extract data
% Reshape data to be from 90N to 90S
idx=inpolygon(X,Y,[140 215],[25 45]);
poly = nanmean(sst2(idx));
%'poly' is empty with closing square bracket when the script is run.
Peter Perkins el 13 de Mzo. de 2023
Simbarashe, readtable and readmatrix read your file just fine, so I don't think that's the issue:
>> sst2 = readmatrix("sst2.txt");
Name Size Bytes Class Attributes
sst2 180x360 518400 double
You have not provided the lat and lon vectors, and I'm not really able to follow your code to glean what they are. But if what you want is the data in a rectangular subset of your data (that assumes it's on a rectangular grid in lat/lon space), I would think you can just use row/column indexing and skip the thing with meshgrid and inpolygon. Something like
-1.686 -1.6809 -1.6667 -1.6505 -1.6336 -1.6096 -1.574 -1.5394 -1.5111 -1.4503
>> nanmean(sst2(1:10,1:10),"all") % or maybe
But it's pretty hard to tell what you have. If the output of nanmean is really  as you say, then you have an issue with idx, which, as I said, seems like you can avoid that whole calculation.