Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark/1178 supports loading swapped-axes image cubes #1194

Merged
merged 53 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
aa340bc
Do not fix the render axes to direction axes
markccchiang Sep 8, 2022
bcebbc3
Modify the changelog
markccchiang Sep 8, 2022
fcf9c33
Add axes numbers for Ra, Dec, Spectral and Stokes in the file info
markccchiang Sep 10, 2022
70a10bf
Add axes numbers in the file info extended message
markccchiang Sep 10, 2022
a6c5dc1
A minor code change
markccchiang Sep 12, 2022
d212cbb
Fix the problem of showing PV image coordinates for swapped axes cubes
markccchiang Sep 12, 2022
c6d382d
Identify key words GLON or GLAT as direction axes
markccchiang Sep 13, 2022
97798ef
Remove unused codes
markccchiang Sep 13, 2022
fa79f05
Modify the protobuf message AxesNumbers
markccchiang Sep 13, 2022
c431952
Change axis indices from 0-based to 1-based in the axes_numbers message
markccchiang Oct 3, 2022
c14c257
Minor code changes and refactoring
markccchiang Oct 3, 2022
09f229e
Fix an unit test error for the file info
markccchiang Oct 3, 2022
88d2037
Revert coordinate settings in PV generator
markccchiang Oct 4, 2022
da2949c
Solve a merge conflict in changelog
markccchiang Oct 4, 2022
91d4ef9
Refactor codes
markccchiang Oct 4, 2022
0a4f763
Merge branch 'dev' of https://github.com/CARTAvis/carta-backend into …
markccchiang Nov 14, 2022
1f72ab2
Update the protobuf submodule
markccchiang Nov 21, 2022
f0fac19
Solve merge conflicts
markccchiang Nov 21, 2022
6c36e34
Solve a merge conflict in changelog
markccchiang Nov 28, 2022
671024d
Merge branch 'dev' of https://github.com/CARTAvis/carta-backend into …
markccchiang Nov 29, 2022
8e65f58
Minor code changes
markccchiang Nov 29, 2022
905eded
Fix the problem of loading image file if it has both linear and direc…
markccchiang Nov 30, 2022
df993e4
Fix the error of showing direction axes range names in the file info …
markccchiang Nov 30, 2022
8e39ce0
Modify file info on the file browser for swapped image cubes
markccchiang Nov 30, 2022
732c824
Fix the problem of showing direction axis names for compressed images
markccchiang Nov 30, 2022
51feea8
Update the protobuf with the new dev branch
markccchiang Dec 2, 2022
c5c1cc7
Solve merge conflicts
markccchiang Dec 2, 2022
a7a37c0
Change the name of linear axis for a PV image as OFFSET
markccchiang Dec 2, 2022
511bdfd
Fix the name of non-direction axis for axis number is 0 or 1
markccchiang Dec 6, 2022
a9c4f04
Remove the function GetRenderAxes from the FileLoader
markccchiang Dec 6, 2022
0c59ee0
Fix the problem of axis names displayed on the file info panel
markccchiang Dec 15, 2022
6f2afc6
Merge branch 'dev' of https://github.com/CARTAvis/carta-backend into …
markccchiang Dec 26, 2022
3d9afd3
Fix the problem of an image without direction axes info for AST rende…
markccchiang Jan 4, 2023
9380630
Update the protobuf submodule with the new dev branch
markccchiang Jan 10, 2023
57daf49
Merge branch 'dev' of https://github.com/CARTAvis/carta-backend into …
markccchiang Jan 10, 2023
e10be2f
Update the protobuf and modify the changelog and the index
markccchiang Jan 10, 2023
b81fbf7
Get axes names through the image loader or the header entries
markccchiang Jan 12, 2023
f8d44fc
Correct the definition of number of channels is spectral axis size
markccchiang Jan 12, 2023
3828815
Solve a merge conflict in changelog
markccchiang Jan 12, 2023
732b788
Solve a merge conflict in the changlog
markccchiang Feb 2, 2023
55d6f75
Skip the stokes axis when rendering an image
markccchiang Feb 22, 2023
77a33ff
Get axis names from header entries that shown on the file info panel
markccchiang Feb 22, 2023
91e1c58
Modify the file info tester
markccchiang Feb 22, 2023
793a2b6
Represent the longitudinal coordinate value in the rangge [0, 360] deg
markccchiang Feb 26, 2023
a9463a4
Correct the syntax to initialize values for axis names
markccchiang Feb 28, 2023
36868ea
Fix the reversed PV generation when getting with fixed angular region…
markccchiang Mar 2, 2023
3fe5529
Merge branch 'dev' of https://github.com/CARTAvis/carta-backend into …
markccchiang Mar 13, 2023
3a3085a
Rename variables for directional axes as spatial axes
markccchiang Mar 13, 2023
b1e7177
Update the protobuf messages for spatial axes
markccchiang Mar 14, 2023
a01fe00
Fix the reference Dec value shown on the file info panel
markccchiang Mar 14, 2023
341e799
Minor code changes
markccchiang Mar 15, 2023
c446d83
bumped protobuf commit
confluence Mar 22, 2023
62b2c48
Merge branch 'mark/1178_set_render_axes_as_0_and_1' of github.com:CAR…
confluence Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added support to keep previously generated moment images ([#1202](https://github.com/CARTAvis/carta-backend/issues/1202)).
* Added pugixml as a third-party library with the option PUGIXML_COMPACT enabled ([#1217](https://github.com/CARTAvis/carta-backend/issues/1217)).
* Added automatically generated documentation with Doxygen ([#1215](https://github.com/CARTAvis/carta-backend/issues/1215)).
* Added support for loading swapped-axes image cubes ([#1178](https://github.com/CARTAvis/carta-backend/issues/1178)).

### Changed
* Removed CASA CRTF parser for performance and annotation region support ([#1219](https://github.com/CARTAvis/carta-backend/issues/1219)).
Expand Down
2 changes: 1 addition & 1 deletion carta-protobuf
190 changes: 127 additions & 63 deletions src/FileList/FileExtInfoLoader.cc

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/FileList/FileExtInfoLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class FileExtInfoLoader {

// Computed entries
void AddDataTypeEntry(CARTA::FileInfoExtended& extended_info, casacore::DataType data_type);
void AddShapeEntries(CARTA::FileInfoExtended& extended_info, const casacore::IPosition& shape, int chan_axis, int depth_axis,
int stokes_axis, const std::vector<int>& render_axes);
void AddShapeEntries(CARTA::FileInfoExtended& extended_info, const casacore::IPosition& shape, const std::vector<int>& spatial_axes,
int spectral_axis, int stokes_axis, const std::vector<int>& render_axes, int depth_axis,
casacore::Vector<casacore::String>& axes_names);
void AddInitialComputedEntries(const std::string& hdu, CARTA::FileInfoExtended& extended_info, const std::string& filename,
const std::vector<int>& render_axes, CompressedFits* compressed_fits = nullptr);
void AddComputedEntries(CARTA::FileInfoExtended& extended_info, casacore::ImageInterface<float>* image,
Expand All @@ -66,7 +67,7 @@ class FileExtInfoLoader {
std::string MakeAngleString(const std::string& type, double val, const std::string& unit);

// Convert Quantities and return formatted string
std::string ConvertCoordsToDeg(const casacore::Quantity& coord0, const casacore::Quantity& coord1);
std::string ConvertCoordsToDeg(const std::string& type, const casacore::Quantity& coord);
std::string ConvertIncrementToArcsec(const casacore::Quantity& inc0, const casacore::Quantity& inc1);

void GetCoordNames(std::string& ctype1, std::string& ctype2, std::string& radesys, std::string& coord_name1, std::string& coord_name2,
Expand Down
6 changes: 2 additions & 4 deletions src/Frame/Frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,16 @@ Frame::Frame(uint32_t session_id, std::shared_ptr<FileLoader> loader, const std:

// Get shape and axis values from the loader
std::string log_message;
if (!_loader->FindCoordinateAxes(_image_shape, _spectral_axis, _z_axis, _stokes_axis, log_message)) {
std::vector<int> spatial_axes, render_axes;
if (!_loader->FindCoordinateAxes(_image_shape, spatial_axes, _spectral_axis, _stokes_axis, render_axes, _z_axis, log_message)) {
_open_image_error = fmt::format("Cannot determine file shape. {}", log_message);
spdlog::error("Session {}: {}", session_id, _open_image_error);
_valid = false;
return;
}

// Determine which axes are rendered, e.g. for pV images
std::vector<int> render_axes = _loader->GetRenderAxes();
_x_axis = render_axes[0];
_y_axis = render_axes[1];

_width = _image_shape(_x_axis);
_height = _image_shape(_y_axis);
_depth = (_z_axis >= 0 ? _image_shape(_z_axis) : 1);
Expand Down
3 changes: 2 additions & 1 deletion src/Frame/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ class Frame {

// Shape and axis info: X, Y, Z, Stokes
casacore::IPosition _image_shape;
int _x_axis, _y_axis, _z_axis, _spectral_axis, _stokes_axis;
int _x_axis, _y_axis, _z_axis; // X and Y are render axes, Z is depth axis (non-render axis) that is not stokes (if any)
int _spectral_axis, _stokes_axis;
int _z_index, _stokes_index; // current index
size_t _width, _height, _depth, _num_stokes;

Expand Down
85 changes: 26 additions & 59 deletions src/ImageData/FileLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ std::shared_ptr<casacore::CoordinateSystem> FileLoader::GetCoordinateSystem(cons
return std::make_shared<casacore::CoordinateSystem>();
}

bool FileLoader::FindCoordinateAxes(casacore::IPosition& shape, int& spectral_axis, int& z_axis, int& stokes_axis, std::string& message) {
bool FileLoader::FindCoordinateAxes(casacore::IPosition& shape, std::vector<int>& spatial_axes, int& spectral_axis, int& stokes_axis,
std::vector<int>& render_axes, int& z_axis, std::string& message) {
// Return image shape and axes for image. Spectral axis may or may not be z axis.
// All parameters are return values.
spatial_axes.assign(2, -1);
spectral_axis = -1;
z_axis = -1;
stokes_axis = -1;
Expand All @@ -201,15 +203,33 @@ bool FileLoader::FindCoordinateAxes(casacore::IPosition& shape, int& spectral_ax
return false;
}

// Determine which axes will be rendered
std::vector<int> render_axes = GetRenderAxes();
// Get spectral and stokes axis
spectral_axis = _coord_sys->spectralAxisNumber();
stokes_axis = _coord_sys->polarizationAxisNumber();

// Set render axes are the first two axes that are not stokes
render_axes.resize(0);
for (int i = 0; i < _num_dims && render_axes.size() < 2; ++i) {
if (i != stokes_axis) {
render_axes.push_back(i);
}
}

_width = shape(render_axes[0]);
_height = shape(render_axes[1]);
_image_plane_size = _width * _height;

// Spectral and stokes axis
spectral_axis = _coord_sys->spectralAxisNumber();
stokes_axis = _coord_sys->polarizationAxisNumber();
// Find spatial axes
if (_coord_sys->hasDirectionCoordinate()) {
auto tmp_axes = _coord_sys->directionAxesNumbers();
spatial_axes[0] = tmp_axes[0];
spatial_axes[1] = tmp_axes[1];
} else if (_coord_sys->hasLinearCoordinate()) {
auto tmp_axes = _coord_sys->linearAxesNumbers();
for (int i = 0; i < casacore::min(tmp_axes.size(), 2); ++i) { // Assume the first two linear axes are spatial axes, if any
spatial_axes[i] = tmp_axes[i];
}
}

// 2D image
if (_num_dims == 2) {
Expand Down Expand Up @@ -282,59 +302,6 @@ bool FileLoader::FindCoordinateAxes(casacore::IPosition& shape, int& spectral_ax
return true;
}

std::vector<int> FileLoader::GetRenderAxes() {
// Determine which axes will be rendered
std::vector<int> axes;

if (!_render_axes.empty()) {
axes = _render_axes;
return axes;
}

// Default unless PV image
axes.assign({0, 1});

if (_image_shape.size() > 2) {
// Normally, use direction axes
if (_coord_sys->hasDirectionCoordinate()) {
casacore::Vector<casacore::Int> dir_axes = _coord_sys->directionAxesNumbers();
axes[0] = dir_axes[0];
axes[1] = dir_axes[1];
} else if (_coord_sys->hasLinearCoordinate()) {
// Check for PV image: usually [Linear, Spectral] axes but could be reversed
// Returns -1 if no spectral axis
int spectral_axis = _coord_sys->spectralAxisNumber();

if (spectral_axis >= 0) {
// Find valid (not -1) linear axes
std::vector<int> valid_axes;
if (spectral_axis == 0) { // reversed
valid_axes.push_back(spectral_axis);
}

casacore::Vector<casacore::Int> lin_axes = _coord_sys->linearAxesNumbers();
for (auto axis : lin_axes) {
if (axis >= 0) {
valid_axes.push_back(axis);
}
}

if (spectral_axis > 0) { // not reversed
valid_axes.push_back(spectral_axis);
}

// One linear + spectral axis = pV image
if (valid_axes.size() == 2) {
axes = valid_axes;
}
}
}
}

_render_axes = axes;
return axes;
}

bool FileLoader::GetSlice(casacore::Array<float>& data, const StokesSlicer& stokes_slicer) {
StokesSource stokes_source = stokes_slicer.stokes_source;
casacore::Slicer slicer = stokes_slicer.slicer;
Expand Down
7 changes: 2 additions & 5 deletions src/ImageData/FileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace carta {

class Frame;

struct StokesSlicer {
StokesSource stokes_source;
casacore::Slicer slicer;
Expand Down Expand Up @@ -78,8 +76,8 @@ class FileLoader {
// Image shape and coordinate system axes
casacore::IPosition GetShape();
std::shared_ptr<casacore::CoordinateSystem> GetCoordinateSystem(const StokesSource& stokes_source = StokesSource());
bool FindCoordinateAxes(casacore::IPosition& shape, int& spectral_axis, int& z_axis, int& stokes_axis, std::string& message);
std::vector<int> GetRenderAxes(); // Determine axes used for image raster data
bool FindCoordinateAxes(casacore::IPosition& shape, std::vector<int>& spatial_axes, int& spectral_axis, int& stokes_axis,
std::vector<int>& render_axes, int& z_axis, std::string& message);

// Slice image data (with mask applied)
bool GetSlice(casacore::Array<float>& data, const StokesSlicer& stokes_slicer);
Expand Down Expand Up @@ -152,7 +150,6 @@ class FileLoader {
size_t _num_dims, _image_plane_size;
size_t _width, _height, _depth, _num_stokes;
int _z_axis, _stokes_axis;
std::vector<int> _render_axes;
std::shared_ptr<casacore::CoordinateSystem> _coord_sys;
bool _has_pixel_mask;
casacore::DataType _data_type;
Expand Down
7 changes: 5 additions & 2 deletions src/ImageData/StokesFilesConnector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,23 @@ bool StokesFilesConnector::StokesFilesValid(std::string& err, int& stokes_axis)
}

casacore::IPosition ref_shape(0);
std::vector<int> ref_spatial_axes, ref_render_axes;
int ref_spectral_axis = -1;
int ref_z_axis = -1;
int ref_stokes_axis = -1;
int ref_index = 0;

for (auto& loader : _loaders) {
casacore::IPosition shape;
std::vector<int> spatial_axes, render_axes;
int spectral_axis;
int z_axis;

if (ref_index == 0) {
loader.second->FindCoordinateAxes(ref_shape, ref_spectral_axis, ref_z_axis, ref_stokes_axis, err);
loader.second->FindCoordinateAxes(
ref_shape, ref_spatial_axes, ref_spectral_axis, ref_stokes_axis, ref_render_axes, ref_z_axis, err);
} else {
loader.second->FindCoordinateAxes(shape, spectral_axis, z_axis, stokes_axis, err);
loader.second->FindCoordinateAxes(shape, spatial_axes, spectral_axis, stokes_axis, render_axes, z_axis, err);
if ((ref_shape.nelements() != shape.nelements()) || (ref_shape != shape) || (ref_spectral_axis != spectral_axis) ||
(ref_stokes_axis != stokes_axis)) {
err = "Image shapes or axes are not consistent!";
Expand Down
2 changes: 1 addition & 1 deletion test/TestFileInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class FileExtInfoLoaderTest : public ::testing::Test {
} else if (computed_entries.name() == "HDU") {
CheckHeaderEntry(computed_entries, "0", CARTA::EntryType::STRING);
} else if (computed_entries.name() == "Shape") {
CheckHeaderEntry(computed_entries, "[6, 6, 5, 1]", CARTA::EntryType::STRING);
CheckHeaderEntry(computed_entries, "[6, 6, 5, 1] (RA, DEC, FREQ, STOKES)", CARTA::EntryType::STRING);
} else if (computed_entries.name() == "Number of channels") {
CheckHeaderEntry(computed_entries, "5", CARTA::EntryType::INT, 5);
} else if (computed_entries.name() == "Number of polarizations") {
Expand Down