Ejemplo n.º 1
0
TimeFrequencyData TimeFrequencyImager::GetData() const
{
	TimeFrequencyData data;
	if(
		_realXX != 0 && _imaginaryXX != 0 &&
		_realXY != 0 && _imaginaryXY != 0 &&
		_realYX != 0 && _imaginaryYX != 0 &&
		_realYY != 0 && _imaginaryYY != 0)
	{
		data = TimeFrequencyData(_realXX, _imaginaryXX, _realXY, _imaginaryXY, _realYX, _imaginaryYX, _realYY, _imaginaryYY);
	} else if(
		_realXX != 0 && _imaginaryXX != 0 &&
		_realYY != 0 && _imaginaryYY != 0)
	{
		data = TimeFrequencyData(AutoDipolePolarisation, _realXX, _imaginaryXX, _realYY, _imaginaryYY);
	} else if(_realStokesI != 0 && _imaginaryStokesI != 0)
	{
		data = TimeFrequencyData(StokesIPolarisation, _realStokesI, _imaginaryStokesI);
	}

	if(_flagXX != 0 && _flagXY != 0 && _flagYX != 0 && _flagYY != 0)
	{
		if(data.Polarisation() != DipolePolarisation)
			throw BadUsageException("Trying to read dipole polarisation masks, but TF data does not have the dipole polarisations"); 
		data.SetIndividualPolarisationMasks(_flagXX, _flagXY, _flagYX, _flagYY);
	} else if(_flagXX != 0 && _flagYY != 0)
	{
		if(data.Polarisation() != AutoDipolePolarisation)
			throw BadUsageException("Trying to read auto dipole polarisation masks, but TF data does not have the auto dipole polarisations"); 
		data.SetIndividualPolarisationMasks(_flagXX, _flagYY);
	} else if(_flagCombined != 0)
	{
		data.SetGlobalMask(_flagCombined);
	}

	return data;
}
Ejemplo n.º 2
0
  void BHFitsImageSet::loadImageData(TimeFrequencyData &data, const TimeFrequencyMetaDataPtr &metaData, const BHFitsImageSetIndex &index)
  {
		std::vector<num_t> buffer(_width * _height);
		_file->ReadCurrentImageData(0, &buffer[0], _width * _height);
		
		int
			rangeStart = _timeRanges[index._imageIndex].start, 
			rangeEnd = _timeRanges[index._imageIndex].end;
		Image2DPtr image = Image2D::CreateZeroImagePtr(rangeEnd-rangeStart, _height);

		std::vector<num_t>::const_iterator bufferPtr = buffer.begin() + _height*rangeStart;
		for(int x=rangeStart; x!=rangeEnd; ++x)
		{
			for(int y=0; y!=_height; ++y)
			{
				image->SetValue(x-rangeStart, y, *bufferPtr);
				++bufferPtr;
			}
		}
		data = TimeFrequencyData(TimeFrequencyData::AmplitudePart, SinglePolarisation, image);

		try {
			FitsFile flagFile(flagFilePath());
			flagFile.Open(FitsFile::ReadOnlyMode);
			flagFile.ReadCurrentImageData(0, &buffer[0], _width * _height);
			bufferPtr = buffer.begin() + _height*rangeStart;
			Mask2DPtr mask = Mask2D::CreateUnsetMaskPtr(rangeEnd-rangeStart, _height);
			for(int x=rangeStart; x!=rangeEnd; ++x)
			{
				for(int y=0; y!=_height; ++y)
				{
					bool flag = false;
					if(*bufferPtr == 0.0)
						flag = false;
					else if(*bufferPtr == 1.0)
						flag = true;
					else std::runtime_error("Expecting a flag file with only ones and zeros, but this file contained other values.");
					mask->SetValue(x-rangeStart, y, flag);
					++bufferPtr;
				}
			}
			data.SetGlobalMask(mask);
		} catch(std::exception &)
		{
			// Flag file could not be read; probably does not exist. Ignore this, flags will be initialized to false.
		}

		double
			frequencyDelta = _file->GetDoubleKeywordValue("CDELT1"),
			timeDelta = _file->GetDoubleKeywordValue("CDELT2");
		BandInfo band;
		for(int ch=0; ch!=_height; ++ch)
		{
			ChannelInfo channel;
			channel.frequencyHz = ch * frequencyDelta * 1000000.0;
			band.channels.push_back(channel);
		}
		metaData->SetBand(band);

		const int rangeWidth = rangeEnd-rangeStart;
		std::vector<double> observationTimes(rangeWidth);
		for(int t=0; t!=rangeWidth; ++t)
			observationTimes[t] = (t + rangeStart) * timeDelta;
		metaData->SetObservationTimes(observationTimes);

		AntennaInfo antennaInfo;
		antennaInfo.id = 0;
		antennaInfo.name = RangeName(index._imageIndex);
		antennaInfo.diameter = 0.0;
		antennaInfo.mount = "Unknown";
		antennaInfo.station = GetTelescopeName();
		metaData->SetAntenna1(antennaInfo);
		metaData->SetAntenna2(antennaInfo);
  }