![]() |
CARTA Backend
The backend component of CARTA
|
#include "Casacore.h"
#include <regex>
#include <casacore/casa/OS/File.h>
#include <casacore/casa/Quanta/UnitMap.h>
#include "ImageData/CartaMiriadImage.h"
#include "Logger/Logger.h"
Functions | |
const std::regex | GILDAS_REGEX (" *[a-zA-Z]+[ .]+\\(T[a-zA-Z_]+[*.]*\\) *") |
bool | CheckFolderPaths (string &top_level_string, string &starting_string) |
bool | IsSubdirectory (std::string folder, std::string top_folder) |
Determines whether a given folder is a subdirectory of a specified top-level folder. | |
casacore::String | GetResolvedFilename (const std::string &root_dir, const std::string &directory, const std::string &file, std::string &message) |
Resolves a file path based on a given root directory and relative subdirectory. | |
void | GetSpectralCoordPreferences (casacore::ImageInterface< float > *image, bool &prefer_velocity, bool &optical_velocity, bool &prefer_wavelength, bool &air_wavelength) |
Determines the spectral coordinate preferences based on an image's native spectral type. | |
std::string | FormatBeam (const casacore::GaussianBeam &gaussian_beam) |
Formats a Gaussian beam's parameters into a human-readable string. | |
std::string | FormatQuantity (const casacore::Quantity &quantity) |
Formats a Casacore quantity into a human-readable string. | |
void | NormalizeUnit (casacore::String &unit) |
Normalizes a given unit string to conform to standard Casacore unit conventions (case-sensitive). | |
bool | IsGildasUnit (const casacore::String &unit) |
bool | ParseHistoryBeamHeader (std::string &header, std::string &bmaj, std::string &bmin, std::string &bpa) |
Parses an AIPS-style beam header to extract beam parameters with regular expression. | |
bool CheckFolderPaths | ( | string & | top_level_string, |
string & | starting_string | ||
) |
This function checks and resolves the given top-level and starting directories. If default placeholder values ("base" or "root") are found, they are replaced accordingly. The function verifies that both directories exist and are accessible, and ensures that the starting directory is a valid subdirectory of the top-level directory.
starting_string
is invalid, it is replaced with top_level_string
. starting_string
is not a subdirectory of top_level_string
, the function logs a critical error and returns false
.top_level_string
and starting_string
are set to their default placeholders ("base" and "root"), the function logs a critical error and returns false
. std::string FormatBeam | ( | const casacore::GaussianBeam & | gaussian_beam | ) |
Formats a Gaussian beam's parameters into a human-readable string.
This function retrieves the major axis, minor axis, and position angle (PA) of a given casacore::GaussianBeam
and formats them into a structured string with six decimal places of precision.
"major: <value> <unit> minor: <value> <unit> pa: <value> <unit>"
std::string FormatQuantity | ( | const casacore::Quantity & | quantity | ) |
Formats a Casacore quantity into a human-readable string.
This function converts a casacore::Quantity
into a string representation with six decimal places of precision, including its unit.
casacore::String GetResolvedFilename | ( | const std::string & | root_dir, |
const std::string & | directory, | ||
const std::string & | file, | ||
std::string & | message | ||
) |
Resolves a file path based on a given root directory and relative subdirectory.
This function constructs an absolute file path using a specified root directory, a relative subdirectory, and a file name. It checks whether the resulting file path exists and is readable. If any issue is encountered, an error message is set.
void GetSpectralCoordPreferences | ( | casacore::ImageInterface< float > * | image, |
bool & | prefer_velocity, | ||
bool & | optical_velocity, | ||
bool & | prefer_wavelength, | ||
bool & | air_wavelength | ||
) |
Determines the spectral coordinate preferences based on an image's native spectral type.
This function analyses the spectral coordinate system of the provided image
and sets preference flags for velocity, wavelength, and their specific variations. It considers the image's native spectral type and applies special handling for CartaMiriadImage
types.
const std::regex GILDAS_REGEX | ( | " *++\\(T[a-zA-Z_]+[*.]*\\) *" | [a-zA-Z][.] | ) |
bool IsGildasUnit | ( | const casacore::String & | unit | ) |
This function uses regex to check if unit is in the GILDAS CLASS software format "unit (Ttype)" where the "type" describes the temperature T. It also tests for casacore Unit name changes where " " and "*" are replaced with ".". For example: "K (Ta*)" --> "K.(Ta.)" in casacore.
bool IsSubdirectory | ( | std::string | folder, |
std::string | top_folder | ||
) |
Determines whether a given folder is a subdirectory of a specified top-level folder.
This function checks if folder
is a subdirectory of top_folder
by resolving both paths to their absolute, weakly canonical forms and then traversing up the directory hierarchy.
top_folder
is empty, the function will always return true
. void NormalizeUnit | ( | casacore::String & | unit | ) |
Normalizes a given unit string to conform to standard Casacore unit conventions (case-sensitive).
This function converts various unit representations into their standardised Casacore equivalents. It replaces non-standard units with correct forms, fixes case inconsistencies, and removes invalid characters. Additionally, it attempts to map the unit to a valid Casacore unit using UnitMap::fromFITS
and UnitVal::check
.
casacore::AipsError | Caught internally when Casacore unit conversions fail. |
bool ParseHistoryBeamHeader | ( | std::string & | header, |
std::string & | bmaj, | ||
std::string & | bmin, | ||
std::string & | bpa | ||
) |
Parses an AIPS-style beam header to extract beam parameters with regular expression.
This function uses regular expressions to extract the major axis (BMAJ), minor axis (BMIN), and position angle (BPA) from an AIPS-style history beam header string. It handles two common formats: one using "Beam =" notation and another using "BMAJ=", "BMIN=", and "BPA=" notation.
false
.