필터 지우기
필터 지우기

Plot for Month and year

조회 수: 11 (최근 30일)
Ara
Ara 2024년 5월 29일
댓글: Ara 2024년 5월 29일
Dear All,
I have data with format of NETCDF file. I can read one of them and plot it. For each day I have many data so I wish to read all of them to provide result for one day and then expand it to provide it for month and year. Also, I would like to have a data in .mat format, for example for each month. Would you please help me in this regard?
Best,
Ara
  댓글 수: 3
Ara
Ara 2024년 5월 29일
I could not share the data as it mentioned the format is not accepted. Here is the link for data to provide a better view of it.
https://data.cosmic.ucar.edu/gnss-ro/cosmic2/provisional/spaceWeather/level2/2023/
Manikanta Aditya
Manikanta Aditya 2024년 5월 29일
Okay thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

Manikanta Aditya
Manikanta Aditya 2024년 5월 29일
편집: Manikanta Aditya 2024년 5월 29일
Hi, @Ara,
Based on the understanding from your explaination in the question, you can use some MATLAB functions and script for it.
Use can use the 'ncread' function: https://in.mathworks.com/help/matlab/ref/ncread.html
Check it out:
% Define paths to your NETCDF files
netcdfPath = 'path/to/netcdf/files/';
% Define output directory for processed data
outputDir = 'path/to/output/directory/';
% Loop through each NETCDF file
netcdfFiles = dir(fullfile(netcdfPath, '*.nc'));
for fileIdx = 1:numel(netcdfFiles)
% Read NETCDF file
ncFile = fullfile(netcdfPath, netcdfFiles(fileIdx).name);
% Read necessary data from NETCDF file (use appropriate commands for your data)
data = ncread(ncFile, 'variable_name');
% Process daily data (e.g., calculate daily averages)
dailyAverage = mean(data, 'all');
dailyDataFileName = fullfile(outputDir, ['daily_data_', datestr(netcdfFiles(fileIdx).datenum, 'yyyymmdd'), '.mat']);
save(dailyDataFileName, 'dailyAverage');
end
% Aggregate daily data to monthly
monthlyDataFileName = fullfile(outputDir, ['monthly_data_', datestr(netcdfFiles(fileIdx).datenum, 'yyyymm'), '.mat']);
save(monthlyDataFileName, 'monthlyData');
% Aggregate monthly data to yearly
yearlyDataFileName = fullfile(outputDir, ['yearly_data_', datestr(netcdfFiles(fileIdx).datenum, 'yyyy'), '.mat']);
save(yearlyDataFileName, 'yearlyData');
  • Consider this workaround script as a base and it should help you to start off.
I hope this gives you some help with your query!
  댓글 수: 7
Manikanta Aditya
Manikanta Aditya 2024년 5월 29일
To create a contour plot of Vertical Total Electron Content (VTEC) from the daily .mat files, you'll need to follow these steps:
  1. Load Data from .mat Files
  2. Interpolate and Contour Plot
% Define the path to your .mat files
matPath = 'path/to/output/directory/';
matFiles = dir(fullfile(matPath, 'daily_data_*.mat'));
% Initialize arrays to store the combined data
allLongitudes = [];
allLatitudes = [];
allVTEC = [];
% Loop through each .mat file and load the data
for fileIdx = 1:numel(matFiles)
% Load the daily data file
matFile = fullfile(matPath, matFiles(fileIdx).name);
data = load(matFile);
% Assuming the data structure contains longitudes, latitudes, and VTEC
longitudes = data.longitudes;
latitudes = data.latitudes;
VTEC = data.VTEC;
% Append the data to the combined arrays
allLongitudes = [allLongitudes; longitudes];
allLatitudes = [allLatitudes; latitudes];
allVTEC = [allVTEC; VTEC];
end
% Ensure all three arrays have the same length
minLength = min([length(allLongitudes), length(allLatitudes), length(allVTEC)]);
allLongitudes = allLongitudes(1:minLength);
allLatitudes = allLatitudes(1:minLength);
allVTEC = allVTEC(1:minLength);
% Create a meshgrid for longitude and latitude
[lonGrid, latGrid] = meshgrid(unique(allLongitudes), unique(allLatitudes));
% Interpolate VTEC onto the grid
VTEC_grid = griddata(allLongitudes, allLatitudes, allVTEC, lonGrid, latGrid, 'natural');
% Create the contour plot
figure;
contourf(lonGrid, latGrid, VTEC_grid);
colorbar;
title('Contour Plot of VTEC');
xlabel('Longitude (degrees)');
ylabel('Latitude (degrees)');
c = colorbar;
c.Label.String = 'VTEC (TECU)';
Ara
Ara 2024년 5월 29일
Thank you for the code and explanation.
I have to calculate VTEC from STEC. I have electron density that I need to read from NETCDF file and then convert it to VTEC. And then plot it as a contourplot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by