Home > atmlab > arts_usage > qarts_add_fascode.m

qarts_add_fascode

PURPOSE ^

QARTS_ADD_FASCODE Includes a Fascode atmosphere

SYNOPSIS ^

function Q = qarts_add_fascode( A, Q, workfolder )

DESCRIPTION ^

 QARTS_ADD_FASCODE   Includes a Fascode atmosphere

  Expands Q to import one of the five Fasoce atmospheres. These atmospheres
  are named as 'tropical', 'midlatitude-summer', 'midlatitude-winter',
  'subarctic-summer' and 'subarctic-winter'.

  Q.ATMSOPHERE_DIM must be set, and can be 1, 2 or 3. Fields of Q set by 
  the function are P_GRID, LAT_GRID (only 2D and 3D), LON_GRID (only 3D), 
  Z_FIELD, T_FIELD, VMR_FIELD, ABS_SPECIES and HSE (set to to true).
  Further, LAT_TRUE is set (if not 3D) to a value representating the
  Fascode atmosphere, and if not already set LON_TRUE is set to zero.

  The P_GRID set reaches about 95 km. LAT/LON_TRUE are set to representative
  values for the selected atmosphere. For 3D, LON_GRID is set to cover the
  complete planet ([-180,180], can be modfified by *A.lon0*). For 2D and 3D,
  LAT_GRID is set to cover pole to pole, with a spacing of 5 degrees. T_FIELD
  and VMR_FIELD have no latitudinal variation, but a latitude grid is required
  to capture the variation in Z_FIELD originating from the constrain of HSE.
  Note that LAT_GRID can be controlled cropped by *A.lat_min* and *A.lat_max*.

  Ionospheric data can be included where the IRI (free electrons) and IGRF
  (magnetic fields) data found in arts_xml-data are used. This part is
  triggered by setting A.ionosphere to true. See further optional fields
  listed below. Settings like p_min applies also to this part. Data of free
  electrons are included only if 'free_electrons' is part of ABS_SPECIES.
  THe electron content is set to zero for the highest altitude, to ensure a
  gradual transition to n=1.

  Free electron content is set to zero if A.ionosphere is false.

  The mandatory fields of A are
   'fascode_atm' : String with name of atmosphere, eg. 'tropical'.
   'ABS_SPECIES' : These data are copied to Q.ABS_SPECIES. 
   
  Optional fields are
   'p_min'     : Crop P_GRID at this value. Lower values are rejected.
   'lat_min'   : Crop LAT_GRID at this value. Lower values are rejected.
   'lat_min'   : Crop LAT_GRID at this value. Higher values are rejected.
   'lon0'      : Focus LON_GRID on this value, ie. LON_GRID = 
                 A.lon0 + [-180,180] 
   'ionosphere': Flag to include ionospheric data. Default is false.
   'igrf_year' : IGRF data year, where the options are 1980, 1990, 2000 
                 and 2010. 
   'iri_sun'   : Solar state to consider for IRI. Options are 'min' and 'max'.
   'iri_season': Season to consider for IRI. Options are 'spring', 'summer',
                 'fall' and 'winter'.
   'iri_utc'   : UTC to consider for IRI. Options are 0:3:21.

 Bad choice for any IGRF and IRI settings will result in an error of the
 type "file not found".  

 FORMAT Q = qarts_add_fascode( A, Q, workfolder )

 OUT   Q          Modified Q
 IN    A          Atmosphere structure, see above.
       Q          Original Q
       workfolder Path to workfolder (not used, but an input is demanded)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

qarts_add_fascode.m

SOURCE CODE ^

