Create timeseries with 3d climate data

3 visualizaciones (últimos 30 días)
Paulemari van Aarde
Paulemari van Aarde el 3 de Mzo. de 2022
Comentada: Ronald el 8 de Abr. de 2024
Hi,
I have 3d climate data in the form lonxlatxtime. I would like to create a timeseries for these data for every year, but have no idea how to do this since I am new to Matlab. Can someone please assist?
Thank you

Respuestas (1)

Ayush
Ayush el 5 de Oct. de 2023
Hi Aarde,
I understand that you want to create time series of the 3D data points which is in the form longitude x latitude x time.
Since the data was not provided, I generated my own data points, which is of the dimension “1x2x12”. Meaning that there will be 1 row and 2 columns where first column will contain the data of the longitude and the second column will contain the data of the latitude and there are total of 12 years.
I randomly generated data of longitude and latitude using the “randi” command, keeping the range from 0 to 180 (representing degrees).
Considering that the data is ready with us, following steps can be used to display the data in timeseries:
  1. Extract the size of data using “[lon, lat, time] = size(climateData);”
  2. You can reshape the data as per your requirement with the following command: reshapedData = reshape(climateData, [[lon,lat], time]);. As the data I created was already in the format 1x2x12, the size of the reshapedData will remain same.
  3. Convert the time vector data to datetime format using: timeVector = datetime(timeVector);”
  4. Now you can use this time data to extract unique years or any other information. If you wish to extract unique years from the data you can use: “years = unique(year(timeVector));”
  5. To plot the created time series data use: “scatter3(x_lon,y_lat, timeVector)”. Where x_lon and y_lat contains the longitudes and latitudes respectively.
Final code snippet is given below:
%% Data Generation
lon = 1; % Number of longitudes
lat = 2; % Number of latitudes
time = 12; % Number of time steps
% Generate random climate data
climateData = randi([0 180],lon, lat, time);
% Display the size of the climate data
disp(size(climateData));
1 2 12
% Generate a random time vector
numTimeSteps = 12; % Number of time steps
% Generate random values for year, month, day, hour, minute, and second
yearValues = randi([2000, 2021], numTimeSteps, 1); % Random years between 2000 and 2021
monthValues = randi([1, 12], numTimeSteps, 1); % Random months
dayValues = randi([1, 28], numTimeSteps, 1); % Random days
hourValues = randi([0, 23], numTimeSteps, 1); % Random hours
minuteValues = randi([0, 59], numTimeSteps, 1); % Random minutes
secondValues = randi([0, 59], numTimeSteps, 1); % Random seconds
% Create the random time vector
timeVector = datetime(yearValues, monthValues, dayValues, hourValues, minuteValues, secondValues);
% Display the time vector
disp(timeVector);
25-Jan-2010 13:15:03 19-Jan-2006 01:54:28 19-Feb-2001 03:38:18 23-Sep-2020 22:37:13 26-Aug-2001 04:51:44 05-Apr-2018 10:04:07 04-Apr-2012 09:44:16 05-Jul-2003 10:43:36 08-Mar-2008 01:29:36 14-Apr-2009 15:29:15 24-May-2004 04:54:45 08-Sep-2008 10:49:39
%% Time Series Conversion
[lon, lat, time] = size(climateData);
reshapedData = reshape(climateData, [[lon,lat], time]);
timeVector = datetime(timeVector);
years = unique(year(timeVector));
disp("Unique year: " + years)
"Unique year: 2001" "Unique year: 2003" "Unique year: 2004" "Unique year: 2006" "Unique year: 2008" "Unique year: 2009" "Unique year: 2010" "Unique year: 2012" "Unique year: 2018" "Unique year: 2020"
%% Data Plotting
x_lon = squeeze(reshapedData(:,1,:));
y_lat = squeeze(reshapedData(:,2,:));
scatter3(x_lon,y_lat, timeVector)
  1 comentario
Ronald
Ronald el 8 de Abr. de 2024
Hi Ayush, could you modify this code so it can be used to reshape a 3D timeseries matrix(lon,lat,time) from daily to monthly? or from monthly to annual?

Iniciar sesión para comentar.

Categorías

Más información sobre Climate Science and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by