CARTA Backend
The backend component of CARTA
Loading...
Searching...
No Matches
carta::Ds9Importer Class Reference

A class for importing region files in DS9 format. More...

#include <Ds9Importer.h>

Inheritance diagram for carta::Ds9Importer:
[legend]
Collaboration diagram for carta::Ds9Importer:
[legend]

Public Member Functions

 Ds9Importer (std::shared_ptr< casacore::CoordinateSystem > coord_sys, int file_id, const std::string &file, bool file_is_filename)
 Constructor for Ds9Importer class for importing regions in DS9 region file.
 
- Public Member Functions inherited from carta::RegionImporter
 RegionImporter (std::shared_ptr< casacore::CoordinateSystem > coord_sys, int file_id)
 Constructor for RegionImporter class.
 
virtual ~RegionImporter ()=default
 Default destructor.
 
std::vector< RegionPropertiesGetRegions (std::string &error)
 Return imported regions and report errors.
 

Private Member Functions

void SetFileLineRegions (std::vector< std::string > &file_lines)
 Parse each line of file to import regions.
 
bool IsDs9Coord (std::string &file_line)
 Check if region file line is a DS9 coordinate.
 
bool SetFileCoordFrame (std::string &ds9_coord)
 Convert DS9 coordinate frame to casacore coordinate frame.
 
void SetGlobals (std::string &file_line)
 Set properties from global file line.
 
RegionProperties SetRegion (std::string &file_line)
 Parse file line to set a region.
 
RegionState ImportPointRegion (std::vector< std::string > &parameters, bool is_annotation=false)
 Import point or text region.
 
RegionState ImportCircleRegion (std::vector< std::string > &parameters, bool is_annotation=false)
 Import circle or compass region.
 
RegionState ImportEllipseRegion (std::vector< std::string > &parameters, bool is_annotation=false)
 Import ellipse, circle, or compass region.
 
RegionState ImportRectangleRegion (std::vector< std::string > &parameters, bool is_annotation=false)
 Import rectangle region.
 
RegionState ImportPolygonLineRegion (std::vector< std::string > &parameters, bool is_annotation=false)
 Import polygon and line-based regions.
 
RegionState ImportVectorRegion (std::vector< std::string > &parameters)
 Import vector region.
 
RegionState ImportRulerRegion (std::vector< std::string > &parameters, std::unordered_map< std::string, std::string > &properties, CARTA::RegionStyle &region_style)
 Import ruler region and its style parameters.
 
RegionState ImportCompassRegion (std::vector< std::string > &parameters, std::unordered_map< std::string, std::string > &properties, CARTA::RegionStyle &region_style)
 Import compass region and its style parameters.
 
CARTA::RegionStyle ImportStyle (CARTA::RegionType region_type, std::unordered_map< std::string, std::string > &properties)
 Set common region style parameters.
 
void ImportPointStyle (std::unordered_map< std::string, std::string > &properties, CARTA::AnnotationStyle *annotation_style)
 Set annotation style point parameters.
 
void ImportFontStyle (std::unordered_map< std::string, std::string > &properties, CARTA::AnnotationStyle *annotation_style)
 Set annotation style font parameters.
 
bool ParameterToQuantity (std::string &parameter, bool is_angle, bool is_xy, std::string &region_name, casacore::Quantity &param_quantity)
 Convert region parameter string to casacore Quantity.
 
bool Ds9ToCasacoreUnit (const std::string &region_name, std::string &parameter)
 Convert DS9 unit to casacore unit in parameter.
 
void ConvertTimeFormatToAngle (std::string &parameter)
 Convert parameter in sexagesimal format to angle format.
 

Private Attributes

std::string _image_coord_frame
 casacore coordinate frame from image coordinate system.
 
std::string _file_coord_frame
 DS9 coordinate frame converted to casacore, from region file.
 
bool _import_pixels
 

Static Private Attributes

static std::unordered_map< std::string, std::string > _coordinate_frames
 DS9 to casacore coordinate frame.
 

Additional Inherited Members

- Protected Member Functions inherited from carta::RegionImporter
virtual std::vector< std::string > ReadRegionFile (const std::string &file, bool file_is_filename, const char extra_delim='\0')
 Read region file into file lines.
 
virtual bool IsCommentLine (const std::string &file_line)
 Determine whether file line starting with comment marker is a comment and not an annotation region.
 
virtual void SetParserDelim (const std::string &delim)
 Set parser delimiter to use in parsing file line.
 
