Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
SourceCatalog Module

Developers quick start guide

This module builds a vector container of Source objects, a map of source identification and an index which is the location of the Source object in the vector container.

Includes and Namespaces

In all code examples we present in the next sections, we assume that the following lines are included by default:

Note that namespaces are used to make the example code more readable.

The Source Class

Before creating a Catalog object we need to create a vector of Source objects. A Source object consists of a source identification number and a vector of shared pointers to Attribute objects. There are three Attribute objects for a Source : Photometry, SpectroscopicRedshift and Coordinates objects.

The Coordinates Attribute

We define the Coordinates Attribute as follows:

double ra_1 = 181.4657;
double dec_1 = -36.27363;
double ra_2 = 281.4657;
double dec_2 = -26.27363;
Store the Right Ascension (Ra) and Delination (Dec) of a source in decimal degrees,...
Definition Coordinates.h:41

In this example, we define two Coordinates objects. A Coordinate object is defined by two double values, the right ascension (e.g. ra_1) and the declinaison (e.g. dec_1). The getRa and getDec functions are available for this class for getting the right ascension and the declinaison value. They are used as follows:

Note that we need to use the dynamic_pointer_cast here.

Output

Right ascension : 181.466
Declinaison : -36.2736

The SpectroscopicRedshift Attribute

We define the SpectroscopicRedshift Attribute as follows:

In the above example a SpectroscopicRedshift object needs two double values, a redshift value and the associated error.

The getValue and getError Functions

The SpectroscopicRedshift class provides two functions, getValue and getError. They can be used as follows:

Output

Z value : 3
Z error : 0.01

The Photometry Attribute

We define the Photometry Attribute as follows:

The Photometry object needs two parameters. The filter_name_vector_ptr parameter is a shared pointer to a vector of strings and the photometry_vector parameter is a vector of FluxErrorPair objects. The FluxErrorPair objects consist of a couple of double values, the flux and the error associated to this flux. The following example shows how to define them.

// Creation of the filter_name_vector_ptr pointer
const std::string filter_name_1 { "COSMOS/g_SDSS" };
const std::string filter_name_2 { "COSMOS/r_SDSS" };
// Creation of the vector of FluxErrorPair objects
const double flux_1 = 0.46575674;
const double error_1 = 0.00001534;
const double flux_2 = 0.01537575674;
const double error_2 = 0.00354616;
// Creation of the Photometry pointer

The find Function

The Photometry class provides the find function as follows:

cout<<" Photometry Flux : " << ptr1->flux << endl;
cout<<" Photometry Error : " << ptr1->error << endl;

Output:

Photometry Flux : 0.465757
Photometry Error : 1.534e-05

The begin and end Iterators

The Photometry class provides an iterator for reading the data as follows:

cout<<" Photometry Filtername : " << photo_iter.filterName() << " Photometry Flux : " << (*photo_iter).flux << " Photometry Error : " << (*photo_iter).error << endl;
}

Output

Photometry Filtername : COSMOS/g_SDSS Photometry Flux : 0.465757 Photometry Error : 1.534e-05
Photometry Filtername : COSMOS/r_SDSS Photometry Flux : 0.0153758 Photometry Error : 0.00354616

The Source Object

Now we need to create a vector of shared pointers to the Attribute objects for building a Source object as follows:

Note that for the needs of the next examples, we have created two attruibute vectors. From this step we are ready to create the Source objects as follows:

// Store Source objects in a vector
The Source class includes all information related to a sky source.
Definition Source.h:48

The Source object needs an identifier(a number) and a vector of shared pointers to its Attribute objects. In this example above we have created two Source objects as a Catalog object needs a vector of Source objects.

The getId Function

cout<<" Source Identifier : " << source_1.getId() << endl;

Output:

Source Identifier : 10000

The getAttribute Function

cout<<" Right ascension : " << coord_ptr->getRa() << endl;
cout<<" Declinaison : " << coord_ptr->getDec() << endl;

Output:

Right ascension : 181.466
Declinaison : -36.2736

The Catalog Class

