From 02dd211678e961d56f3764b38bb5c5efc93750c9 Mon Sep 17 00:00:00 2001 From: Pam Harris Date: Tue, 23 Jul 2024 11:09:41 -0600 Subject: [PATCH 1/5] Add rest_freq field to moment request message --- carta-protobuf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carta-protobuf b/carta-protobuf index 202c31d25..25a9b9b2d 160000 --- a/carta-protobuf +++ b/carta-protobuf @@ -1 +1 @@ -Subproject commit 202c31d25ec4bda97cbb9bd71fee589541872847 +Subproject commit 25a9b9b2dee7c23f2bd92f11816a7dbf92b91837 From 0ec86546958f0152d4be7fdde532f1f75af99dfc Mon Sep 17 00:00:00 2001 From: Pam Harris Date: Tue, 23 Jul 2024 13:19:35 -0600 Subject: [PATCH 2/5] Update protobuf commit --- carta-protobuf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carta-protobuf b/carta-protobuf index 25a9b9b2d..8b2ec6f46 160000 --- a/carta-protobuf +++ b/carta-protobuf @@ -1 +1 @@ -Subproject commit 25a9b9b2dee7c23f2bd92f11816a7dbf92b91837 +Subproject commit 8b2ec6f463c9cc5973f2e3d4385e93f3a923d634 From 57afca33ffb23d5d589966ee1bde080a0c6b266e Mon Sep 17 00:00:00 2001 From: Pam Harris Date: Tue, 23 Jul 2024 16:57:24 -0600 Subject: [PATCH 3/5] Add feature to set rest frequency in moment generator --- src/ImageGenerators/MomentGenerator.cc | 39 ++++++++++++++++++++------ src/ImageGenerators/MomentGenerator.h | 3 ++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/ImageGenerators/MomentGenerator.cc b/src/ImageGenerators/MomentGenerator.cc index bb062d1b5..803db2a83 100644 --- a/src/ImageGenerators/MomentGenerator.cc +++ b/src/ImageGenerators/MomentGenerator.cc @@ -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(); @@ -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()); @@ -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(*_image, image_region)); @@ -192,6 +202,19 @@ void MomentGenerator::ResetImageMoments(const casacore::ImageRegion& image_regio _image_moments.reset(new IM(casacore::SubImage(*_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]; diff --git a/src/ImageGenerators/MomentGenerator.h b/src/ImageGenerators/MomentGenerator.h index eda5c466c..0526ab97f 100644 --- a/src/ImageGenerators/MomentGenerator.h +++ b/src/ImageGenerators/MomentGenerator.h @@ -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(); @@ -72,6 +74,7 @@ class MomentGenerator : public casa::ImageMomentsProgressMonitor { int _axis; // Moment axis casacore::Vector _include_pix; casacore::Vector _exclude_pix; + double _rest_frequency; // Hz casacore::String _error_msg; bool _success; bool _cancel; From 130b4066ce23c0cb332882767c61a10c8c6a966b Mon Sep 17 00:00:00 2001 From: Pam Harris Date: Tue, 23 Jul 2024 16:59:53 -0600 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 719b15def..398d2fa3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Support PV image generation along a polyline region ([#1341](https://github.com/CARTAvis/carta-backend/issues/1341)). +* Support setting rest frequency for moment image generation ([#1385](https://github.com/CARTAvis/carta-backend/issues/1385)). ### Fixed * Fixed crash when loading non-image HDU by URL ([#1365](https://github.com/CARTAvis/carta-backend/issues/1365)). From fce52611602c2cac353992702a4a5eedc7f612f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrianna=20Pi=C5=84ska?= Date: Mon, 9 Sep 2024 10:43:16 +0200 Subject: [PATCH 5/5] Bumped protobuf --- carta-protobuf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carta-protobuf b/carta-protobuf index ded71d4f4..855ddc275 160000 --- a/carta-protobuf +++ b/carta-protobuf @@ -1 +1 @@ -Subproject commit ded71d4f4ee643c128e7d7a708f2cd144ba34062 +Subproject commit 855ddc275d45ffcd397658b96b38414948561911