0001 % QARTS_ADD_FASCODE   Includes a Fascode atmosphere
0002 %
0003 %  Expands Q to import one of the five Fasoce atmospheres. These atmospheres
0004 %  are named as 'tropical', 'midlatitude-summer', 'midlatitude-winter',
0005 %  'subarctic-summer' and 'subarctic-winter'.
0006 %
0007 %  Q.ATMSOPHERE_DIM must be set, and can be 1, 2 or 3. Fields of Q set by
0008 %  the function are P_GRID, LAT_GRID (only 2D and 3D), LON_GRID (only 3D),
0009 %  Z_FIELD, T_FIELD, VMR_FIELD, ABS_SPECIES and HSE (set to to true).
0010 %  Further, LAT_TRUE is set (if not 3D) to a value representating the
0011 %  Fascode atmosphere, and if not already set LON_TRUE is set to zero.
0012 %
0013 %  The P_GRID set reaches about 95 km. LAT/LON_TRUE are set to representative
0014 %  values for the selected atmosphere. For 3D, LON_GRID is set to cover the
0015 %  complete planet ([-180,180], can be modfified by *A.lon0*). For 2D and 3D,
0016 %  LAT_GRID is set to cover pole to pole, with a spacing of 5 degrees. T_FIELD
0017 %  and VMR_FIELD have no latitudinal variation, but a latitude grid is required
0018 %  to capture the variation in Z_FIELD originating from the constrain of HSE.
0019 %  Note that LAT_GRID can be controlled cropped by *A.lat_min* and *A.lat_max*.
0020 %
0021 %  Ionospheric data can be included where the IRI (free electrons) and IGRF
0022 %  (magnetic fields) data found in arts_xml-data are used. This part is
0023 %  triggered by setting A.ionosphere to true. See further optional fields
0024 %  listed below. Settings like p_min applies also to this part. Data of free
0025 %  electrons are included only if 'free_electrons' is part of ABS_SPECIES.
0026 %  THe electron content is set to zero for the highest altitude, to ensure a
0027 %  gradual transition to n=1.
0028 %
0029 %  Free electron content is set to zero if A.ionosphere is false.
0030 %
0031 %  The mandatory fields of A are
0032 %   'fascode_atm' : String with name of atmosphere, eg. 'tropical'.
0033 %   'ABS_SPECIES' : These data are copied to Q.ABS_SPECIES.
0034 %
0035 %  Optional fields are
0036 %   'p_min'     : Crop P_GRID at this value. Lower values are rejected.
0037 %   'lat_min'   : Crop LAT_GRID at this value. Lower values are rejected.
0038 %   'lat_min'   : Crop LAT_GRID at this value. Higher values are rejected.
0039 %   'lon0'      : Focus LON_GRID on this value, ie. LON_GRID =
0040 %                 A.lon0 + [-180,180]
0041 %   'ionosphere': Flag to include ionospheric data. Default is false.
0042 %   'igrf_year' : IGRF data year, where the options are 1980, 1990, 2000
0043 %                 and 2010.
0044 %   'iri_sun'   : Solar state to consider for IRI. Options are 'min' and 'max'.
0045 %   'iri_season': Season to consider for IRI. Options are 'spring', 'summer',
0046 %                 'fall' and 'winter'.
0047 %   'iri_utc'   : UTC to consider for IRI. Options are 0:3:21.
0048 %
0049 % Bad choice for any IGRF and IRI settings will result in an error of the
0050 % type "file not found".
0051 %
0052 % FORMAT Q = qarts_add_fascode( A, Q, workfolder )
0053 %
0054 % OUT   Q          Modified Q
0055 % IN    A          Atmosphere structure, see above.
0056 %       Q          Original Q
0057 %       workfolder Path to workfolder (not used, but an input is demanded)
0058 
0059 % 2013-09-29   Created by Patrick Eriksson.
0060 
0061 function Q = qarts_add_fascode( A, Q, workfolder )
0062 %
0063 rqre_datatype( A, { @isstruct } );
0064 rqre_datatype( Q, { @isstruct } );
0065 rqre_datatype( workfolder, { @ischar,@isempty } );
0066 
0067 
0068 arts_xmldata_path       = atmlab( 'ARTS_XMLDATA_PATH' );
0069 if isnan( arts_xmldata_path )
0070   error('You need to set ARTS_XMLDATA_PATH to use this function.');
0071 end
0072 
0073 if ~qarts_isset( Q.ATMOSPHERE_DIM )
0074   error( 'Q.ATMOSPHERE_DIM must be set.' );
0075 end
0076 
0077 
0078 switch lower( A.fascode_atm )
0079   
0080  case 'tropical'  
0081   Q.LAT_TRUE = 10;
0082  case 'midlatitude-summer'  
0083   Q.LAT_TRUE = 45;
0084  case 'midlatitude-winter'  
0085   Q.LAT_TRUE = 45;
0086  case 'subarctic-summer'  
0087   Q.LAT_TRUE = 75;
0088  case 'subarctic-winter'  
0089   Q.LAT_TRUE = 75;
0090  otherwise
0091   error( 'Unrecognised choice for *A.fascode_atm* (%s).', A.fascode_atm );
0092 end
0093 %
0094 if ~qarts_isset( Q.LON_TRUE )
0095   Q.LON_TRUE = 0;
0096 end
0097   
0098 
0099 % Use z as reference for p_grid
0100 %
0101 R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'Fascod', ...
0102                                    A.fascode_atm, [A.fascode_atm,'.z.xml'] ) );
0103 %
0104 Q.P_GRID  = vec2col( R.grids{1} );
0105 %
0106 if isfield( A, 'p_min' )
0107   ind      = find( Q.P_GRID >= A.p_min );
0108   Q.P_GRID = Q.P_GRID( ind );  
0109 end
0110 %
0111 Q.Z_FIELD = vec2col( R.data );
0112 
0113 % t_field
0114 R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'Fascod', ...   
0115                                    A.fascode_atm, [A.fascode_atm,'.t.xml'] ) );
0116 Q.T_FIELD = interpp( R.grids{1}, R.data, Q.P_GRID );
0117 
0118 % vmr_field
0119 %
0120 Q.ABS_SPECIES = A.ABS_SPECIES;
0121 %
0122 nabs          = length( Q.ABS_SPECIES );
0123 Q.VMR_FIELD   = zeros( nabs, length(Q.P_GRID) );
0124 %
0125 fe_found      = 0;
0126 %
0127 for i = 1 : nabs
0128   species = arts_tgs2species( Q.ABS_SPECIES(i).TAG{1} );
0129   
0130   if strcmp( species, 'free_electrons' )
0131     fe_found = i;
0132   else
0133     R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'Fascod', ...
0134                          A.fascode_atm, [A.fascode_atm,'.',species,'.xml'] ) );
0135     % Use nearest interpolation downwards
0136     Q.VMR_FIELD(i,:) = interpp( [1e99;R.grids{1}], [R.data(1);R.data], ...
0137                                                                     Q.P_GRID );
0138   end
0139 end
0140 
0141 Q.HSE.ON                = true;
0142 Q.HSE.P                 = Q.P_GRID(2);
0143 Q.HSE.ACCURACY          = 1;
0144 
0145 
0146 % If no ionosphere, handle 2D and 3D, and return
0147 if ~safegetfield( A, 'ionosphere', false );
0148 
0149   if Q.ATMOSPHERE_DIM == 2
0150     Q.LAT_GRID = [ -90 : 5 : 90 ]';
0151     Q.LAT_TRUE = Q.LAT_GRID;
0152     Q.LON_TRUE = repmat( Q.LON_TRUE, size(Q.LAT_GRID) );
0153     nlon = 1;
0154   elseif Q.ATMOSPHERE_DIM == 3
0155     Q.LAT_TRUE = {};
0156     Q.LON_TRUE = {};
0157     Q.LAT_GRID = [ -90 : 3 : 90 ]';
0158     Q.LON_GRID = [ -180 180 ];
0159     if isfield( A, 'lon0' )
0160       Q.LON_GRID = A.lon0 + Q.LON_GRID;    
0161     end
0162     nlon = length(Q.LON_GRID);
0163   end 
0164 
0165   if Q.ATMOSPHERE_DIM > 1
0166     ind        = find( Q.LAT_GRID >= safegetfield( A, 'lat_min', -Inf )  &  ...
0167                        Q.LAT_GRID <= safegetfield( A, 'lat_max', Inf  )   );
0168     Q.LAT_GRID = Q.LAT_GRID( ind );
0169     %
0170     nlat = length( Q.LAT_GRID );
0171     %
0172     Q.Z_FIELD   = repmat( Q.Z_FIELD, [ 1 nlat nlon ] );
0173     Q.T_FIELD   = repmat( Q.T_FIELD, [ 1 nlat nlon ] );
0174     Q.VMR_FIELD = repmat( Q.VMR_FIELD, [ 1 1 nlat nlon ] );
0175   end
0176 
0177   return;   % --->
0178 end
0179 
0180 
0181 %-----------------------------------------------------------------------------
0182 %--- Add ionopshere
0183 %-----------------------------------------------------------------------------
0184 
0185 if Q.ATMOSPHERE_DIM == 2
0186   error( 'Adding an ionosphere not supported for 2D.' );
0187 end
0188   
0189 
0190 % Take altitudes and pressures from free electron data
0191 %
0192 R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'IRI', ...
0193                                                          'IRI.Ne.z.xml.gz' ) );
0194 %
0195 ind = find( R.grids{1} <= Q.P_GRID(end)/10  &  ...
0196             R.grids{1} >= safegetfield( A, 'p_min', 0 ) );
0197 %
0198 pnew = vec2col( R.grids{1}(ind) );
0199 %
0200 Q.P_GRID  = [ Q.P_GRID;  pnew ];
0201 Q.Z_FIELD = [ Q.Z_FIELD; R.data(ind,1,1) ];
0202 Q.T_FIELD = [ Q.T_FIELD; repmat( Q.T_FIELD(end), [ length(pnew), 1 ] ) ];
0203 % Use "zeropadding" for vmr
0204 vmr_field   = Q.VMR_FIELD;
0205 Q.VMR_FIELD = zeros( size(vmr_field,1), length(Q.P_GRID) );
0206 Q.VMR_FIELD(:,1:size(vmr_field,2)) = vmr_field;
0207 clear vmr_field;
0208 
0209 
0210 % Load magnetic fields (lat and lon taken from these data)
0211 %
0212 R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'IGRF', ...
0213             sprintf('IGRF11_%d_200km-5deg-5deg.B_u.xml.gz', A.igrf_year ) ) );
0214 %
0215 if Q.ATMOSPHERE_DIM == 1
0216   outgrids = { Q.P_GRID, Q.LAT_TRUE, Q.LON_TRUE };
0217 else
0218   Q.LAT_GRID = R.grids{2};
0219   ind        = find( Q.LAT_GRID >= safegetfield( A, 'lat_min', -Inf )  &  ...
0220                      Q.LAT_GRID <= safegetfield( A, 'lat_max', Inf  )   );
0221   Q.LAT_GRID = Q.LAT_GRID( ind ); 
0222   %
0223   Q.LON_GRID = R.grids{3};
0224   %
0225   outgrids = { Q.P_GRID, Q.LAT_GRID, Q.LON_GRID };
0226 end
0227 %
0228 Q.MAG_U_FIELD = arts_regrid( Q.ATMOSPHERE_DIM, R.grids, R.data, outgrids );
0229 %
0230 %
0231 R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'IGRF', ...
0232             sprintf('IGRF11_%d_200km-5deg-5deg.B_v.xml.gz', A.igrf_year ) ) );
0233 Q.MAG_V_FIELD = arts_regrid( Q.ATMOSPHERE_DIM, R.grids, R.data, outgrids );
0234 %
0235 %
0236 R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'IGRF', ...
0237             sprintf('IGRF11_%d_200km-5deg-5deg.B_w.xml.gz', A.igrf_year ) ) );
0238 Q.MAG_W_FIELD = arts_regrid( Q.ATMOSPHERE_DIM, R.grids, R.data, outgrids );
0239 
0240 
0241 % Expand to 3D
0242 %
0243 if Q.ATMOSPHERE_DIM == 3
0244   nlat = length( Q.LAT_GRID );
0245   nlon = length( Q.LON_GRID );
0246   %
0247   Q.Z_FIELD   = repmat( Q.Z_FIELD, [ 1 nlat nlon ] );
0248   Q.T_FIELD   = repmat( Q.T_FIELD, [ 1 nlat nlon ] );
0249   Q.VMR_FIELD = repmat( Q.VMR_FIELD, [ 1 1 nlat nlon ] );
0250 end
0251 
0252 
0253 if fe_found
0254   R = xmlLoad( fullfile( arts_xmldata_path, 'planets', 'Earth', 'IRI', ...
0255                          sprintf( 'IRI_sol%s_%s_%02dUTC.Ne.xml.gz', ...
0256                                     A.iri_sun, A.iri_season, A.iri_utc ) )  );
0257   Q.VMR_FIELD(fe_found,:,:,:) = arts_regrid( Q.ATMOSPHERE_DIM, R.grids, ...
0258                                                            R.data, outgrids );
0259   Q.VMR_FIELD(fe_found,end,:,:) = 0;
0260 end
0261 
0262 
0263 % Centre on lon0?
0264 %
0265 if isfield( A, 'lon0' )
0266   Q.LON_GRID = Q.LON_GRID - mean(Q.LON_GRID([1 end])) + A.lon0
0267 end
0268 
0269

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005