From this step we can create a Catalog object providing the vector of Source objects as follows:

Catalog contains a container of sources.
Definition Catalog.h:47

The size Function

To know the size of a Catalog object, use the size function as follows:

cout<<" Catalog size : " << catalog.size() << endl;

Output:

Catalog size : 2

The cbegin and cend Iterators

The catalog class provides an iterator in order to play with the Catalog contents, hereafter we display for instance the Source identifier as follows:

for (auto it = catalog.cbegin(); it != catalog.cend(); ++it ) {
cout<<" Catalog Source ID : " << it->getId() <<endl;
}

Output:

Catalog Source ID : 10000
Catalog Source ID : 20000

The find Function?

To find a Source object in the Catalog using the identification number (e.g. 20000), proceed as follows:

shared_ptr<Source> secondSource(catalog.find(20000));

In this example we try to find the Source with the identifier number 20000. A nullptr is returned in case of no Source found. In our case, we know the Source object exists and we can display some information of the Source as the coordinates for instance.

cout<<" Right Ascension : " << coordinates->getRa() <<endl;
cout<<" Declinaison : " << coordinates->getDec() <<endl;

Output:

Right Ascension : 281.466
Declinaison : -26.2736

The Entire Code

#include <iostream>
#include <vector>
#include <memory>
using namespace Euclid::SourceCatalog;
using namespace std;
int main() {
// ---------------------------------------------------------------------------
// Coordinates Class
// ---------------------------------------------------------------------------
double ra_1 = 181.4657;
double dec_1 = -36.27363;
double ra_2 = 281.4657;
double dec_2 = -26.27363;
cout << " " << endl;
cout << "--> Coordinates Class" << endl;
cout << " " << endl;
// ---------------------------------------------------------------------------
// SpectroscopicRedshift Class
// ---------------------------------------------------------------------------
double z_value = 3.;
double z_error = 0.01;
cout << " " << endl;
cout << "--> SpectroscopicRedshift Class" << endl;
cout << " " << endl;
// ---------------------------------------------------------------------------
// Photometry Class
// ---------------------------------------------------------------------------
// Creation of the filter_name_vector_ptr pointer
const std::string filter_name_1 { "COSMOS/g_SDSS" };
const std::string filter_name_2 { "COSMOS/r_SDSS" };
// Creation of the vector of FluxErrorPair objects
const double flux_1 = 0.46575674;
const double error_1 = 0.00001534;
const double flux_2 = 0.01537575674;
const double error_2 = 0.00354616;
// Creation of the Photometry pointer
cout << " " << endl;
cout << "--> Photometry Class" << endl;
cout << " " << endl;
cout<<" Photometry Flux : " << ptr1->flux << endl;
cout<<" Photometry Error: " << ptr1->error << endl;
cout<<" Photometry Filtername : " << photo_iter.filterName() << " Photometry Flux : " << (*photo_iter).flux << " Photometry Error : " << (*photo_iter).error << endl;
}
// ---------------------------------------------------------------------------
// Source Class
// ---------------------------------------------------------------------------
// Store Source objects in a vector
cout << " " << endl;
cout << "--> Source Class" << endl;
cout << " " << endl;
cout<<" Source Identifier : " << source_1.getId() << endl;
cout<<" Right ascension : " << coord_ptr->getRa() << endl;
cout<<" Declinaison : " << coord_ptr->getDec() << endl;
// ---------------------------------------------------------------------------
// Catalog Class
// ---------------------------------------------------------------------------
Catalog catalog{ source_vector };
cout << " " << endl;
cout << "--> Catalog Class" << endl;
cout << " " << endl;
cout<<" Catalog size : " << catalog.size() << endl;
for (auto it = catalog.cbegin(); it != catalog.cend(); ++it ) {
cout<<" Catalog Source ID : " << it->getId() <<endl;
}
shared_ptr<Source> secondSource(catalog.find(20000));
cout<<" Right Ascension : " << coordinates->getRa() <<endl;
cout<<" Declinaison : " << coordinates->getDec() <<endl;
}
T begin(T... args)
T endl(T... args)