|
| 1 | +function [iono_struct, general_struct] = gen_iono_ns(UT) |
| 2 | +% Name: |
| 3 | +% gen_iono_ns |
| 4 | +% |
| 5 | +% Author: |
| 6 | +% Kyle Ruzic |
| 7 | +% |
| 8 | +% Date: |
| 9 | +% August 24th 2018 |
| 10 | +% |
| 11 | +% Purpose: |
| 12 | +% This program is largely |
| 13 | +% based on the beginning of this PHaRLAP example, |
| 14 | +% "ray_test_3d_sp.m" The purpose of this is to generate a IRI |
| 15 | +% ionospheric grid, that is used by PHaRLAP to calculate the |
| 16 | +% path of the rays. A version of this also exists that saves |
| 17 | +% the generated ionosphere which allows for it to be easily |
| 18 | +% reloaded to prevent having to regenerate it every time you |
| 19 | +% make a new model for the same date and time. |
| 20 | +% |
| 21 | +% Inputs: |
| 22 | +% UT - Vector containing date and time information, must be |
| 23 | +% formatted like [YYYY MM DD HH MM] |
| 24 | +% |
| 25 | +% Outputs: |
| 26 | +% iono_struct |
| 27 | +% .pf_grid - 3d grid (height vs lat. vs lon.) of ionospheric plasma |
| 28 | +% frequency (MHz) |
| 29 | +% .pf_grid_5 - 3d grid (height vs lat. vs lon.) of ionospheric plasma |
| 30 | +% frequency (MHz) 5 minutes later |
| 31 | +% .collision_freq - 3d grid (height vs lat. vs lon.) of ionospheric |
| 32 | +% collision frequencies |
| 33 | +% .Bx - 3d grid of x component of geomagnetic field |
| 34 | +% .By - 3d grid of y component of geomagnetic field |
| 35 | +% .Bz - 3d grid of z component of geomagnetic field |
| 36 | +% |
| 37 | +% .iono_grid_parms - 9x1 vector containing the parameters which define the |
| 38 | +% |
| 39 | +% ionospheric grid : |
| 40 | +% (1) geodetic latitude (degrees) start |
| 41 | +% (2) latitude step (degrees) |
| 42 | +% (3) number of latitudes |
| 43 | +% (4) geodetic longitude (degrees) start |
| 44 | +% (5) lonitude step (degrees) |
| 45 | +% (6) number of longitudes |
| 46 | +% (7) geodetic height (km) start |
| 47 | +% (8) height step (km) |
| 48 | +% (9) number of heights |
| 49 | +% |
| 50 | +% .geomag_grid_parms - 9x1 vector containing the parameters which define the |
| 51 | +% |
| 52 | +% geomagnetic grid : |
| 53 | +% (1) geodetic latitude (degrees) start |
| 54 | +% (2) latitude step (degrees) |
| 55 | +% (3) number of latitudes |
| 56 | +% (4) geodetic lonitude (degrees) start |
| 57 | +% (5) lonitude step (degrees) |
| 58 | +% (6) number of longitudes |
| 59 | +% (7) geodetic height (km) start |
| 60 | +% (8) height step (km) |
| 61 | +% (9) number of heights |
| 62 | +% |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +if ~exist('minute', 'var') |
| 70 | + minute = 0; |
| 71 | +end |
| 72 | + |
| 73 | +UT = UT |
| 74 | +speed_of_light = 2.99792458e8; |
| 75 | +re = 6376000; % Radius of Earth in m |
| 76 | +R12 = 100; |
| 77 | +origin_lat = 52.16; % Location of SuperDARN saskatoon |
| 78 | +origin_long = -106.52; |
| 79 | +origin_ht = 0.0; |
| 80 | +doppler_flag = 1; |
| 81 | + |
| 82 | +%ionospheric grid setup |
| 83 | + |
| 84 | +ht_start = 50; % start height for ionospheric grid (km) |
| 85 | +ht_inc = 6; % height increment (km) |
| 86 | +num_ht = 301.0; |
| 87 | +lat_start = 30.0; |
| 88 | +lat_inc = 0.086; |
| 89 | +num_lat = 701.0; |
| 90 | +lon_start= -156.0; |
| 91 | +lon_inc = 0.15; |
| 92 | +num_lon = 701.0; |
| 93 | +iono_grid_parms = [lat_start, lat_inc, num_lat, lon_start, lon_inc, num_lon, ... |
| 94 | + ht_start, ht_inc, num_ht]; |
| 95 | + |
| 96 | +B_ht_start = ht_start; % start height for geomagnetic grid (km) |
| 97 | +B_num_ht = 201; %ceil(num_ht * ht_inc/B_ht_inc); % Max that can be used is 201 |
| 98 | +B_ht_inc = (ht_inc*(num_ht-1))/(B_num_ht-1); % height increment (km) |
| 99 | +B_lat_start = lat_start; |
| 100 | +B_num_lat = 101; % max value that can be used is 101 |
| 101 | +B_lat_inc = (lat_inc*(num_lat-1))/(B_num_lat-1); |
| 102 | +B_lon_start = lon_start; |
| 103 | +B_num_lon = 101; % max value that can be used is 101 |
| 104 | +B_lon_inc = (lon_inc*(num_lon-1))/(B_num_lon-1); |
| 105 | +geomag_grid_parms = [B_lat_start, B_lat_inc, B_num_lat, B_lon_start, ... |
| 106 | + B_lon_inc, B_num_lon, B_ht_start, B_ht_inc, B_num_ht]; |
| 107 | + |
| 108 | + |
| 109 | +% this block of code ensures that the size of both the iono_grid |
| 110 | +% and geomagnetic grid are equal |
| 111 | + |
| 112 | +kill = false; % if they aren't equal terminate the program and print |
| 113 | + % an error message |
| 114 | +if (B_ht_start + (B_num_ht-1)*B_ht_inc) ~= (ht_start + (num_ht-1)*ht_inc) |
| 115 | + kill = true; |
| 116 | + fprintf("Inconsistently sized Magnetic and Ionospheric grids (height)"); |
| 117 | + tot_B_height = (B_ht_start + (B_num_ht-1)*B_ht_inc) |
| 118 | + tot_iono_height = (ht_start + (num_ht-1)*ht_inc) |
| 119 | +elseif (B_lat_start + (B_num_lat-1)*B_lat_inc) ~= (lat_start + (num_lat-1)*lat_inc) |
| 120 | + kill = true; |
| 121 | + fprintf("Inconsistently sized Magnetic and Ionospheric grids (lat)"); |
| 122 | + tot_B_lat = (B_lat_start + (B_num_lat-1)*B_lat_inc) |
| 123 | + tot_iono_lat = (lat_start + (num_lat-1)*lat_inc) |
| 124 | +elseif (B_lon_start + (B_num_lon-1)*B_lon_inc) ~= (lon_start + (num_lon-1)*lon_inc) |
| 125 | + kill = true; |
| 126 | + fprintf("Inconsistently sized Magnetic and Ionospheric grids (lon)"); |
| 127 | + tot_B_lon = (B_lon_start + (B_num_lon-1)*B_lon_inc) |
| 128 | + tot_iono_lon = (lon_start + (num_lon-1)*lon_inc) |
| 129 | +end |
| 130 | + |
| 131 | +if kill |
| 132 | + fprintf('Size mismatch of iono and geomagnetic grids') |
| 133 | + return |
| 134 | +end |
| 135 | + |
| 136 | +%Generates the model ionosphere |
| 137 | +tic |
| 138 | +fprintf('Generating ionospheric and geomag grids... ') |
| 139 | +[iono_pf_grid, iono_pf_grid_5, collision_freq, Bx, By, Bz] = ... |
| 140 | + gen_iono_grid_3d(UT, R12, iono_grid_parms, ... |
| 141 | + geomag_grid_parms, doppler_flag, 'iri2016'); |
| 142 | +toc |
| 143 | +fprintf('\n') |
| 144 | + |
| 145 | +%Creates a structure with the outputs |
| 146 | + |
| 147 | +iono_struct.pf_grid = iono_pf_grid; |
| 148 | +iono_struct.pf_grid_5 = iono_pf_grid_5; |
| 149 | +iono_struct.collision_freq = collision_freq; |
| 150 | +iono_struct.Bx = Bx; |
| 151 | +iono_struct.By = By; |
| 152 | +iono_struct.Bz = Bz; |
| 153 | +iono_struct.iono_grid_parms = iono_grid_parms; |
| 154 | +iono_struct.geomag_grid_parms = geomag_grid_parms; |
| 155 | + |
| 156 | + |
0 commit comments