std::pair<TimeFrequencyData,TimeFrequencyMetaDataPtr> RSPReader::ReadSingleBeamlet(unsigned long timestepStart, unsigned long timestepEnd, unsigned beamletCount, unsigned beamletIndex) { std::pair<TimeFrequencyData,TimeFrequencyMetaDataPtr> data = ReadAllBeamlets(timestepStart, timestepEnd, beamletCount); const unsigned width = timestepEnd - timestepStart; Image2DPtr realX = Image2D::CreateZeroImagePtr(width, 1); Image2DPtr imaginaryX = Image2D::CreateZeroImagePtr(width, 1); Image2DPtr realY = Image2D::CreateZeroImagePtr(width, 1); Image2DPtr imaginaryY = Image2D::CreateZeroImagePtr(width, 1); Mask2DPtr mask = Mask2D::CreateUnsetMaskPtr(width, 1); TimeFrequencyData allX = data.first.Make(Polarization::XX); TimeFrequencyData allY = data.first.Make(Polarization::YY); Image2DCPtr xr = allX.GetRealPart(); Image2DCPtr xi = allX.GetImaginaryPart(); Image2DCPtr yr = allY.GetRealPart(); Image2DCPtr yi = allY.GetImaginaryPart(); Mask2DCPtr maskWithBeamlets = data.first.GetSingleMask(); for(unsigned x=0;x<width;++x) { realX->SetValue(x, 0, xr->Value(x, beamletIndex)); imaginaryX->SetValue(x, 0, xi->Value(x, beamletIndex)); realY->SetValue(x, 0, yr->Value(x, beamletIndex)); imaginaryY->SetValue(x, 0, yi->Value(x, beamletIndex)); mask->SetValue(x, 0, maskWithBeamlets->Value(x, beamletIndex)); } data.first = TimeFrequencyData(Polarization::XX, realX, imaginaryX, Polarization::YY, realY, imaginaryY); data.first.SetGlobalMask(mask); BandInfo band = data.second->Band(); band.channels[0] = data.second->Band().channels[beamletIndex]; band.channels.resize(1); data.second->SetBand(band); return data; }
void UVImager::Image(const TimeFrequencyData &data, TimeFrequencyMetaDataCPtr metaData, unsigned frequencyIndex) { if(_uvReal == 0) Empty(); Image2DCPtr real = data.GetRealPart(), imaginary = data.GetImaginaryPart(); Mask2DCPtr flags = data.GetSingleMask(); for(unsigned i=0;i<data.ImageWidth();++i) { switch(_imageKind) { case Homogeneous: if(flags->Value(i, frequencyIndex)==0.0L) { num_t vr = real->Value(i, frequencyIndex), vi = imaginary->Value(i, frequencyIndex); if(std::isfinite(vr) && std::isfinite(vi)) { num_t u,v; GetUVPosition(u, v, i, frequencyIndex, metaData); SetUVValue(u, v, vr, vi, 1.0); SetUVValue(-u, -v, vr, -vi, 1.0); } } break; case Flagging: if((flags->Value(i, frequencyIndex)!=0.0L && !_invertFlagging) || (flags->Value(i, frequencyIndex)==0.0L && _invertFlagging)) { num_t u,v; GetUVPosition(u, v, i, frequencyIndex, metaData); SetUVValue(u, v, 1, 0, 1.0); SetUVValue(-u, -v, 1, 0, 1.0); } break; } } }
std::pair<TimeFrequencyData,TimeFrequencyMetaDataPtr> RSPReader::ReadChannelBeamlet(unsigned long timestepStart, unsigned long timestepEnd, unsigned beamletCount, unsigned beamletIndex) { const unsigned width = timestepEnd - timestepStart; std::pair<TimeFrequencyData,TimeFrequencyMetaDataPtr> data = ReadSingleBeamlet(timestepStart*(unsigned long) 256, timestepEnd*(unsigned long) 256, beamletCount, beamletIndex); TimeFrequencyData allX = data.first.Make(Polarization::XX); TimeFrequencyData allY = data.first.Make(Polarization::YY); Image2DCPtr xr = allX.GetRealPart(); Image2DCPtr xi = allX.GetImaginaryPart(); Image2DCPtr yr = allY.GetRealPart(); Image2DCPtr yi = allY.GetImaginaryPart(); Mask2DCPtr mask = data.first.GetSingleMask(); Image2DPtr outXR = Image2D::CreateUnsetImagePtr(width, 256), outXI = Image2D::CreateUnsetImagePtr(width, 256), outYR = Image2D::CreateUnsetImagePtr(width, 256), outYI = Image2D::CreateUnsetImagePtr(width, 256); Mask2DPtr outMask = Mask2D::CreateUnsetMaskPtr(width, 256); std::vector<double> observationTimes; for(unsigned long timestep = 0;timestep < timestepEnd-timestepStart;++timestep) { unsigned long timestepIndex = timestep * 256; SampleRow realX = SampleRow::MakeFromRow(xr.get(), timestepIndex, 256, 0), imaginaryX = SampleRow::MakeFromRow(xi.get(), timestepIndex, 256, 0), realY = SampleRow::MakeFromRow(yr.get(), timestepIndex, 256, 0), imaginaryY = SampleRow::MakeFromRow(yi.get(), timestepIndex, 256, 0); FFTTools::FFT(realX, imaginaryX); FFTTools::FFT(realY, imaginaryY); realX.SetVerticalImageValues(outXR.get(), timestep); imaginaryX.SetVerticalImageValues(outXI.get(), timestep); realY.SetVerticalImageValues(outYR.get(), timestep); imaginaryY.SetVerticalImageValues(outYI.get(), timestep); observationTimes.push_back(data.second->ObservationTimes()[timestepIndex + 256/2]); size_t validValues = 0; for(unsigned y=0;y<256;++y) { if(!mask->Value(timestepIndex + y, 0)) ++validValues; } for(unsigned y=0;y<256;++y) { outMask->SetValue(timestep, y , validValues == 0); } } data.first = TimeFrequencyData(Polarization::XX, outXR, outXI, Polarization::YY, outYR, outYI); data.first.SetGlobalMask(outMask); BandInfo band = data.second->Band(); band.channels.clear(); for(unsigned i=0;i<256;++i) { ChannelInfo channel; channel.frequencyHz = i+1; channel.frequencyIndex = i; band.channels.push_back(channel); } data.second->SetBand(band); data.second->SetObservationTimes(observationTimes); return data; }