virtual void ParseRegionParameters (std::string &region_definition, std::vector< std::string > &parameters, std::unordered_map< std::string, std::string > &properties)
 Parse file line into region parameters and style properties.
 
virtual std::string GetProperty (const std::string &name, const std::unordered_map< std::string, std::string > &properties, bool check_global=false)
 Return value of name in region properties or global properties.
 
CARTA::TextAnnotationPosition GetTextPosition (const std::string &position)
 Convert text region position to CARTA position enum.
 
void AddTextStyleToProperties (const CARTA::RegionStyle &text_style, RegionProperties &textbox_properties)
 Add text region style to textbox region properties.
 
double WorldToPixelLength (casacore::Quantity length, unsigned int pixel_axis)
 Convert length region parameter to pixels if in world coordinates.
 
void ImportCompassStyle (std::string &compass_properties, std::string &compass_coord, CARTA::AnnotationStyle *annotation_style)
 Set style parameters for compass region.
 
void ImportRulerStyle (std::string &ruler_properties, std::string &ruler_coord)
 Get style parameters for ruler region.
 
- Protected Attributes inherited from carta::RegionImporter
std::shared_ptr< casacore::CoordinateSystem > _coord_sys
 Image coordinate system.
 
int _file_id
 File id of reference image.
 
std::string _parser_delim
 Delimiter for parsing region file, specific to file type.
 
std::unordered_map< std::string, std::string > _global_properties
 Map of properties from global line of region file.
 
std::unordered_map< CARTA::RegionType, std::string > _region_names
 Region names for conversion CRTF or DS9 name to CARTA type.
 
std::string _errors
 Errors for region lines which failed.
 
std::vector< RegionProperties_regions
 Imported regions.
 

Detailed Description

A class for importing region files in DS9 format.

Constructor & Destructor Documentation

◆ Ds9Importer()

Ds9Importer::Ds9Importer ( std::shared_ptr< casacore::CoordinateSystem >  coord_sys,
int  file_id,
const std::string &  file,
bool  file_is_filename 
)

Constructor for Ds9Importer class for importing regions in DS9 region file.

Parameters
coord_syscasacore::CoordinateSystem of image from which region is imported
file_idId of image from which region is imported
fileFile name or contents to import
file_is_filenameIndicates whether file parameter contains name or contents.
Here is the call graph for this function:

Member Function Documentation

◆ ConvertTimeFormatToAngle()

void Ds9Importer::ConvertTimeFormatToAngle ( std::string &  parameter)
private

Convert parameter in sexagesimal format to angle format.

Parameters
[in,out]parameterRegion parameter string to convert
Here is the caller graph for this function:

◆ Ds9ToCasacoreUnit()

bool Ds9Importer::Ds9ToCasacoreUnit ( const std::string &  region_name,
std::string &  parameter 
)
private

Convert DS9 unit to casacore unit in parameter.

Parameters
[in]region_nameRegion name
[in,out]parameterRegion parameter string to convert
Returns
Whether conversion is successful
Here is the caller graph for this function:

◆ ImportCircleRegion()

RegionState Ds9Importer::ImportCircleRegion ( std::vector< std::string > &  parameters,
bool  is_annotation = false 
)
private

Import circle or compass region.

Parameters
parametersRegion definition parameters
is_annotationWhether region is annotation region
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportCompassRegion()

RegionState Ds9Importer::ImportCompassRegion ( std::vector< std::string > &  parameters,
std::unordered_map< std::string, std::string > &  properties,
CARTA::RegionStyle &  region_style 
)
private

Import compass region and its style parameters.

Parameters
[in]parametersRegion definition parameters
[in]propertiesMap of style parameters
[out]region_styleRegion style parameters
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportEllipseRegion()

RegionState Ds9Importer::ImportEllipseRegion ( std::vector< std::string > &  parameters,
bool  is_annotation = false 
)
private

Import ellipse, circle, or compass region.

Parameters
parametersRegion definition parameters
is_annotationWhether region is annotation region
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportFontStyle()

void Ds9Importer::ImportFontStyle ( std::unordered_map< std::string, std::string > &  properties,
CARTA::AnnotationStyle *  annotation_style 
)
private

Set annotation style font parameters.

Parameters
[in]propertiesMap of style parameters
[out]annotation_styleAnnotation style parameters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportPointRegion()

RegionState Ds9Importer::ImportPointRegion ( std::vector< std::string > &  parameters,
bool  is_annotation = false 
)
private

Import point or text region.

