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:
#include <iostream>
#include <vector>
#include <memory>
using namespace Euclid::SourceCatalog;
using namespace std;
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;
shared_ptr<Attribute> coordinates_1_ptr { new Coordinates{ra_1, dec_1} };
shared_ptr<Attribute> coordinates_2_ptr { new Coordinates{ra_2, dec_2} };
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:
double z_value = 3.;
double z_error = 0.01;
shared_ptr<Attribute> spec_redshift_ptr { new SpectroscopicRedshift {z_value, z_error} };
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:
cout<<
" Z value : " <<
dynamic_pointer_cast<SpectroscopicRedshift>(spec_redshift_ptr)->getValue() << endl;
cout<<
" Z error : " <<
dynamic_pointer_cast<SpectroscopicRedshift>(spec_redshift_ptr)->getError() << endl;
Output
Z value : 3
Z error : 0.01
The Photometry Attribute
We define the Photometry Attribute as follows:
Photometry photometry {filter_name_vector_ptr, photometry_vector};
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.
shared_ptr<vector<std::string>> filter_name_vector_ptr { new vector<std::string> { filter_name_1, filter_name_2 } };
const double flux_1 = 0.46575674;
const double error_1 = 0.00001534;
const double flux_2 = 0.01537575674;
const double error_2 = 0.00354616;
vector<FluxErrorPair> photometry_vector { FluxErrorPair(flux_1,error_1), FluxErrorPair(flux_2, error_2) };
shared_ptr<Attribute> photometry_ptr { new Photometry { filter_name_vector_ptr, photometry_vector } };
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:
for (
auto photo_iter = dynamic_pointer_cast<Photometry>(photometry_ptr)->
begin(); photo_iter !=
dynamic_pointer_cast<Photometry>(photometry_ptr)->
end(); ++photo_iter) {
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:
vector<shared_ptr<Attribute>> attribute_vector_1 {coordinates_1_ptr, spec_redshift_ptr, photometry_ptr};
vector<shared_ptr<Attribute>> attribute_vector_2 {coordinates_2_ptr, spec_redshift_ptr};
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:
Source source_1{ 10000, attribute_vector_1};
Source source_2{ 20000, attribute_vector_2};
vector<Source> source_vector { source_1, source_2 };
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
shared_ptr<Coordinates> coord_ptr(source_1.getAttribute<Coordinates>());
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 catalog{ source_vector };
The size Function
To know the size of a Catalog object, use the size function as follows:
cout<<" Catalog size : " << catalog.size() << endl;
Output:
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.
shared_ptr<Coordinates> coordinates(secondSource->getAttribute<Coordinates>());
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() {
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;
double z_value = 3.;
double z_error = 0.01;
cout << " " << endl;
cout << "--> SpectroscopicRedshift Class" << endl;
cout << " " << endl;
const double flux_1 = 0.46575674;
const double error_1 = 0.00001534;
const double flux_2 = 0.01537575674;
const double error_2 = 0.00354616;
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 source_1{ 10000, attribute_vector_1};
Source source_2{ 20000, attribute_vector_2};
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;
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;
}
cout<<" Right Ascension : " << coordinates->getRa() <<endl;
cout<<" Declinaison : " << coordinates->getDec() <<endl;
}