Home > Angelas_Raster_Code > writeOutFits_raster_new.m

writeOutFits_raster_new

PURPOSE ^

%%%%%%%%Now we will try to make maps of each individual raster

SYNOPSIS ^

function olddir = writeOutFits_raster_new(cbass,hdf,maindir,fits_name, df,number)

DESCRIPTION ^

%%%%%%%%Now we will try to make maps of each individual raster

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %%%%%%%%%Now we will try to make maps of each individual raster
0002 function olddir = writeOutFits_raster_new(cbass,hdf,maindir,fits_name, df,number)
0003 
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 %  function olddir = writeOutFits_raster(hdf,maindir, df,number)
0007 %
0008 %  hdf:  (0) fits  (1) hdf
0009 %  m: number of raster so you can call lots
0010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0011 %%%%%%%%%%%%%
0012 
0013 
0014 % Select the how you want to save data fits/hdf
0015 %olddir =pwd;
0016 %if(length(parm.fits.hdf) == 1)
0017 %  hdf=parm.fits.hdf;
0018 %else
0019 %  hdf = 0; % Defaults to .fits
0020 %end
0021 olddir = pwd;
0022 display(['hdf is' , hdf])
0023 % Select the data you want to save as fits
0024 %if(length(parm.fits.source) ~= 0)
0025 % sourcename = parm.fits.source;
0026 %else
0027 % sourcename ='source' % Defaults to just on-source data
0028 %end
0029 
0030 %display(['Will cut data on',sourcename])
0031 
0032 % Cut the data on required observation type, ready for saving to .fits
0033 % First check if the special cases of 'all' or 'allastro' have been
0034 % selected
0035 
0036 %if (strcmpi(sourcename,'all'))
0037 %    df = d; % ie all the data will be writtn out as fits including skydips, noise events
0038 %elseif (strcmpi(sourcename,'allastro'))
0039 %    df = cutObs(d, {'source', 'ncp', 'radio_point_scan','calibrator','beammap','abscal','radio_point_cross'},'or');
0040 %else
0041 %    l = ['d.index.',char(sourcename),'.fast'];
0042 %    df = framecut(d,eval(l)); % Now only have the selected data in df
0043 %end
0044 
0045 if (size(df.antenna0.receiver.utc,1)==0) ;
0046     display('Zero-sized data passed to writeOutFits.  Save will fail. Not going to make any maps');
0047   
0048 else
0049   
0050 
0051 root_name = strcat(maindir,fits_name);
0052 
0053 % JL TO DO check if file exists, if so delete.
0054 if ~isempty('df.flags.fast');  % catch in case no flags set - early south data
0055     flags = df.flags.fast(:,1);
0056 else
0057     flags = logical(zeros((size(df.antenna0.receiver.data(:,1)))));
0058     
0059 end
0060 figure
0061 plot(flags)
0062 
0063 startTimeMJD = df.antenna0.receiver.utc(1);
0064 endTimeMJD = df.antenna0.receiver.utc(length(df.antenna0.receiver.utc));
0065 display('Calling writefits map');
0066 
0067 % recombine 1st and 8th columns.
0068 % At this point the 8 columns are
0069 % [(I+V)-r1*Tload1  Q1  U1  Q2  U2  Q3  U3  (I-V)-r2*Tload2]
0070 % d.antenna0.receiver.data
0071 % [df q] = logcal(df, 'iv');
0072 % if(~q)
0073 %   df = getIV_newdata(df);
0074 % end
0075 %I=d.antenna0.receiver.data(:,1)+d.antenna0.receiver.data(:,8);
0076 %V=d.antenna0.receiver.data(:,1)-d.antenna0.receiver.data(:,8);
0077 %d.antenna0.receiver.data(:,1)=I;
0078 %d.antenna0.receiver.data(:,8)=V;
0079 if(strmatch('N',cbass,'exact'))
0080  I = df.antenna0.receiver.data(:,1);
0081  Q1 = df.antenna0.receiver.data(:,2);
0082  U1 = df.antenna0.receiver.data(:,3);
0083  Q2 =df.antenna0.receiver.data(:,4);
0084  U2 = df.antenna0.receiver.data(:,5);
0085  Q3 = df.antenna0.receiver.data(:,6);
0086  U3 = df.antenna0.receiver.data(:,7);
0087  V = df.antenna0.receiver.data(:,8);
0088 else
0089     % CBASS South LL,Q, U, Q, U, RR
0090  I1 = df.antenna0.receiver.data(:,1);
0091  Q1 = df.antenna0.receiver.data(:,2);
0092  U1 = df.antenna0.receiver.data(:,3);
0093  Q2 =df.antenna0.receiver.data(:,4);
0094  U2 = df.antenna0.receiver.data(:,5);
0095  I2 = df.antenna0.receiver.data(:,6);
0096 end
0097 
0098 % I = df.antenna0.receiver.data(:,1); % This is called from fast_reduc which has already reordered data to have I,Q,U,V in data 1--4
0099 % Q = df.antenna0.receiver.data(:,2);
0100 % U = df.antenna0.receiver.data(:,3);
0101 % V =df.antenna0.receiver.data(:,4);
0102 
0103 
0104 
0105 % need the equatorial coordinates
0106 df = calculateRADECJ2000(df);
0107 
0108 %   % option to have output in galactic coords
0109 %   if parm.galactic.coSys == 1 %MI - 10.10.11
0110 %      [outlist] = coco(equa, 'j2000.0', 'g', 'r', 'r');%MI - 10.10.11
0111 %      df.antenna0.servo.equa = outlist;%MI - 10.10.11
0112 %   else
0113 %       df.antenna0.servo.equa = equa;
0114 %   end       %MI - 10.10.111
0115 %
0116   clear az;   
0117   clear el;
0118   clear equa;
0119    
0120 end
0121 
0122 if (hdf==1)
0123     disp(['Removing old file ',root_name,'_',number,'.hdf'])
0124     unix(['rm ',root_name,'_',number,'.hdf']);
0125     writeFitsMap([root_name,'_',number,'.hdf'],df,startTimeMJD,endTimeMJD,1,1,hdf,flags); 
0126 else
0127        disp(['Removing old file ',root_name,'_',number,'.fits'] )
0128        unix(['rm ',root_name,'_',number,'.fits']);
0129     writeFitsMap([root_name,'_',number,'.fits'],df,startTimeMJD,endTimeMJD,1,1,hdf,flags);
0130 end
0131 % %%
0132 %
0133 % % this -- exist('parm.fits.domapflag') returns zero for some reason
0134 % % despite the fact that it exists!!!
0135 %
0136 % [home,installeddir]=where_am_i();
0137 % location = [home,'/',installeddir];
0138 %
0139 % %Check if we want to make automated maps from the data
0140 %
0141 % %if (strcmpi(parm.fits.domapflag,'yes')) % strcmpi() instead of '==' (MAS).
0142 %
0143 %   disp('Attempting to make a map from the fits file...');
0144 %
0145 %   %if(length(parm.fits.frame) ~= 0)
0146 %   %  frame = parm.fits.frame;
0147 %   %else
0148 %     frame = 'radec';
0149 %     projection = 'tan';
0150 %   %end
0151 %   %disp('Got frame');
0152 %
0153 % %   if(length(parm.fits.projection) ~= 0)
0154 % %     projection = parm.fits.projection;
0155 % %   else
0156 % %     projection = 'moll';
0157 % %   end
0158 % %   disp('Got projection');
0159 %
0160 %
0161 % % Check if there is a specified .ini file for mapping
0162 %
0163 % %   if(length(parm.fits.ini) ~=0)
0164 % %     descart_ini_file = parm.fits.ini;
0165 % %   else
0166 % %     if (strcmp(frame,'heal') & strcmp(projection,'moll'))
0167 % %       descart_ini_file = 'mapping_params_heal_moll.ini';
0168 % %     elseif (strcmp(frame,'radec') & strcmp(projection,'tan'))
0169 %      name = df.antenna0.tracker.source(10)
0170 %      descart_ini_file = strcat(['mapping_params_radec_tan_',char(name),'.ini']); % AUTOMATICALLY PICKS UP SOURCE NAME
0171 % %     elseif (strcmp(frame,'azel') & strcmp(projection,'plate'))
0172 % %      descart_ini_file = 'mapping_params_azel_plate.ini';
0173 % %     else
0174 % %      disp(' Could not parse frame and projection, defaulting to heal / moll');
0175 % %      descart_ini_file = 'mapping_params_heal_moll.ini';
0176 % %     end
0177 % %   end
0178 %
0179 % % Check if there a designated python plotting file
0180 % %     if(length(parm.fits.pyplot)~=0)
0181 % %       png_plot_script = parm.fits.pyplot;
0182 % %     else
0183 % %       if (strcmp(frame,'heal') & strcmp(projection,'moll'))
0184 % %       png_plot_script = 'plot_healpix_map.py';
0185 % %     elseif (strcmp(frame,'radec') & strcmp(projection,'tan'))
0186 %      png_plot_script = 'plot_radec_map.py';
0187 % %     elseif (strcmp(frame,'azel') & strcmp(projection,'plate'))
0188 % %      png_plot_script = 'plot_cart_map.py';
0189 % %     else
0190 % %      disp(' Could not parse frame and projection, defaulting to heal / moll');
0191 % %      png_plot_script = 'plot_healpix_map.py';
0192 % %     end
0193 % %     end
0194 %
0195 %   disp(['Will use ini file ',descart_ini_file,'  -- plot script ',png_plot_script]);
0196 %
0197 %   disp('Setting Paths and Pythonpath...');
0198 %   % The following assumes that you have descart_cbass
0199 %   % and   plot_healpix_map.py installed in the appropriate locations.
0200 %   olddir=pwd;
0201 %   fitsdir=[maindir];
0202 %   cd(fitsdir);
0203 %   current_pythonpath = getenv('PYTHONPATH');
0204 %   if (length(current_pythonpath)==0)
0205 %     new_pythonpath =[location,'/descart/data_selection/'];
0206 %   else
0207 %   new_pythonpath =[location,'/descart/data_selection/:',current_pythonpath];
0208 %   end
0209 %   setenv('PYTHONPATH',new_pythonpath);
0210 %   current_path = getenv('PATH');
0211 %   new_path=[location,'/webpage_logging/:',location,'/descart/map_making/:',current_path];
0212 %   setenv('PATH',new_path);
0213 %   disp('...done');
0214 %   %disp(['New pythonpath',new_pythonpath])
0215 %
0216 %   % delete the chunks
0217 %   disp('Deleting chunks ...');
0218 %   delete_chunks_command=['python -m cbass.delete_chunks ',root_name,'_',number,'.fits'];
0219 %   unix(delete_chunks_command);
0220 %   disp('...done');
0221 %
0222 %   % data selection stage
0223 % %   do_select=1;
0224 % %
0225 % %   if(do_select==1)
0226 % %     if(length(parm.dataselect)~=0)
0227 % %           split_flags = parm.dataselect.dflags;
0228 % %       split_name  = parm.dataselect.fname;
0229 % % select_command=['python -m cbass.split_data -',split_flags,' -N ', split_name,' ',root_name,'.fits'];
0230 % %     else
0231 %       select_command=['python -m cbass.split_data -zkg -N BASIC ',root_name,'_',number,'.fits'];
0232 %    % end
0233 %   disp(['Selecting the data with: ',select_command]);
0234 %     unix(select_command);
0235 %     disp('...done');
0236 %   %end
0237 %
0238 %   % prepare file list then called descart mapper.
0239 %   if (hdf==1)
0240 %     unix('echo fitstable*.hdf > files.txt');
0241 %     %unix(['echo ',root_name,'_',number,'*.hdf > files.txt']);
0242 %   else
0243 %     unix('echo fitstable*.fits > files.txt');
0244 %     %unix(['echo ',root_name,'_',number,'*.fits > files.txt']);
0245 %   end
0246 %
0247 %   disp(['Calling descart_cbass to make map using ',descart_ini_file]);
0248 %   unix(['descart_cbass ',location,'/webpage_logging/',descart_ini_file]);
0249 %
0250 % %   % Make the .png previews from the map fits file
0251 % %   if (exist('map.fits')==2)
0252 % %   disp(['Making png previews using ',png_plot_script]);
0253 % %   unix(['python ',location,'/webpage_logging/',png_plot_script,' ',number,'_map.fits']);
0254 % %   else
0255 % %      disp(['map.fits does not exist will not make preview']);
0256 % %   end;
0257 %
0258 %   % Now rename relevant files
0259 %   disp('Renaming files...');
0260 %   %s2 = regexp(maindir, '/', 'split');
0261 %   %thedate=char(s2(end));
0262 %   fitsfile =  strcat(thedate,'_',number,'.fits');
0263 %   fitsmapfile= strcat(thedate,'_',number,'_map.fits');
0264 %   hitsfile= strcat(thedate,'_',number,'.hits');
0265 %
0266 %   movefile(['fitstable_',number,'.fits'],fitsfile);
0267 %   movefile('map.fits',fitsmapfile);
0268 %   movefile('map.hits',hitsfile);
0269 %
0270 %
0271 %
0272 % % if (strcmp(frame,'heal') & strcmp(projection,'moll'))
0273 % %
0274 % %   tmap= strcat(thedate,'_T.png');
0275 % %   qmap= strcat(thedate,'_Q.png');
0276 % %   umap= strcat(thedate,'_U.png');
0277 % %
0278 % %   movefile('map_T.png',tmap);
0279 % %   movefile('map_Q.png',qmap);
0280 % %   movefile('map_U.png',umap);
0281 % %   % Make Figs for the web page.
0282 % %   copyfile(tmap,'fig1.png');
0283 % %   copyfile(qmap,'fig2.png');
0284 % %   copyfile(umap,'fig3.png');
0285 % %
0286 % % elseif (strcmp(frame,'azel') & strcmp(projection,'plate'))
0287 % %
0288 % %   tmap= strcat(thedate,'_azel_T.png');
0289 % %   movefile('map_T.png',tmap);
0290 % %   copyfile(tmap,'fig1.png');
0291 %
0292 %   %%%
0293 %   % Angela added to make small raster maps from the radec,tan projections
0294 %   %%%
0295 % if (strcmp(frame,'radec') & strcmp(projection,'tan'))
0296 %     disp('Making radec tan .png maps')
0297 %     %date = thedate;
0298 %     name = df.antenna0.tracker.source(10);
0299 %     %d = script_pol_maps(d,name,date);
0300 %     unix(['python ',location,'/webpage_logging/plot_radec_polmap.py ', fitsmapfile]);
0301 %     disp('Copying fits file to named file');
0302 %     %disp(['cp ',fitsfile,' ',name,'_',fitsfile]); % For santiy in finding similar files later
0303 %     fitsfile
0304 %     movefile(fitsfile,[char(name),'_',number,'_',fitsfile])
0305 % end
0306 %
0307 %
0308 %
0309 %   delete('files.txt');
0310 %   disp('...map making completed');
0311 % %else
0312   disp('Will not attempt to make a map...');
0313 end
0314 
0315   clear df;
0316 disp(['Returning to directory ',olddir]);
0317 cd(olddir);
0318 return;

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005