@@ -274,15 +274,34 @@ def _get_data(
274274 with fits .open (filename , memmap = False ) as hdu_list :
275275 vis_hdu = hdu_list [0 ] # assumes the visibilities are in the primary hdu
276276 if vis_hdu .header ["NAXIS" ] == 7 :
277- raw_data_array = vis_hdu .data .data [:, 0 , 0 , :, :, :, :]
278- if self .Nspws != raw_data_array .shape [1 ]: # pragma: no cover
277+ self .data_array = vis_hdu .data .data [:, 0 , 0 ]
278+ if (
279+ self .Nspws != self .data_array .shape [1 ]
280+ or len (self .data_array .shape ) != 5
281+ ): # pragma: no cover
279282 raise RuntimeError (bad_data_shape_msg )
280283
284+ # Reshape the data array to combine the spw & freq axes
285+ self .data_array = np .reshape (
286+ self .data_array ,
287+ (self .Nblts , self .Nfreqs , self .Npols , self .data_array .shape [4 ]),
288+ )
289+
281290 else :
282- # in many uvfits files the spw axis is left out,
283- # here we put it back in so the dimensionality stays the same
284- raw_data_array = vis_hdu .data .data [:, 0 , 0 , :, :, :]
285- raw_data_array = raw_data_array [:, np .newaxis , :, :]
291+ self .data_array = vis_hdu .data .data [:, 0 , 0 , :, :, :]
292+
293+ if len (self .data_array .shape ) != 4 : # pragma: no cover
294+ raise RuntimeError (bad_data_shape_msg )
295+
296+ self .flag_array = self .data_array [:, :, :, 2 ] <= 0
297+ self .nsample_array = np .abs (self .data_array [:, :, :, 2 ])
298+
299+ # FITS uvw direction convention is opposite ours and Miriad's.
300+ # So conjugate the visibilities and flip the uvws:
301+ self .data_array = (
302+ self .data_array [:, :, :, 0 ] - 1j * self .data_array [:, :, :, 1 ]
303+ )
304+
286305 else :
287306 # do select operations on everything except data_array, flag_array
288307 # and nsample_array
@@ -350,24 +369,26 @@ def _get_data(
350369 if freq_frac < 1 :
351370 raw_data_array = raw_data_array [:, :, freq_inds , :, :]
352371
353- if len (raw_data_array .shape ) != 5 : # pragma: no cover
354- raise RuntimeError (bad_data_shape_msg )
372+ if len (raw_data_array .shape ) != 5 : # pragma: no cover
373+ raise RuntimeError (bad_data_shape_msg )
355374
356- # Reshape the data array to be the right size if we are working w/ multiple
357- # spectral windows
358- raw_data_array = np .reshape (
359- raw_data_array ,
360- (self .Nblts , self .Nfreqs , self .Npols , raw_data_array .shape [4 ]),
361- )
375+ # Reshape the data array to be the right size if we are working w/ multiple
376+ # spectral windows
377+ raw_data_array = np .reshape (
378+ raw_data_array ,
379+ (self .Nblts , self .Nfreqs , self .Npols , raw_data_array .shape [4 ]),
380+ )
362381
363- # FITS uvw direction convention is opposite ours and Miriad's.
364- # So conjugate the visibilities and flip the uvws:
365- self .data_array = raw_data_array [:, :, :, 0 ] - 1j * raw_data_array [:, :, :, 1 ]
366- self .flag_array = raw_data_array [:, :, :, 2 ] <= 0
367- self .nsample_array = np .abs (raw_data_array [:, :, :, 2 ])
382+ # FITS uvw direction convention is opposite ours and Miriad's.
383+ # So conjugate the visibilities and flip the uvws:
384+ self .data_array = (
385+ raw_data_array [:, :, :, 0 ] - 1j * raw_data_array [:, :, :, 1 ]
386+ )
387+ self .flag_array = raw_data_array [:, :, :, 2 ] <= 0
388+ self .nsample_array = np .abs (raw_data_array [:, :, :, 2 ])
368389
369- del raw_data_array
370- gc .collect ()
390+ del raw_data_array
391+ gc .collect ()
371392
372393 if fix_old_proj :
373394 self .fix_phase (use_ant_pos = fix_use_ant_pos )
0 commit comments