Formatting rainfall grid data

1 Ansicht (letzte 30 Tage)
Nikhil Sumer
Nikhil Sumer am 8 Jun. 2016
Beantwortet: BhaTTa am 29 Aug. 2024
I have daily rainfall grid data for the whole year lets say 2013. But the original file was in binary and i have converted into ascii text and then to excel. But still i need to format the data.The data for each day is in form of India's map where each cell represents particular coordinates. Data outside the map outline is null (-999). So i want to extract the data for the whole year for a specific coordinates. Please help.

Antworten (1)

BhaTTa
BhaTTa am 29 Aug. 2024
Hey @Nikhil Sumer, to extract daily rainfall data for a specific set of coordinates from your grid data, you can follow these steps in MATLAB. This process involves reading the data from your Excel file, identifying the correct grid cell that corresponds to the desired coordinates, and then extracting the data for that cell across all days.
% Define the coordinates of interest
targetLatitude = 23.5; % Example latitude
targetLongitude = 77.0; % Example longitude
% Load the grid data from Excel
filename = 'rainfall_data_2013.xlsx';
sheet = 1; % Assuming all data is in the first sheet
data = readmatrix(filename, 'Sheet', sheet);
% Define grid resolution and boundaries
% These should match your dataset's specifics
latRange = [6.0, 37.0]; % Example latitude range for India
lonRange = [68.0, 97.0]; % Example longitude range for India
numLatCells = 31; % Number of latitude grid cells
numLonCells = 29; % Number of longitude grid cells
% Calculate the size of each grid cell
latCellSize = (latRange(2) - latRange(1)) / numLatCells;
lonCellSize = (lonRange(2) - lonRange(1)) / numLonCells;
% Find the index of the target grid cell
latIndex = floor((targetLatitude - latRange(1)) / latCellSize) + 1;
lonIndex = floor((targetLongitude - lonRange(1)) / lonCellSize) + 1;
% Initialize a vector to store extracted data
extractedData = [];
% Loop through each day's data
numDays = size(data, 1) / (numLatCells * numLonCells); % Assuming data is stacked
for day = 1:numDays
% Extract the grid data for the current day
dayData = data((day-1)*numLatCells*numLonCells+1 : day*numLatCells*numLonCells, :);
% Reshape the day's data into a 2D grid
dayGrid = reshape(dayData, numLatCells, numLonCells);
% Extract the data for the target coordinates
value = dayGrid(latIndex, lonIndex);
% Check if the value is valid (not null)
if value ~= -999
extractedData(end+1) = value; % Append the value to the extracted data
else
extractedData(end+1) = NaN; % Use NaN for null values
end
end
% Display the extracted data
disp('Extracted Rainfall Data for Target Coordinates:');
disp(extractedData);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by