Skip to content

Commit

Permalink
Add feature to set rest frequency in moment generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pford committed Jul 23, 2024
1 parent 0ec8654 commit 57afca3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/ImageGenerators/MomentGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ bool MomentGenerator::CalculateMoments(int file_id, const casacore::ImageRegion&
_success = false;
_cancel = false;

// Set moment axis
// Save request settings
SetMomentAxis(moment_request);

// Set pixel range
SetPixelRange(moment_request);

// Set moment types
SetMomentTypes(moment_request);
SetRestFrequency(moment_request);

// Reset an ImageMoments
ResetImageMoments(image_region);
// Save image rest frequency for restore
double image_rest_freq = _image->coordinates().spectralCoordinate().restFrequency(); // Hz

// Calculate moments
try {
// Reset an ImageMoments rest frequency and subimage
ResetImageMoments(image_region);

// Start the timer
_start_time = std::chrono::high_resolution_clock::now();

Expand Down Expand Up @@ -90,9 +90,12 @@ bool MomentGenerator::CalculateMoments(int file_id, const casacore::ImageRegion&
}
}
} catch (AipsError& error) {
_error_msg = error.getLastMessage();
_error_msg = error.getMesg();
}

// Restore original rest frequency
SetImageRestFrequency(image_rest_freq);

// Set is the moment calculation successful or not
moment_response.set_success(IsSuccess());

Expand Down Expand Up @@ -181,7 +184,14 @@ void MomentGenerator::SetPixelRange(const CARTA::MomentRequest& moment_request)
}
}

void MomentGenerator::SetRestFrequency(const CARTA::MomentRequest& moment_request) {
_rest_frequency = moment_request.rest_freq(); // Hz
}

void MomentGenerator::ResetImageMoments(const casacore::ImageRegion& image_region) {
// Set the requested rest frequency in the image spectral coordinate
SetImageRestFrequency(_rest_frequency);

// Reset the sub-image
_sub_image.reset(new casacore::SubImage<casacore::Float>(*_image, image_region));

Expand All @@ -192,6 +202,19 @@ void MomentGenerator::ResetImageMoments(const casacore::ImageRegion& image_regio
_image_moments.reset(new IM(casacore::SubImage<casacore::Float>(*_sub_image), os, this, true));
}

void MomentGenerator::SetImageRestFrequency(double rest_frequency) {
auto csys = _image->coordinates();
if (rest_frequency != csys.spectralCoordinate().restFrequency()) {
casacore::String error;
casacore::Quantity new_rest_freq(rest_frequency, "Hz");
if (csys.setRestFrequency(error, new_rest_freq)) {
_image->setCoordinateInfo(csys);
} else {
throw(casacore::AipsError(error));
}
}
}

int MomentGenerator::GetMomentMode(CARTA::Moment moment) {
if (_moment_map.count(moment)) {
return _moment_map[moment];
Expand Down
3 changes: 3 additions & 0 deletions src/ImageGenerators/MomentGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class MomentGenerator : public casa::ImageMomentsProgressMonitor {
void SetMomentAxis(const CARTA::MomentRequest& moment_request);
void SetMomentTypes(const CARTA::MomentRequest& moment_request);
void SetPixelRange(const CARTA::MomentRequest& moment_request);
void SetRestFrequency(const CARTA::MomentRequest& moment_request);
void ResetImageMoments(const casacore::ImageRegion& image_region);
void SetImageRestFrequency(double rest_frequency);
int GetMomentMode(CARTA::Moment moment);
casacore::String GetMomentSuffix(casacore::Int moment);
casacore::String GetInputFileName();
Expand All @@ -72,6 +74,7 @@ class MomentGenerator : public casa::ImageMomentsProgressMonitor {
int _axis; // Moment axis
casacore::Vector<float> _include_pix;
casacore::Vector<float> _exclude_pix;
double _rest_frequency; // Hz
casacore::String _error_msg;
bool _success;
bool _cancel;
Expand Down

0 comments on commit 57afca3

Please sign in to comment.