Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Final Lab 2
- Loading branch information
Youssef EL_Dieb
committed
Jun 24, 2021
1 parent
9febaac
commit 598ef0ea846a4e1239a3ddfc1ef477c8a4061516
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
%% This script allows you to open and explore the data in a *.nc file | |||
clear all | |||
close all | |||
|
|||
FileName = 'o3_surface_20180701000000.nc'; | |||
|
|||
Contents = ncinfo(FileName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
|
|||
function [AllDataMem] = LoadAllData(FileName) | |||
%UNTITLED2 Summary of this function goes here | |||
% Detailed explanation goes here | |||
ExploreData; | |||
fprintf('Data Dimension Names: %s, %s, %s\n',... | |||
Contents.Dimensions(1).Name,... | |||
Contents.Dimensions(2).Name,... | |||
Contents.Dimensions(3).Name) | |||
Contents = ncinfo(FileName); % Store the file content information in a variable. | |||
for idx = 1: 8 | |||
AllData(idx,:,:,:) = ncread(FileName, Contents.Variables(idx).Name); | |||
fprintf('Loading %s\n', Contents.Variables(idx).Name); | |||
% display loading information | |||
end | |||
|
|||
AllDataMem = whos('AllData').bytes/1000000; | |||
fprintf('Memory used for all data: %.3f MB\n', AllDataMem) | |||
end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
%% Selecting data | |||
% We want to load models only, i.e. variables 1, 2, 4, 5, 6, 7, 8 | |||
% and we only want a single hour. We use indexing into our *.nc file: | |||
% To load the variable 'chimere_ozone, starting at lat = 1, lon = 1 and | |||
% hour = 1 we use: | |||
[AllHourMem] = LoadAllHour(FileName); | |||
function [AllHourMem] = LoadAllHour(FileName) | |||
%UNTITLED2 Summary of this function goes here | |||
% Detailed explanation goes here | |||
ExploreData; | |||
StartLat = 1; | |||
NumLat = 400; | |||
StartLon = 1; | |||
NumLon = 700; | |||
StartHour = 1; | |||
NumHour = 1; | |||
|
|||
Data = ncread(FileName, 'chimere_ozone', [StartLon, StartLat, StartHour], [NumLon, NumLat, NumHour]); | |||
|
|||
Contents = ncinfo(FileName); % Store the file content information in a variable. | |||
for idx = 1 | |||
AllHour(idx,:,:,:) = ncread(FileName, 'chimere_ozone', [StartLon, StartLat, StartHour], [NumLon, NumLat, NumHour]); | |||
fprintf('', [StartLon, StartLat, StartHour], [NumLon, NumLat, NumHour]); | |||
% display loading information | |||
end | |||
|
|||
AllHourMem = whos('AllHour').bytes/1000000; | |||
fprintf('Memory used for all data: %.3f MB\n', AllHourMem) | |||
end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
%% List variable names | |||
% note that variable 3 is an ensemble, we will NOT use this in our project! | |||
% Not each model is 700 x 400 x 12 and we know that lat, lon and time match | |||
% these numbers. | |||
% To visulaise this 3D array think of it as a 700 x 400 grid for each model | |||
% for one hour. These are stacked up 25 high. | |||
|
|||
function [AllHorsMem] = LoadAllHors(FileName) | |||
%UNTITLED2 Summary of this function goes here | |||
% Detailed explanation goes here | |||
ExploreData; | |||
Contents = ncinfo(FileName); | |||
NumVariables = size(Contents.Variables,2); | |||
fprintf('Variable names and sizes:\n') | |||
for idx = 1: NumVariables | |||
AllHors(idx,:,:,:) = size(Contents.Variables,2); | |||
fprintf('%i %s %i, %i, %i',... | |||
idx, Contents.Variables(idx).Name, Contents.Variables(idx).Size); | |||
fprintf('\n'); | |||
end | |||
AllHorsMem = whos('AllHors').bytes/1000000; | |||
fprintf('Memory used for Hour: %.3f MB\n', AllHorsMem) | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
|
|||
%LoadHours; | |||
%LoadAllHours; | |||
%ReportResults; | |||
[AllDataMem] = LoadAllData(FileName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
%% Cycling through the variable names | |||
% We only want the models to load | |||
|
|||
[ResultsMem] = Results(FileName); | |||
function [ResultsMem] = Results(FileName) | |||
%UNTITLED2 Summary of this function goes here | |||
% Detailed explanation goes here | |||
ExploreData; | |||
Contents = ncinfo(FileName); % Store the file content information in a variable. | |||
for idx = [1, 2, 4, 5, 6, 7, 8] | |||
%Result(idx) = ncread(Contents.Variables(idx).Name); | |||
fprintf('Model %i : %s\n', idx, Contents.Variables(idx).Name); | |||
end | |||
end |