- Data Clipping: The temperature data is clipped to the range [283, 328] using max and min functions.
- Contour Plot: contourf is used with specified levels from 283 to 328.
- Color Limits: caxis ensures the colormap aligns with the specified temperature range.
- Colorbar and Labels: A colorbar is added for reference, and labels are set for clarity.
How do I set a temperature and/or colour range for a surface temperature map of WRF data?
8 views (last 30 days)
Show older comments
Hi there, I'm sorry if this is a silly question but I'm so stuck! I'm new to Matlab and am researching heat mitigation and am currently trying to create a surface temperature plot using data from the WRF model. I'm trying to produce a surface temperature model with this colour scheme;
I believe I have the right scheme, but I'm having trouble incrementing the colours properly. This is really important because we want to compare our model's surface temperature map with a surface temperature map from satellite data (made with code from our research partners). However, when I plot a surface temperature map of my model data, the colours seem to be very concentrated in the dark blue region except for one tiny spot, as seen below;
My guess is that the model may have one or two grid cells with abnormally high temperatures and that's throwing something off? So I wanted to limit my range to between 283 and 328 K, because that's the range of the satellite data surface temperature plot. This is my current code;
filename=('wrfout_d03_2018-07-03_12:00:00');
temp=ncread(filename, 'TSK');
longitude=ncread(filename, 'XLONG');
latitude=ncread(filename, 'XLAT');
mycolours = [0 0 168/255; 0 0 250/255; 0 52/255 1; 0 129/255 1; 0 200/255 1; 35/255 1 212/255; 93/255 1 154/255; 154/255 1 93/255; 212/255 1 35/255; 1 219/255 0; 1 148/255 0; 1 82/255 0; 250/255 15/255 0; 168/255 0 0]
colormap(mycolours);
contourf(longitude, latitude, temp, 283:328);
I'm not quite sure what I'm missing (or maybe I'm misdiagnosing the problem entirely?). I've also tried 283:3:328 in contourf and that didn't help either. I would appreciate any advice! Thank you!
0 Comments
Answers (1)
Abhinaya Kennedy
on 22 Aug 2024
% Load data
filename = 'wrfout_d03_2018-07-03_12:00:00';
temp = ncread(filename, 'TSK');
longitude = ncread(filename, 'XLONG');
latitude = ncread(filename, 'XLAT');
% Clip temperature data to the desired range
temp(temp < 283) = 283;
temp(temp > 328) = 328;
% Define custom colormap
mycolours = [0 0 168/255; 0 0 250/255; 0 52/255 1; 0 129/255 1; 0 200/255 1;
35/255 1 212/255; 93/255 1 154/255; 154/255 1 93/255; 212/255 1 35/255;
1 219/255 0; 1 148/255 0; 1 82/255 0; 250/255 15/255 0; 168/255 0 0];
colormap(mycolours);
% Define contour levels
contourLevels = 283:1:328;
% Plot with contourf
contourf(longitude, latitude, temp, contourLevels, 'LineColor', 'none');
colorbar; % Add a colorbar for reference
% Set color limits to match the data range
caxis([283 328]);
% Add labels and title
xlabel('Longitude');
ylabel('Latitude');
title('Surface Temperature (K)');
This should streamline your plotting process while ensuring the colors are mapped correctly to the temperature range.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!