Parameters
parametersRegion definition parameters
is_annotationWhether region is annotation region
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportPointStyle()

void Ds9Importer::ImportPointStyle ( std::unordered_map< std::string, std::string > &  properties,
CARTA::AnnotationStyle *  annotation_style 
)
private

Set annotation style point parameters.

Parameters
[in]propertiesMap of style parameters
[out]annotation_styleAnnotation style parameters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportPolygonLineRegion()

RegionState Ds9Importer::ImportPolygonLineRegion ( std::vector< std::string > &  parameters,
bool  is_annotation = false 
)
private

Import polygon and line-based regions.

Parameters
parametersRegion definition parameters
is_annotationWhether region is annotation region
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportRectangleRegion()

RegionState Ds9Importer::ImportRectangleRegion ( std::vector< std::string > &  parameters,
bool  is_annotation = false 
)
private

Import rectangle region.

Parameters
parametersRegion definition parameters
is_annotationWhether region is annotation region
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportRulerRegion()

RegionState Ds9Importer::ImportRulerRegion ( std::vector< std::string > &  parameters,
std::unordered_map< std::string, std::string > &  properties,
CARTA::RegionStyle &  region_style 
)
private

Import ruler region and its style parameters.

Parameters
[in]parametersRegion definition parameters
[in]propertiesMap of style parameters
[out]region_styleRegion style parameters
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportStyle()

CARTA::RegionStyle Ds9Importer::ImportStyle ( CARTA::RegionType  region_type,
std::unordered_map< std::string, std::string > &  properties 
)
private

Set common region style parameters.

Parameters
region_typeRegion type
propertiesMap of style parameters
Returns
Region style parameters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportVectorRegion()

RegionState Ds9Importer::ImportVectorRegion ( std::vector< std::string > &  parameters)
private

Import vector region.

Parameters
parametersRegion definition parameters
Returns
region state struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDs9Coord()

bool Ds9Importer::IsDs9Coord ( std::string &  file_line)
private

Check if region file line is a DS9 coordinate.

Parameters
file_lineLine of region file to check
Here is the caller graph for this function:

◆ ParameterToQuantity()

bool Ds9Importer::ParameterToQuantity ( std::string &  parameter,
bool  is_angle,
bool  is_xy,
std::string &  region_name,
casacore::Quantity &  param_quantity 
)
private

Convert region parameter string to casacore Quantity.

Parameters
[in]parameterRegion parameter string to convert
[in]is_angleWhether param describes an angle quantity
[in]is_xyWhether param describes a position quantity
[in]region_nameRegion name
[out]param_quantityRegion parameter as casacore Quantity
Returns
Whether conversion is successful
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFileCoordFrame()

bool Ds9Importer::SetFileCoordFrame ( std::string &  ds9_coord)
private

Convert DS9 coordinate frame to casacore coordinate frame.

Parameters
ds9_coordFile line with DS9 coordinate frame
Here is the caller graph for this function:

◆ SetFileLineRegions()

void Ds9Importer::SetFileLineRegions ( std::vector< std::string > &  file_lines)
private

Parse each line of file to import regions.

Parameters
file_linesLines read from region file
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetGlobals()

void Ds9Importer::SetGlobals ( std::string &  file_line)
private

Set properties from global file line.

Parameters
file_lineFile line with global values
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRegion()

RegionProperties Ds9Importer::SetRegion ( std::string &  file_line)
private

Parse file line to set a region.

Parameters
file_lineFile line to parse
Returns
region properties struct
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _coordinate_frames

std::unordered_map< std::string, std::string > Ds9Importer::_coordinate_frames
staticprivate
Initial value:
{{"physical", "image"}, {"image", "image"}, {"b1950", "B1950"},
{"fk4", "B1950"}, {"j2000", "J2000"}, {"fk5", "J2000"}, {"galactic", "GALACTIC"}, {"ecliptic", "ECLIPTIC"}, {"icrs", "ICRS"},
{"wcs", "UNSUPPORTED"}, {"wcsa", "UNSUPPORTED"}, {"linear", "UNSUPPORTED"}}

DS9 to casacore coordinate frame.

◆ _file_coord_frame

std::string carta::Ds9Importer::_file_coord_frame
private

DS9 coordinate frame converted to casacore, from region file.

◆ _image_coord_frame

std::string carta::Ds9Importer::_image_coord_frame
private

casacore coordinate frame from image coordinate system.

◆ _import_pixels

bool carta::Ds9Importer::_import_pixels
private

The documentation for this class was generated from the following files: