Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refreshing the MATLAB codes #17

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions matlab/RunLowtran.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
clear;

alt_km = 0;
zenithangle = [0, 60, 80];
%% Set parameters
% Units: distance in km, wavelength in nm, angle in degree
model = 5; % selects the geographical - seasonal model atmosphere
% 0: If meteorological data are specified (horizontal path only)
% 1: Tropical Atmosphere
% 2: Midlatitude Summer
% 3: Midlatitude Winter
% 4: Subarctic Summer
% 5: Subarctic Winter
% 6: 1976 US Standard
% 7: If a new model atmosphere (e.g. radiosonde data) is to be read in

p.model=5;
p.h1=alt_km;
p.angle=zenithangle;
p.wlshort= 200;
p.wllong=30000;

T = lowtran_transmission(p);
%% For a horizontal (constant-pressure) path
[wavelength_x, transmittance_y] = lowtran_horizaltrans(...
'model',model,...
'altitude',0,...
'transmission_distance',10,...
'wavelength_start',200,...
'wavelength_end',2000);
figure(1);
plot(wavelength_x, transmittance_y)
ylim([0,1])
xlabel('wavelength (nm)')
ylabel('transmittance')
title({'Horizontal transmittance at altitude 0 km'; ...
'with transmission distance of 10 km at subarctic winter.'})

plot_transmission(T)
%% For a vertical or slant path from a certain altitude to space
[wavelength_x, transmittance_y] = lowtran_groud2space(...
'model',model,...
'altitude',0,...
'zenith_angle',45,... % vector could work
'wavelength_start',200,...
'wavelength_end',2000);
figure(2);
plot(wavelength_x, transmittance_y)
ylim([0,1])
xlabel('wavelength (nm)')
ylabel('transmittance')
title({'Transmittance from altitude 0 km to space'; ...
'with zenith angle 45° at subarctic winter.'})
65 changes: 65 additions & 0 deletions matlab/lowtran_groud2space.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function [wavelength,transmittance] = lowtran_groud2space(varargin)
% Lowtran model from Matlab.
% Senario: a vertical or slant path from a certain altitude to space
% https://www.scivision.dev/matlab-python-user-module-import/
assert(~verLessThan('matlab', '9.5'), 'Matlab >= R2018b required')

%% Deal with input values
% Order of parameters and default values:
% 'model', 5;
% 'altitude', 0;
% 'zenith_angle', 45;
% 'wavelength_start', 200;
% 'wavelength_end', 2000;
occupy = [0,0,0,0,0];
for i = 1:length(varargin)
switch class(varargin{i})
case 'char'
if strcmp(varargin{i},'model')
model = varargin{i+1};
occupy(1) = 1;
elseif strcmp(varargin{i},'altitude')
altitude = varargin{i+1};
occupy(2) = 1;
elseif strcmp(varargin{i},'zenith_angle')
zenith_angle = varargin{i+1};
occupy(3) = 1;
elseif strcmp(varargin{i},'wavelength_start')
wavelength_start = varargin{i+1};
occupy(4) = 1;
elseif strcmp(varargin{i},'wavelength_end')
wavelength_end = varargin{i+1};
occupy(5) = 1;
end
end
end
if occupy(1) == 0
model = 0;
end
if occupy(2) == 0
altitude = 10;
end
if occupy(3) == 0
zenith_angle = 45;
end
if occupy(4) == 0
wavelength_start = 1;
end
if occupy(5) == 0
wavelength_end = 1;
end

%% Apply lowtran code
p.model = model;
p.h1 = altitude;
p.angle = zenith_angle;
p.wlshort = wavelength_start;
p.wllong = wavelength_end;

c1 = py.dict(p);
T = py.lowtran.transmittance(c1);
transmittance = squeeze(xarray2mat(T{'transmission'}));
transmittance = transmittance.';
wavelength = xarray2mat(T{'wavelength_nm'});

end
64 changes: 64 additions & 0 deletions matlab/lowtran_horizaltrans.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function [wavelength,transmittance] = lowtran_horizaltrans(varargin)
% Lowtran model from Matlab.
% Senario: a horizontal (constant-pressure) path
% https://www.scivision.dev/matlab-python-user-module-import/
assert(~verLessThan('matlab', '9.5'), 'Matlab >= R2018b required')

%% Deal with input values
% Order of parameters and default values:
% 'model', 5;
% 'initial_altitude', 0;
% 'transmission_distance', 10;
% 'wavelength_start', 200;
% 'wavelength_end', 2000;
occupy = [0,0,0,0,0];
for i = 1:length(varargin)
switch class(varargin{i})
case 'char'
if strcmp(varargin{i},'model')
model = varargin{i+1};
occupy(1) = 1;
elseif strcmp(varargin{i},'altitude')
altitude = varargin{i+1};
occupy(2) = 1;
elseif strcmp(varargin{i},'transmission_distance')
transmission_distance = varargin{i+1};
occupy(3) = 1;
elseif strcmp(varargin{i},'wavelength_start')
wavelength_start = varargin{i+1};
occupy(4) = 1;
elseif strcmp(varargin{i},'wavelength_end')
wavelength_end = varargin{i+1};
occupy(5) = 1;
end
end
end
if occupy(1) == 0
model = 0;
end
if occupy(2) == 0
altitude = 10;
end
if occupy(3) == 0
transmission_distance = 1;
end
if occupy(4) == 0
wavelength_start = 1;
end
if occupy(5) == 0
wavelength_end = 1;
end

%% Apply lowtran code
p.model = model;
p.h1 = altitude;
p.range_km = transmission_distance;
p.wlshort = wavelength_start;
p.wllong = wavelength_end;

c1 = py.dict(p);
T = py.lowtran.horiztrans(c1);
transmittance = squeeze(xarray2mat(T{'transmission'}));
wavelength = xarray2mat(T{'wavelength_nm'});

end
12 changes: 0 additions & 12 deletions matlab/lowtran_transmission.m

This file was deleted.

11 changes: 0 additions & 11 deletions matlab/plot_transmission.m

This file was deleted.