%Generate time series from NCAR high-resolution model. Can be adapted to %work with other NCAR model output fairly easily. %Total precipitation output started on March 1 of model year 45 and %continued through year 75 or so; I used the years 46-65 for the time %period to look at. year = 46; %% %Latitude and longitude ranges. Longitude is in 0-360 east format (only generatePowerSpectra will convert % west degrees if that is input to it; other functions need to use the natively recognized values) coordBox = [22 27 320 325; 7 12 233 238]; %% filename = strcat("CESM-NCAR_HR/precip", int2str(year), ".nc"); %% %I'm not exactly sure how the grid used in the model was developed. It's a vector of %points instead of a latitude/longitude matrix - easiest way to find %anything is just to use Matlab logicals to very quickly go through arrays %and see which points meet all required criteria. latitudes = ncread(filename, "lat"); longitudes = ncread(filename, "lon"); cells = []; s = size(coordBox); for row=1:s(1) LatLog = (latitudes >= coordBox(row, 1)) & (latitudes <= coordBox(row, 2)); LonLog = (longitudes >= coordBox(row, 3)) & (longitudes <= coordBox(row, 4)); locations = LatLog & LonLog; c = find(locations); c = rot90(c); if (size(cells) == 0) cells = c; else cells = horzcat(cells, c); end end % load("Integrals/NCARMappingData.mat", "NCARGridToVector"); % %Make the vector horizontal to line up with what generatePowerSpectra % %expects. % %cells = rot90(rot90(rot90(cells))); % % cells = zeros(259920, 1); % cIndex = 0; % for gridRow = 1:361 % cells(cIndex + 1:cIndex + 720) = NCARGridToVector(gridRow, :); % cIndex = cIndex + 720; % end %% numPoints = size(cells); numPoints = numPoints(2); precipVals2 = zeros(numPoints, 7300); %Take in each year of precipitation at a time, and place this into %precipVals. Logicals are much simpler than doing things in lots of for %loops. while year < 66 year index = 365 * (year - 46); filename = strcat("CESM-NCAR_HR/precip", int2str(year), ".nc"); precipitation = ncread(filename, "PRECT"); precipitation = precipitation * 3600000; precipVals2(:, 1+index:365+index) = precipitation(cells, :); year = year + 1; end %% %Save to .mat files. for point=1:numPoints ref = int2str(cells(point)); precipVals = precipVals2(point, :); precipVals = rot90(rot90(rot90(precipVals))); save(strcat("timeseries_NCARHR/", ref), 'precipVals'); if (mod(point, 1000) == 0) point end end