41 using namespace catalogue;
42 using namespace chainmesh;
94 if (!(coord1.size()==coord2.size() && coord2.size()==coord3.size()))
95 ErrorCBL(
"coordinates with different dimensions!",
"Catalogue",
"Catalogue.cpp");
98 vector<double> _weight = weight;
99 if (_weight.size()==0) _weight.resize(coord1.size(), 1);
104 for (
size_t i=0; i<coord1.size(); ++i) {
107 comovingCoordinates coord = {coord1[i], coord2[i], coord3[i]};
108 m_object.push_back(move(Object::Create(objectType, coord, _weight[i])));
111 observedCoordinates coord = {coord1[i], coord2[i], coord3[i]};
112 m_object.push_back(move(Object::Create(objectType, coord, inputUnits, cosm, _weight[i])));
114 else ErrorCBL(
"CoordinateType is not valid!",
"Catalogue",
"Catalogue.cpp");
124 cbl::catalogue::Catalogue::Catalogue (
const ObjectType objectType,
const CoordinateType coordinateType,
const std::vector<std::string> file,
const int col1,
const int col2,
const int col3,
const int colWeight,
const int colRegion,
const double nSub,
const double fact,
const cosmology::Cosmology &cosm,
const CoordinateUnits inputUnits,
const CharEncode charEncode,
const std::string comment,
const int seed)
131 for (
size_t dd=0; dd<file.size(); ++dd) {
133 string line, file_in = file[dd];
135 if (charEncode==CharEncode::_ascii_) {
137 coutCBL <<
"Reading the catalogue: " << file_in << endl;
138 ifstream finr(file_in.c_str());
checkIO(finr, file_in);
140 double Weight, Value;
long Region;
142 long maxRegion = -100000000;
144 while (getline(finr, line)) {
146 if (line.find(comment)==string::npos) {
150 stringstream ss(line);
151 vector<double> value;
while (ss>>Value) value.emplace_back(Value);
152 checkDim(value, col1,
"value",
false);
checkDim(value, col2,
"value",
false);
155 checkDim(value, col3,
"value",
false);
156 comovingCoordinates coord;
157 coord.xx = value[col1-1]*fact;
158 coord.yy = value[col2-1]*fact;
159 coord.zz = value[col3-1]*fact;
160 Weight = (colWeight!=-1 && colWeight-1<(int)value.size()) ? value[colWeight-1] : 1.;
161 Region = (colRegion!=-1 && colRegion-1<(int)value.size()) ? (
long)value[colRegion-1] : 0;
162 m_object.push_back(move(Object::Create(objectType, coord, Weight, Region)));
166 observedCoordinates coord;
167 coord.ra = value[col1-1]*fact;
168 coord.dec = value[col2-1]*fact;
169 coord.redshift = ((int)value.size()>=col3) ? value[col3-1] : 1.;
170 Weight = (colWeight!=-1 && colWeight-1<(int)value.size()) ? value[colWeight-1] : 1.;
171 Region = (colRegion!=-1 && colRegion-1<(int)value.size()) ? (
long)value[colRegion-1] : 0;
172 m_object.push_back(move(Object::Create(objectType, coord, inputUnits, cosm, Weight, Region)));
175 else ErrorCBL(
"CoordinateType is not valid!",
"Catalogue",
"Catalogue.cpp");
177 maxRegion = max(maxRegion, Region);
183 m_nRegions = maxRegion+1;
184 WarningMsgCBL(
"The total number of region is "+
conv(m_nRegions,
par::fINT)+
", deducted from the maximum value of the input regions; if needed, this number can be changed with the function set_region_number()",
"Catalogue",
"Catalogue.cpp");
187 finr.clear(); finr.close();
190 else if (charEncode==CharEncode::_binary_) {
194 coutCBL <<
"Reading the catalogue: " << file_in << endl;
199 ifstream finr(file_in.c_str(), ios::in|ios::binary|ios::ate);
checkIO(finr, file_in);
201 comovingCoordinates coord;
204 finr.seekg(0, ios::beg);
206 finr.read((
char*)(&num_bin), 2);
208 int n_blocks = num_bin;
210 for (
int i=1; i<=n_blocks; ++i) {
211 finr.read((
char*)(&num_bin), 4);
212 int n_objs = num_bin;
214 for (
int j=1; j<=n_objs; ++j) {
215 finr.read((
char*)(&val), 4);
216 coord.xx = (val)*fact;
217 finr.read((
char*)(&val), 4);
218 coord.yy = (val)*fact;
219 finr.read((
char*)(&val), 4);
220 coord.zz = (val)*fact;
223 if (ran()<nSub) m_object.push_back(move(Object::Create(objectType, coord)));
227 finr.read((
char*)(&num_bin), 4);
229 int n_objs2 = num_bin;
231 if (n_objs2!=n_objs)
ErrorCBL(
"wrong reading of input binary file",
"Catalogue",
"Catalogue.cpp");
234 finr.clear(); finr.close();
237 else ErrorCBL(
"charEncode is not valid!",
"Catalogue",
"Catalogue.cpp");
245 cbl::catalogue::Catalogue::Catalogue (
const ObjectType objectType,
const CoordinateType coordinateType,
const std::vector<Var> attribute,
const std::vector<int> column,
const std::vector<std::string> file,
const int comments,
const double nSub,
const double fact,
const cosmology::Cosmology &cosm,
const CoordinateUnits inputUnits,
const char delimiter,
const int seed)
250 if (attribute.size()==column.size()) nvar = attribute.size();
251 else ErrorCBL(
"Column vector and attribute vector must have equal size!",
"Catalogue",
"Catalogue.cpp");
253 if (!(std::is_sorted(column.begin(), column.end())))
ErrorCBL(
"Column vector must be sort in ascending order!",
"Catalogue",
"Catalogue.cpp");
256 unordered_map<int, Var> varMap;
257 for (
size_t ii=0; ii<nvar; ii++)
258 varMap.insert({column[ii], attribute[ii]});
265 for (
size_t dd=0; dd<file.size(); ++dd) {
267 string line, file_in = file[dd];
269 coutCBL <<
"Reading the catalogue: " << file_in << endl;
270 ifstream finr(file_in.c_str());
checkIO(finr, file_in);
276 for (
int cc=0;
cc<comments;
cc++) getline(finr, line);
278 while (getline(finr, line)) {
283 m_object.push_back(move(Object::Create(objectType, defaultComovingCoord, 1.)));
286 m_object.push_back(move(Object::Create(objectType, defaultObservedCoord, inputUnits, cosm, 1.)));
288 else ErrorCBL(
"CoordinateType is not valid!",
"Catalogue",
"Catalogue.cpp");
290 stringstream ss(line);
292 if (delimiter!=
'\t') {
294 stringstream temp(line);
296 while (getline(temp, temp_string, delimiter))
297 ss << temp_string+
" ";
303 size_t ii = nObjects()-1;
306 for (
int jj=1; jj<=
cbl::Max(column); jj++) {
307 if (varMap[column[index]]==Var::_ID_ || varMap[column[index]]==Var::_IDHOST_) {
310 if (std::find(column.begin(), column.end(), jj)!=column.end()) {
311 set_var(ii, varMap[column[index]], Value_i);
317 else if (varMap[column[index]]==Var::_GalaxyTag_) {
319 if (std::find(column.begin(), column.end(), jj)!=column.end()) {
320 set_var(ii, varMap[column[index]], Value_d);
327 if (std::find(column.begin(), column.end(), jj)!=column.end()) {
328 if ((varMap[column[index]]==Var::_RA_) || (varMap[column[index]]==Var::_Dec_)) Value_d =
radians(Value_d, inputUnits);
329 set_var(ii, varMap[column[index]],
330 ((varMap[column[index]]==Var::_X_) || (varMap[column[index]]==Var::_Y_) || (varMap[column[index]]==Var::_Z_)) ?
331 Value_d*fact : Value_d,
340 finr.clear(); finr.close();
354 vector<vector<double>> vars;
356 for (
size_t dd=0; dd<file.size(); ++dd) {
358 string line, file_in = file[dd];
360 coutCBL <<
"Reading the catalogue: " << file_in << endl;
361 ifstream finr(file_in.c_str());
checkIO(finr, file_in);
364 for (
int cc=0;
cc<comments;
cc++) getline(finr, line);
365 while (getline(finr, line)) {
369 stringstream ss(line);
370 vector<double> num;
double NN = -1.e30;
371 while (ss>>NN) num.push_back(NN);
373 m_object.push_back(move(Object::Create(objectType)));
376 for (
size_t i=0; i<column.size(); i++)
377 vv.push_back(num[column[i]-1]);
383 finr.clear(); finr.close();
388 for (
size_t i=0; i<vars.size(); i++)
389 set_var(attribute[i], vars[i]);
399 m_nRegions =
Max(Var::_Region_)+1;
401 WarningMsgCBL(
"The total number of region is "+
conv(m_nRegions,
par::fINT)+
", deducted from the maximum value of the input regions; if needed, this number can be changed with the function set_region_number()",
"Catalogue",
"Catalogue.cpp");
413 vector<long> vv(m_nRegions);
415 for (
size_t i=0; i<m_nRegions; ++i) vv[i] = static_cast<long>(i);
425 vector<long> vv(m_object.size());
427 for (
size_t i=0; i<nObjects(); ++i) vv[i] = m_object[i]->region();
438 vector<string> vv(m_object.size());
440 for (
size_t i=0; i<nObjects(); ++i) vv[i] = m_object[i]->field();
456 vv = m_object[index]->xx();
460 vv = m_object[index]->yy();
464 vv = m_object[index]->zz();
468 vv = m_object[index]->ra();
472 vv = m_object[index]->dec();
476 vv = m_object[index]->ra_tile();
480 vv = m_object[index]->dec_tile();
484 vv = m_object[index]->sn();
487 case Var::_Redshift_:
488 vv = m_object[index]->redshift();
491 case Var::_RedshiftMin_:
492 vv = m_object[index]->redshiftMin();
495 case Var::_RedshiftMax_:
496 vv = m_object[index]->redshiftMax();
500 vv = m_object[index]->shear1();
504 vv = m_object[index]->shear2();
508 vv = m_object[index]->odds();
511 case Var::_LensingWeight_:
512 vv = m_object[index]->lensingWeight();
515 case Var::_LensingCalib_:
516 vv = m_object[index]->lensingCalib();
520 vv = m_object[index]->dc();
524 vv = m_object[index]->weight();
528 vv = m_object[index]->mass();
531 case Var::_Magnitude_:
532 vv = m_object[index]->magnitude();
535 case Var::_MagnitudeU_:
536 vv = m_object[index]->magnitudeU();
539 case Var::_MagnitudeG_:
540 vv = m_object[index]->magnitudeG();
543 case Var::_MagnitudeR_:
544 vv = m_object[index]->magnitudeR();
547 case Var::_MagnitudeI_:
548 vv = m_object[index]->magnitudeI();
552 vv = m_object[index]->SFR();
556 vv = m_object[index]->sSFR();
559 case Var::_MassProxy_:
560 vv = m_object[index]->mass_proxy();
563 case Var::_MassProxyError_:
564 vv = m_object[index]->mass_proxy_error();
568 vv = m_object[index]->mstar();
571 case Var::_MassInfall_:
572 vv = m_object[index]->massinfall();
576 vv = m_object[index]->vx();
580 vv = m_object[index]->vy();
584 vv = m_object[index]->vz();
588 vv = m_object[index]->region();
592 vv = m_object[index]->generic();
596 vv = m_object[index]->radius();
599 case Var::_DensityContrast_:
600 vv = m_object[index]->densityContrast();
603 case Var::_CentralDensity_:
604 vv = m_object[index]->centralDensity();
607 case Var::_X_displacement_:
608 vv = m_object[index]->x_displacement();
611 case Var::_Y_displacement_:
612 vv = m_object[index]->y_displacement();
615 case Var::_Z_displacement_:
616 vv = m_object[index]->z_displacement();
619 case Var::_MassEstimate_:
620 vv = m_object[index]->mass_estimate();
623 case Var::_RadiusEstimate_:
624 vv = m_object[index]->radius_estimate();
627 case Var::_VeldispEstimate_:
628 vv = m_object[index]->veldisp_estimate();
632 vv = m_object[index]->xcm();
636 vv = m_object[index]->ycm();
640 vv = m_object[index]->zcm();
644 vv = m_object[index]->spin_x();
648 vv = m_object[index]->spin_y();
652 vv = m_object[index]->spin_z();
656 vv = m_object[index]->veldisp();
660 vv = m_object[index]->vmax();
664 vv = m_object[index]->vmax_rad();
668 vv = m_object[index]->tot_mass();
672 vv = m_object[index]->ID();
676 vv = m_object[index]->nsub();
680 vv = m_object[index]->parent();
683 case Var::_GalaxyTag_:
684 vv = m_object[index]->galaxyTag();
688 ErrorCBL(
"no such a variable in the list!",
"var",
"Catalogue.cpp");
704 vv = m_object[index]->ID();
708 ErrorCBL(
"no such a variable in the list!",
"var",
"Catalogue.cpp");
718 vector<int> vv(m_object.size(), 0.);
720 for (
size_t i=0; i<nObjects(); ++i) vv[i] = var(i, var_name);
729 vector<double> vv(m_object.size(), 0.);
731 for (
size_t i=0; i<nObjects(); ++i) vv[i] = var(i, var_name);
742 if (var_name==Var::_X_)
743 return m_object[index]->isSet_xx();
745 else if (var_name==Var::_Y_)
746 return m_object[index]->isSet_yy();
748 else if (var_name==Var::_Z_)
749 return m_object[index]->isSet_zz();
751 else if (var_name==Var::_RA_)
752 return m_object[index]->isSet_ra();
754 else if (var_name==Var::_Dec_)
755 return m_object[index]->isSet_dec();
757 else if (var_name==Var::_TileRA_)
758 return m_object[index]->isSet_ra_tile();
760 else if (var_name==Var::_TileDec_)
761 return m_object[index]->isSet_dec_tile();
763 else if (var_name==Var::_SN_)
764 return m_object[index]->isSet_sn();
766 else if (var_name==Var::_Redshift_)
767 return m_object[index]->isSet_redshift();
769 else if (var_name==Var::_RedshiftMin_)
770 return m_object[index]->isSet_redshiftMin();
772 else if (var_name==Var::_RedshiftMax_)
773 return m_object[index]->isSet_redshiftMax();
775 else if (var_name==Var::_Shear1_)
776 return m_object[index]->isSet_shear1();
778 else if (var_name==Var::_Shear2_)
779 return m_object[index]->isSet_shear2();
781 else if (var_name==Var::_ODDS_)
782 return m_object[index]->isSet_odds();
784 else if (var_name==Var::_LensingWeight_)
785 return m_object[index]->isSet_lensingWeight();
787 else if (var_name==Var::_LensingCalib_)
788 return m_object[index]->isSet_lensingCalib();
790 else if (var_name==Var::_Dc_)
791 return m_object[index]->isSet_dc();
793 else if (var_name==Var::_Weight_)
794 return m_object[index]->isSet_weight();
796 else if (var_name==Var::_Mass_)
797 return m_object[index]->isSet_mass();
799 else if (var_name==Var::_Magnitude_)
800 return m_object[index]->isSet_magnitude();
802 else if (var_name==Var::_MagnitudeU_)
803 return m_object[index]->isSet_magnitudeU();
805 else if (var_name==Var::_MagnitudeG_)
806 return m_object[index]->isSet_magnitudeG();
808 else if (var_name==Var::_MagnitudeR_)
809 return m_object[index]->isSet_magnitudeR();
811 else if (var_name==Var::_MagnitudeI_)
812 return m_object[index]->isSet_magnitudeI();
814 else if (var_name==Var::_SFR_)
815 return m_object[index]->isSet_SFR();
817 else if (var_name==Var::_sSFR_)
818 return m_object[index]->isSet_sSFR();
820 else if (var_name==Var::_MassProxy_)
821 return m_object[index]->isSet_mass_proxy();
823 else if (var_name==Var::_MassProxyError_)
824 return m_object[index]->isSet_mass_proxy_error();
826 else if (var_name==Var::_Mstar_)
827 return m_object[index]->isSet_mstar();
829 else if (var_name==Var::_MassInfall_)
830 return m_object[index]->isSet_massinfall();
832 else if (var_name==Var::_Vx_)
833 return m_object[index]->isSet_vx();
835 else if (var_name==Var::_Vy_)
836 return m_object[index]->isSet_vy();
838 else if (var_name==Var::_Vz_)
839 return m_object[index]->isSet_vz();
841 else if (var_name==Var::_Region_)
842 return m_object[index]->isSet_region();
844 else if (var_name==Var::_Generic_)
845 return m_object[index]->isSet_generic();
847 else if (var_name==Var::_Radius_)
848 return m_object[index]->isSet_radius();
850 else if (var_name==Var::_DensityContrast_)
851 return m_object[index]->isSet_densityContrast();
853 else if (var_name==Var::_CentralDensity_)
854 return m_object[index]->isSet_centralDensity();
856 else if (var_name==Var::_X_displacement_)
857 return m_object[index]->isSet_x_displacement();
859 else if (var_name==Var::_Y_displacement_)
860 return m_object[index]->isSet_y_displacement();
862 else if (var_name==Var::_Z_displacement_)
863 return m_object[index]->isSet_z_displacement();
865 else if (var_name==Var::_MassEstimate_)
866 return m_object[index]->isSet_mass_estimate();
868 else if (var_name==Var::_RadiusEstimate_)
869 return m_object[index]->isSet_radius_estimate();
871 else if (var_name==Var::_VeldispEstimate_)
872 return m_object[index]->isSet_veldisp_estimate();
874 else if (var_name==Var::_XCM_)
875 return m_object[index]->isSet_xcm();
877 else if (var_name==Var::_YCM_)
878 return m_object[index]->isSet_ycm();
880 else if (var_name==Var::_ZCM_)
881 return m_object[index]->isSet_zcm();
883 else if (var_name==Var::_XSpin_)
884 return m_object[index]->isSet_spin_x();
886 else if (var_name==Var::_YSpin_)
887 return m_object[index]->isSet_spin_y();
889 else if (var_name==Var::_ZSpin_)
890 return m_object[index]->isSet_spin_z();
892 else if (var_name==Var::_VelDisp_)
893 return m_object[index]->isSet_veldisp();
895 else if (var_name==Var::_Vmax_)
896 return m_object[index]->isSet_vmax();
898 else if (var_name==Var::_VmaxRad_)
899 return m_object[index]->isSet_vmax_rad();
901 else if (var_name==Var::_TotMass_)
902 return m_object[index]->isSet_tot_mass();
904 else if (var_name==Var::_ID_)
905 return m_object[index]->isSet_ID();
907 if (var_name==Var::_GalaxyTag_)
908 return m_object[index]->isSet_galaxyTag();
911 return ErrorCBL(
"no such a variable in the list!",
"isSetVar",
"Catalogue.cpp");
923 while (ret==
true && i<nObjects())
924 ret = isSetVar(i++, var_name);
935 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_region(region[i]);
937 set_region_number(
static_cast<size_t>( (nRegions<0) ? cbl::Max<long>(region)+1 : nRegions) );
946 for (
size_t i=0; i<m_object.size(); i++)
947 if (m_object[i]->region()>=
static_cast<int>(nRegions))
950 m_nRegions = nRegions;
959 for (
size_t i=0; i<m_object.size(); i++) {
960 m_object[i]->set_ra_tile(RA_tile[i], inputUnits);
961 m_object[i]->set_dec_tile(Dec_tile[i], inputUnits);
971 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_field(field[i]);
983 m_object[index]->set_xx(value);
987 m_object[index]->set_yy(value);
991 m_object[index]->set_zz(value);
995 m_object[index]->set_ra(value);
999 m_object[index]->set_dec(value);
1003 m_object[index]->set_sn(value);
1006 case Var::_Redshift_:
1007 m_object[index]->set_redshift(value, cosmology, update_coordinates);
1010 case Var::_RedshiftMin_:
1011 m_object[index]->set_redshiftMin(value);
1014 case Var::_RedshiftMax_:
1015 m_object[index]->set_redshiftMax(value);
1019 m_object[index]->set_shear1(value);
1023 m_object[index]->set_shear2(value);
1027 m_object[index]->set_odds(value);
1030 case Var::_LensingWeight_:
1031 m_object[index]->set_lensingWeight(value);
1034 case Var::_LensingCalib_:
1035 m_object[index]->set_lensingCalib(value);
1039 m_object[index]->set_dc(value);
1043 m_object[index]->set_weight(value);
1047 m_object[index]->set_mass(value);
1050 case Var::_Magnitude_:
1051 m_object[index]->set_magnitude(value);
1054 case Var::_MagnitudeU_:
1055 m_object[index]->set_magnitudeU(value);
1058 case Var::_MagnitudeG_:
1059 m_object[index]->set_magnitudeG(value);
1062 case Var::_MagnitudeR_:
1063 m_object[index]->set_magnitudeR(value);
1066 case Var::_MagnitudeI_:
1067 m_object[index]->set_magnitudeI(value);
1071 m_object[index]->set_SFR(value);
1075 m_object[index]->set_sSFR(value);
1078 case Var::_MassProxy_:
1079 m_object[index]->set_mass_proxy(value);
1082 case Var::_MassProxyError_:
1083 m_object[index]->set_mass_proxy_error(value);
1087 m_object[index]->set_mstar(value);
1090 case Var::_MassInfall_:
1091 m_object[index]->set_massinfall(value);
1095 m_object[index]->set_vx(value);
1099 m_object[index]->set_vy(value);
1103 m_object[index]->set_vz(value);
1107 m_object[index]->set_region(value);
1110 case Var::_Generic_:
1111 m_object[index]->set_generic(value);
1115 m_object[index]->set_radius(value);
1118 case Var::_CentralDensity_:
1119 m_object[index]->set_centralDensity(value);
1122 case Var::_DensityContrast_:
1123 m_object[index]->set_densityContrast(value);
1126 case Var::_X_displacement_:
1127 m_object[index]->set_x_displacement(value);
1130 case Var::_Y_displacement_:
1131 m_object[index]->set_y_displacement(value);
1134 case Var::_Z_displacement_:
1135 m_object[index]->set_z_displacement(value);
1138 case Var::_MassEstimate_:
1139 m_object[index]->set_mass_estimate(value);
1142 case Var::_RadiusEstimate_:
1143 m_object[index]->set_radius_estimate(value);
1146 case Var::_VeldispEstimate_:
1147 m_object[index]->set_veldisp_estimate(value);
1151 m_object[index]->set_xcm(value);
1155 m_object[index]->set_ycm(value);
1159 m_object[index]->set_zcm(value);
1163 m_object[index]->set_spin_x(value);
1167 m_object[index]->set_spin_y(value);
1171 m_object[index]->set_spin_z(value);
1174 case Var::_VelDisp_:
1175 m_object[index]->set_veldisp(value);
1179 m_object[index]->set_vmax(value);
1182 case Var::_VmaxRad_:
1183 m_object[index]->set_vmax_rad(value);
1186 case Var::_TotMass_:
1187 m_object[index]->set_tot_mass(value);
1190 case Var::_GalaxyTag_:
1191 m_object[index]->set_galaxyTag(value);
1195 ErrorCBL(
"no such a variable in the list!",
"set_var",
"Catalogue.cpp");
1209 m_object[index]->set_ID(value);
1214 m_object[index]->set_IDHost(value);
1219 ErrorCBL(
"no such a variable in the list!",
"set_var",
"Catalogue.cpp");
1248 if (m_object.size()!=var.size())
ErrorCBL(
"m_object.size()!=var.size()!",
"set_var",
"Catalogue.cpp");
1253 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_xx(var[i]);
1257 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_yy(var[i]);
1261 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_zz(var[i]);
1265 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_ra(var[i]);
1269 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_dec(var[i]);
1273 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_sn(var[i]);
1276 case Var::_Redshift_:
1277 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_redshift(var[i], cosmology, update_coordinates);
1280 case Var::_RedshiftMin_:
1281 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_redshiftMin(var[i]);
1284 case Var::_RedshiftMax_:
1285 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_redshiftMax(var[i]);
1289 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_shear1(var[i]);
1293 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_shear2(var[i]);
1297 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_odds(var[i]);
1300 case Var::_LensingWeight_:
1301 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_lensingWeight(var[i]);
1304 case Var::_LensingCalib_:
1305 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_lensingCalib(var[i]);
1309 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_dc(var[i]);
1313 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_weight(var[i]);
1317 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_mass(var[i]);
1320 case Var::_Magnitude_:
1321 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_magnitude(var[i]);
1324 case Var::_MagnitudeU_:
1325 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_magnitudeU(var[i]);
1328 case Var::_MagnitudeG_:
1329 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_magnitudeG(var[i]);
1332 case Var::_MagnitudeR_:
1333 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_magnitudeR(var[i]);
1336 case Var::_MagnitudeI_:
1337 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_magnitudeI(var[i]);
1341 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_SFR(var[i]);
1345 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_sSFR(var[i]);
1348 case Var::_MassProxy_:
1349 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_mass_proxy(var[i]);
1352 case Var::_MassProxyError_:
1353 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_mass_proxy_error(var[i]);
1357 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_mstar(var[i]);
1360 case Var::_MassInfall_:
1361 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_massinfall(var[i]);
1365 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_vx(var[i]);
1369 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_vy(var[i]);
1373 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_vz(var[i]);
1378 vector<long> regList(nObjects());
1379 for (
size_t i=0; i<nObjects(); ++i) regList[i] = static_cast<long>(var[i]);
1380 set_region(regList);
1384 case Var::_Generic_:
1385 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_generic(var[i]);
1389 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_radius(var[i]);
1392 case Var::_CentralDensity_:
1393 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_centralDensity(var[i]);
1396 case Var::_DensityContrast_:
1397 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_densityContrast(var[i]);
1400 case Var::_X_displacement_:
1401 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_x_displacement(var[i]);
1404 case Var::_Y_displacement_:
1405 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_y_displacement(var[i]);
1408 case Var::_Z_displacement_:
1409 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_z_displacement(var[i]);
1412 case Var::_MassEstimate_:
1413 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_mass_estimate(var[i]);
1416 case Var::_RadiusEstimate_:
1417 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_radius_estimate(var[i]);
1420 case Var::_VeldispEstimate_:
1421 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_veldisp_estimate(var[i]);
1425 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_xcm(var[i]);
1429 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_ycm(var[i]);
1433 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_zcm(var[i]);
1437 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_spin_x(var[i]);
1441 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_spin_y(var[i]);
1445 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_spin_z(var[i]);
1448 case Var::_VelDisp_:
1449 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_veldisp(var[i]);
1453 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_vmax(var[i]);
1456 case Var::_VmaxRad_:
1457 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_vmax_rad(var[i]);
1460 case Var::_TotMass_:
1461 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_tot_mass(var[i]);
1464 case Var::_GalaxyTag_:
1465 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_galaxyTag(var[i]);
1469 ErrorCBL(
"no such a variable in the list!",
"set_var",
"Catalogue.cpp");
1479 if (m_object.size()!=var.size())
ErrorCBL(
"m_object.size()!=var.size()!",
"set_var",
"Catalogue.cpp");
1484 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_ID(var[i]);
1489 for (
size_t i=0; i<nObjects(); ++i) m_object[i]->set_IDHost(var[i]);
1494 ErrorCBL(
"no such a variable in the list!",
"set_var",
"Catalogue.cpp");
1532 vector<vector<double>> stats;
1534 for (
auto &&vv : var_name)
1535 stats.emplace_back(stats_var(vv));
1544 void cbl::catalogue::Catalogue::var_distr (
const Var var_name, std::vector<double> &_var, std::vector<double> &dist, std::vector<double> &err,
const int nbin,
const bool linear,
const std::string file_out,
const double Volume,
const bool norm,
const double V1,
const double V2,
const std::string bin_type,
const bool convolution,
const double sigma)
const
1546 distribution(_var, dist, err, var(var_name), var(Var::_Weight_), nbin, linear, file_out, (norm) ? Volume*weightedN() : Volume, V1, V2, bin_type,
convolution, sigma);
1555 double red, xx, yy, zz;
1560 vector<double> RA(nObjects()), DEC(nObjects());
1562 for (
size_t i=0; i<nObjects(); ++i) {
1563 RA[i] = (inputUnits==CoordinateUnits::_radians_) ? ra(i) :
radians(ra(i), inputUnits);
1564 DEC[i] = (inputUnits==CoordinateUnits::_radians_) ? dec(i) :
radians(dec(i), inputUnits);
1570 for (
size_t i=0; i<nObjects(); ++i) {
1573 m_object[i]->set_dc(cosm.
D_C(red));
1577 m_object[i]->set_xx(xx);
1578 m_object[i]->set_yy(yy);
1579 m_object[i]->set_zz(zz);
1594 for (
size_t i=0; i<nObjects(); ++i) {
1596 m_object[i]->set_ra(ra);
1597 m_object[i]->set_dec(dec);
1598 m_object[i]->set_dc(dc);
1604 if (outputUnits!=CoordinateUnits::_radians_) {
1606 if (outputUnits==CoordinateUnits::_degrees_)
1607 for (
size_t i=0; i<nObjects(); ++i) {
1608 ra = m_object[i]->ra();
1609 dec = m_object[i]->dec();
1610 m_object[i]->set_ra(
degrees(ra));
1611 m_object[i]->set_dec(
degrees(dec));
1614 else if (outputUnits==CoordinateUnits::_arcseconds_)
1615 for (
size_t i=0; i<nObjects(); ++i) {
1616 ra = m_object[i]->ra();
1617 dec = m_object[i]->dec();
1622 else if (outputUnits==CoordinateUnits::_arcminutes_)
1623 for (
size_t i=0; i<nObjects(); ++i) {
1624 ra = m_object[i]->ra();
1625 dec = m_object[i]->dec();
1630 else ErrorCBL(
"outputUnits type not allowed!",
"computePolarCoordinates",
"Catalogue.cpp");
1645 for (
size_t i=0; i<nObjects(); ++i) {
1647 m_object[i]->set_ra(ra);
1648 m_object[i]->set_dec(dec);
1649 m_object[i]->set_dc(dc);
1650 m_object[i]->set_redshift(cosmology.
Redshift(dc, z1, z2), cosmology);
1656 if (outputUnits!=CoordinateUnits::_radians_) {
1658 if (outputUnits==CoordinateUnits::_degrees_)
1659 for (
size_t i=0; i<nObjects(); ++i) {
1660 m_object[i]->set_ra(
degrees(ra));
1661 m_object[i]->set_dec(
degrees(dec));
1664 else if (outputUnits==CoordinateUnits::_arcseconds_)
1665 for (
size_t i=0; i<nObjects(); ++i) {
1670 else if (outputUnits==CoordinateUnits::_arcminutes_)
1671 for (
size_t i=0; i<nObjects(); ++i) {
1676 else ErrorCBL(
"outputUnits type not allowed!",
"computePolarCoordinates",
"Catalogue.cpp");
1686 for (
size_t i=0; i<nObjects(); ++i) {
1687 m_object[i]->set_xx(xx(i)/dc(i));
1688 m_object[i]->set_yy(yy(i)/dc(i));
1689 m_object[i]->set_zz(zz(i)/dc(i));
1699 for (
size_t i=0; i<nObjects(); ++i) {
1700 m_object[i]->set_xx(xx(i)*dc(i));
1701 m_object[i]->set_yy(yy(i)*dc(i));
1702 m_object[i]->set_zz(zz(i)*dc(i));
1712 const int nObj = m_object.size();
1714 if (
int(vv.size())!=nObj)
1717 vector<shared_ptr<Object>> obj(nObj);
1719 m_index.resize(nObj);
1721 for (
size_t i=0; i<vv.size(); i++) {
1723 obj[i] = m_object[vv[i]];
1735 if (m_index.size()>0) {
1737 const size_t nObj = m_object.size();
1739 if (m_index.size()!=nObj)
1742 vector<shared_ptr<Object>> obj(nObj);
1746 for (
size_t i=0; i<nObj; i++)
1747 m_object[i] = obj[m_index[i]];
1756 for (
size_t i=0; i<m_object.size(); i++)
1757 nn += m_object[i]->weight();
1767 if (m_object.size()==0)
ErrorCBL(
"m_object.size()=0!",
"write_comoving_coordinates",
"Catalogue.cpp");
1769 coutCBL <<
"I'm writing the file: " << outputFile <<
"..." << endl;
1771 ofstream fout(outputFile.c_str());
checkIO(fout, outputFile);
1773 for (
size_t i=0; i<nObjects(); ++i)
1774 fout << xx(i) <<
" " << yy(i) <<
" " << zz(i) << endl;
1776 fout.clear(); fout.close();
1785 if (m_object.size()==0)
ErrorCBL(
"m_object.size()=0!",
"write_obs_coordinates",
"Catalogue.cpp");
1787 coutCBL <<
"I'm writing the file: " << outputFile <<
"..." << endl;
1789 ofstream fout(outputFile.c_str());
checkIO(fout, outputFile);
1792 ErrorCBL(
"polar coordinates are not set!",
"write_obs_coordinates",
"Catalogue.cpp");
1794 for (
size_t i=0; i<nObjects(); ++i)
1795 fout << ra(i) <<
" " << dec(i) <<
" " << redshift(i) << endl;
1797 fout.clear(); fout.close();
1806 coutCBL <<
"Writing the file: " << outputFile <<
"..." << endl;
1808 ofstream fout(outputFile.c_str());
checkIO(fout, outputFile);
1811 fout << header << endl;
1814 if (var_name.size()==0) {
1817 ErrorCBL(
"Polar coordinates are not set!",
"write_data",
"Catalogue.cpp");
1819 if (!
isSet(region(0)))
1820 for (
size_t i=0; i<nObjects(); ++i)
1821 fout << xx(i) << sep << yy(i) << sep << zz(i) << sep << ra(i) << sep << dec(i) << sep << redshift(i) << sep << dc(i) << endl;
1823 for (
size_t i=0; i<nObjects(); ++i)
1824 fout << xx(i) << sep << yy(i) << sep << zz(i) << sep << ra(i) << sep << dec(i) << sep << redshift(i) << sep << dc(i) << sep << region(i) << endl;
1829 vector<vector<double>> data;
1830 for (
size_t j=0; j<var_name.size(); j++)
1831 data.push_back(var(var_name[j]));
1833 for (
size_t i=0; i<nObjects(); ++i) {
1834 for (
size_t j=0; j<data.size(); j++)
1835 fout << data[j][i] << sep;
1841 fout.clear(); fout.close();
1850 vector<shared_ptr<Object>> objects;
1851 vector<bool> w(m_object.size());
1853 bool fact = (excl) ?
false :
true;
1855 for (
size_t i=0; i<m_object.size(); i++)
1856 w[i] = mask(m_object[i])&&fact;
1858 for (
size_t i=0; i<m_object.size(); i++)
1860 objects.push_back(m_object[i]);
1871 vector<shared_ptr<Object>> objects;
1872 vector<bool> w(m_object.size());
1874 bool fact = (excl) ?
false :
true;
1876 for (
size_t i=0; i<m_object.size(); i++)
1877 w[i] = mask(m_object[i])&&fact;
1879 for (
size_t i=0; i<m_object.size(); i++)
1881 objects.push_back(m_object[i]);
1892 vector<shared_ptr<Object>> objects;
1893 vector<double> vvar = var(var_name);
1894 vector<int> w(vvar.size());
1896 for (
size_t i=0; i<m_object.size(); i++) {
1897 w[i] = (excl) ? 1 : 0;
1898 if (vvar[i] >= down && vvar[i] < up)
1899 w[i] = (excl) ? 0 : 1;
1902 for (
size_t i=0; i<m_object.size(); i++)
1904 objects.push_back(m_object[i]);
1915 const double RA_hw = 0.5 * tile_width_RA * (
par::pi/180.);
1916 const double Dec_hw = 0.5 * tile_width_Dec * (
par::pi/180.);
1920 std::vector<long int> dummy_tiles = data.
region();
1921 std::sort(dummy_tiles.begin(), dummy_tiles.end());
1923 const int n_tiles = (int)(unique_tile_numbers.size());
1928 std::vector<double> RA_min (n_tiles);
1929 std::vector<double> RA_max (n_tiles);
1930 std::vector<double> Dec_min (n_tiles);
1931 std::vector<double> Dec_max (n_tiles);
1933 std::vector<bool> isSet_region (n_tiles);
1935 for (
size_t i=0; i<data.
nObjects(); i++) {
1937 if (data.
isSetVar(i, catalogue::Var::_TileRA_) ==
false)
1939 if (data.
isSetVar(i, catalogue::Var::_TileDec_) ==
false)
1941 if (data.
isSetVar(i, catalogue::Var::_Region_) ==
false)
1943 if (data.
var(i, catalogue::Var::_Region_) < 0)
1944 ErrorCBL(
"The tile number for the object "+
cbl::conv(i,
cbl::par::fINT)+
" in the data catalogue is <0. The tile numbers must be all the integers between 0 and N, where N is the highest tile number.",
"sub_catalogue",
"Catalogue.cpp");
1946 if (data.
region(i) < n_tiles)
1947 isSet_region[data.
region(i)] =
true;
1949 ErrorCBL(
"The tile number "+
cbl::conv(i,
cbl::par::fINT)+
" in the data catalogue is greater than the number of tiles. The tile numbers must be all the integers between 0 and N, where N is the highest tile number.",
"sub_catalogue",
"Catalogue.cpp");
1952 double candidate_RA_min = data.
ra_tile(i) - RA_hw/cos(std::abs(data.
dec_tile(i)));
1953 if (candidate_RA_min < 0)
1956 double candidate_RA_max = data.
ra_tile(i) + RA_hw/cos(std::abs(data.
dec_tile(i)));
1960 double candidate_Dec_min = data.
dec_tile(i) - Dec_hw;
1961 double candidate_Dec_max = data.
dec_tile(i) + Dec_hw;
1963 RA_min[data.
region(i)] = candidate_RA_min;
1964 RA_max[data.
region(i)] = candidate_RA_max;
1965 Dec_min[data.
region(i)] = candidate_Dec_min;
1966 Dec_max[data.
region(i)] = candidate_Dec_max;
1970 for (
int i=0; i<n_tiles; i++)
1971 if (isSet_region[i] ==
false)
1972 ErrorCBL(
"The tile number "+
cbl::conv(i,
cbl::par::fINT)+
" in the original catalogue (data) is missing. The tile numbers must be all the integers between 0 and N, where N is the highest tile number.",
"sub_catalogue",
"Catalogue.cpp");
1974 std::vector<bool>().swap(isSet_region);
1979 std::string mkdir =
"mkdir -p "+dir_tiles;
if (system(mkdir.c_str())) {}
1980 std::ofstream myfile; myfile.open(dir_tiles+file_tiles);
1981 myfile <<
"# RA_min RA_max Dec_min Dec_max [all in degrees]" <<std::endl;
1982 for (
int i=0; i<n_tiles; i++)
1985 coutCBL<<
"I wrote the file "+dir_tiles+file_tiles<<std::endl;
1990 std::vector<shared_ptr<Object>> objects;
1992 for (
size_t i=0; i<this->nObjects(); i++) {
1994 for (
int j=0; j<n_tiles; j++) {
1996 if (Dec_min[j] < this->dec(i) && Dec_max[j] > this->dec(i)) {
1998 if (RA_max[j] > RA_min[j]) {
2000 if (RA_min[j] < this->ra(i) && RA_max[j] > this->ra(i)) {
2002 objects.push_back(m_object[i]);
2008 if (RA_min[j] < this->ra(i) || RA_max[j] > this->ra(i)) {
2010 objects.push_back(m_object[i]);
2030 vector<shared_ptr<Object>> objects;
2033 string mangle_dir = path.
DirCosmo()+
"/External/mangle/";
2035 string mangle_working_dir = mangle_dir+
"output/";
2036 string mkdir =
"mkdir -p "+mangle_working_dir;
2037 if (system(mkdir.c_str())) {}
2039 string input = mangle_working_dir+
"temporary.dat";
2040 string output = mangle_working_dir+
"temporary_output.dat";
2042 write_obs_coordinates(input);
2044 string polyid = mangle_dir+
"/bin/polyid -ur "+mangle_mask+
" "+input+
" "+output;
2045 if (system(polyid.c_str())) {}
2047 ifstream fin(output);
2053 while(getline(fin, line))
2055 stringstream ss(line);
2057 while (ss>>NN) num.push_back(NN);
2059 if( !excl && num.size()>2)
2060 objects.push_back(m_object[nn]);
2061 if( excl && num.size()<3)
2062 objects.push_back(m_object[nn]);
2065 fin.clear(); fin.close();
2067 string rm =
"rm "+input+
" "+output;
2068 if (system(rm.c_str())) {}
2078 if (nSub<=0 || nSub>1 || !isfinite(nSub))
ErrorCBL(
"nSub must be in the range (0,1] !",
"diluted_catalogue",
"Catalogue.cpp");
2081 auto diluted_catalogue = *
this;
2084 vector<bool> index(nObjects(),
false);
2087 for (
size_t i=0; i<nObjects()*(1-nSub); ++i) index[i] =
true;
2090 default_random_engine engine(seed);
2091 std::shuffle(begin(index), end(index), engine);
2094 diluted_catalogue.remove_objects(index);
2096 return diluted_catalogue;
2105 return sqrt((m_object[i]->xx()-obj->xx())*(m_object[i]->xx()-obj->xx())+
2106 (m_object[i]->yy()-obj->yy())*(m_object[i]->yy()-obj->yy())+
2107 (m_object[i]->zz()-obj->zz())*(m_object[i]->zz()-obj->zz()));
2116 return 2.*asin(0.5*sqrt((m_object[i]->xx()-obj->xx())*(m_object[i]->xx()-obj->xx())+
2117 (m_object[i]->yy()-obj->yy())*(m_object[i]->yy()-obj->yy())+
2118 (m_object[i]->zz()-obj->zz())*(m_object[i]->zz()-obj->zz())));
2129 shared_ptr<Catalogue> cat {
new Catalogue(*
this)};
2131 if (gridsize<1.e-30)
return cat;
2135 vector<shared_ptr<Object>> sample;
2143 coutCBL <<
"Please wait, I'm subdividing the catalogue in "<<pow(SUB, 3)<<
" sub-catalogues..."<<endl;
2145 int nx = SUB, ny = SUB, nz = SUB;
2147 double Cell_X = (
Max(Var::_X_)-
Min(Var::_X_))/nx;
2148 double Cell_Y = (
Max(Var::_Y_)-
Min(Var::_Y_))/ny;
2149 double Cell_Z = (
Max(Var::_Z_)-
Min(Var::_Z_))/nz;
2150 double MinX =
Min(Var::_X_);
2151 double MinY =
Min(Var::_Y_);
2152 double MinZ =
Min(Var::_Z_);
2154 vector<long> regions(cat->nObjects());
2156 for (
size_t i=0; i<cat->nObjects(); i++) {
2157 int i1 = min(
int((cat->xx(i)-MinX)/Cell_X), nx-1);
2158 int j1 = min(
int((cat->yy(i)-MinY)/Cell_Y), ny-1);
2159 int z1 = min(
int((cat->zz(i)-MinZ)/Cell_Z), nz-1);
2160 long index = z1+nz*(j1+ny*i1);
2164 cat->set_region(regions);
2166 size_t nRegions = cat->nRegions();
2168 vector<Catalogue> subSamples(nRegions);
2170 for (
size_t i=0; i<nRegions; ++i) {
2171 double start = (double)cat->region_list()[i];
2172 double stop = start+1;
2173 subSamples[i] = sub_catalogue(Var::_Region_, start, stop);
2181 for (
size_t rr=0; rr<nRegions; ++rr) {
2183 vector<double> _xx = subSamples[rr].var(Var::_X_), _yy = subSamples[rr].var(Var::_Y_), _zz = subSamples[rr].var(Var::_Z_);
2185 ChainMesh3D ll(gridsize, _xx, _yy, _zz, rMAX, (
long)-1.e5, (
long)1.e5);
2188 for (
int i=0; i<ll.
nCell(); i++) {
2189 vector<long> list = ll.
get_list(i);
2191 int nObj = list.size();
2194 double XX = 0., YY = 0., ZZ = 0., RA = 0., DEC = 0., REDSHIFT = 0., WEIGHT = 0.;
2196 for (
size_t j=0; j<list.size(); j++) {
2197 XX += subSamples[rr].xx(list[j]);
2198 YY += subSamples[rr].yy(list[j]);
2199 ZZ += subSamples[rr].zz(list[j]);
2200 RA += subSamples[rr].ra(list[j]);
2201 DEC += subSamples[rr].dec(list[j]);
2202 REDSHIFT += subSamples[rr].redshift(list[j]);
2203 WEIGHT += subSamples[rr].weight(list[j]);
2206 shared_ptr<Object> obj{
new Object()};
2207 XX /= nObj; obj->
set_xx(XX);
2208 YY /= nObj; obj->set_yy(YY);
2209 ZZ /= nObj; obj->set_zz(ZZ);
2210 RA /= nObj; obj->set_ra(RA);
2211 DEC /= nObj; obj->set_dec(DEC);
2212 REDSHIFT /= nObj; obj->set_redshift(REDSHIFT, cosmology);
2213 obj->set_weight(WEIGHT);
2214 sample.push_back(obj);
2221 shared_ptr<Catalogue> cat_new(
new Catalogue{sample});
2232 vector<double> vvar = var(var_name);
2234 for (
size_t i=0; i<m_object.size(); i++)
2236 if (vvar[i] >= down && vvar[i] < up)
2239 nObjw = (excl) ? weightedN()-nObjw : nObjw;
2251 vector<double> vvar = var(var_name);
2253 for (
size_t i=0; i<m_object.size(); i++)
2254 if (vvar[i] >= down && vvar[i] < up)
2257 nObjw = (excl) ? weightedN()-nObjw : nObjw;
2277 double deltaX = density.
deltaX();
2278 double deltaY = density.
deltaY();
2279 double deltaZ = density.
deltaZ();
2280 int nx = density.
nx();
2281 int ny = density.
ny();
2282 int nz = density.
nz();
2284 for (
size_t i=0; i<nObjects(); ++i) {
2285 int i1 = min(
int((xx(i)-density.
MinX())/deltaX),nx-1);
2286 int j1 = min(
int((yy(i)-density.
MinY())/deltaY),ny-1);
2287 int k1 = min(
int((zz(i)-density.
MinZ())/deltaZ),nz-1);
2289 double w = (useMass) ? mass(i)*weight(i) : weight(i);
2291 if (interpolation_type==0) {
2294 else if (interpolation_type==1) {
2296 double dx = (xx(i)-density.
XX(i1))/deltaX;
2297 double dy = (yy(i)-density.
YY(j1))/deltaY;
2298 double dz = (zz(i)-density.
ZZ(k1))/deltaZ;
2300 int i2 = (dx<0) ? i1-1 : i1+1;
2301 int j2 = (dy<0) ? j1-1 : j1+1;
2302 int k2 = (dz<0) ? k1-1 : k1+1;
2351 double data_tot=0, random_tot=0;
2354 for (
int i=0; i<density.
nx(); i++)
2355 for (
int j=0; j<density.
ny(); j++)
2356 for (
int k=0; k<density.
nz(); k++) {
2363 double mean_random = random_tot/nrandom;
2364 coutCBL <<
"Mean random objects " << mean_random <<
" in " << nrandom <<
" cells " << endl;
2369 for (
int i=0; i<density.
nx(); i++)
2370 for (
int j=0; j<density.
ny(); j++)
2371 for (
int k=0; k<density.
nz(); k++) {
2384 coutCBL <<
"Masked " << masked_cells <<
"/" << nrandom <<
" for bad random coverage " << endl;
2386 double norm = int(random_tot)/data_tot;
2387 for (
int i=0; i<density.
nx(); i++)
2388 for (
int j=0; j<density.
ny(); j++)
2389 for (
int k=0; k<density.
nz(); k++) {
2395 if (kernel_radius>0)
2407 vector<double> fvar_input(nbin, 0);
2408 vector<double> fvar_target(nbin, 0);
2410 vector<double> input_var = input_catalogue.
var(var_name);
2411 vector<double> target_var = target_catalogue.
var(var_name);
2413 double Vmin = target_catalogue.
Min(var_name);
2414 double Vmax = target_catalogue.
Max(var_name);
2416 double binSize_inv = pow((Vmax-Vmin)/nbin, -1);
2418 for (
size_t i=0; i<input_var.size(); i++)
2419 if (input_var[i] < Vmax && Vmin < input_var[i]) {
2420 int occ = max(0, min(
int((input_var[i]-Vmin)*binSize_inv), nbin));
2424 for (
size_t i=0; i<target_var.size(); i++)
2425 if (target_var[i] < Vmax && Vmin < target_var[i]) {
2426 int occ = max(0, min(
int((target_var[i]-Vmin)*binSize_inv), nbin));
2427 fvar_target[occ] ++;
2432 for (
size_t i=0; i<input_var.size(); i++)
2433 if (input_var[i] < Vmax && Vmin < input_var[i]) {
2434 int occ = max(0, min(
int((input_var[i]-Vmin)*binSize_inv), nbin));
2435 if (ran() < fvar_target[occ]/fvar_input[occ])
2436 m_object.push_back(shared_ptr<Object>(input_catalogue.
catalogue_object(i)));
2446 vector< vector<double> > fvars_input(nbin1, vector<double>(nbin2, 0));
2447 vector< vector<double> > fvars_target(nbin1, vector<double>(nbin2, 0));
2449 vector<double> input_var1 = input_catalogue.
var(var_name1);
2450 vector<double> target_var1 = target_catalogue.
var(var_name1);
2451 vector<double> input_var2 = input_catalogue.
var(var_name2);
2452 vector<double> target_var2 = target_catalogue.
var(var_name2);
2454 double V1min = target_catalogue.
Min(var_name1);
2455 double V1max = target_catalogue.
Max(var_name1);
2457 double V2min = target_catalogue.
Min(var_name2);
2458 double V2max = target_catalogue.
Max(var_name2);
2460 double binSize1_inv = pow((V1max-V1min)/nbin1,-1);
2461 double binSize2_inv = pow((V2max-V2min)/nbin2,-1);
2463 for (
size_t i=0; i<input_var1.size(); i++)
2464 if ( (input_var1[i] < V1max && V1min < input_var1[i]) && (input_var2[i] < V2max && V2min < input_var2[i])) {
2465 int occ1 = max(0, min(
int((input_var1[i]-V1min)*binSize1_inv), nbin1));
2466 int occ2 = max(0, min(
int((input_var2[i]-V2min)*binSize2_inv), nbin2));
2467 fvars_input[occ1][occ2] ++;
2470 for (
size_t i=0; i<target_var1.size(); i++)
2471 if ( (target_var1[i] < V1max && V1min < target_var2[i]) && (target_var2[i] < V2max && V2min < target_var2[i])) {
2472 int occ1 = max(0, min(
int((target_var1[i]-V1min)*binSize1_inv), nbin1));
2473 int occ2 = max(0, min(
int((target_var2[i]-V2min)*binSize2_inv), nbin2));
2474 fvars_target[occ1][occ2] ++;
2480 for (
size_t i=0; i<input_var1.size(); i++)
2481 if ((input_var1[i] < V1max && V1min < input_var1[i]) && (input_var2[i] < V2max && V2min < input_var2[i])) {
2482 const int occ1 = max(0, min(
int((input_var1[i]-V1min)*binSize1_inv), nbin1));
2483 const int occ2 = max(0, min(
int((input_var2[i]-V2min)*binSize2_inv), nbin2));
2484 if (ran() < fvars_target[occ1][occ2]/fvars_input[occ1][occ2])
2485 m_object.push_back(shared_ptr<Object>(input_catalogue.
catalogue_object(i)));
2496 if (index.size() != m_object.size())
ErrorCBL (
"argument size not valid!",
"remove_objects",
"Catalogue.cpp");
2498 decltype(m_object) object_temp;
2500 for (
size_t ii = 0; ii<index.size(); ii++)
2501 if (!index[ii]) object_temp.emplace_back(m_object[ii]);
2503 m_object.swap(object_temp);
2512 shared_ptr<Object> temp = m_object[ind1];
2513 m_object[ind1] = m_object[ind2];
2514 m_object[ind2] = temp;
2523 coutCBL <<
"I'm sorting the catalogue..." << endl;
2525 vector<double> variable = var(var_name);
2529 for (
size_t i = 0; i<nObjects()-1; ++i) {
2531 if (variable[i] > variable[i+1]) {
2532 double temp = variable[i];
2533 variable[i] = variable[i+1];
2534 variable[i+1] = temp;
2535 swap_objects(i, i+1);
2540 if (variable[i] < variable[i+1]) {
2541 double temp = variable[i];
2542 variable[i] = variable[i+1];
2543 variable[i+1] = temp;
2544 swap_objects(i, i+1);
2558 coutCBL <<
"I'm shuffling objects in the catalogue..." << endl;
2561 std::mt19937_64 generator;
2562 generator.seed(seed);
2564 std::shuffle(m_object.begin(), m_object.end(), generator);
2573 std::vector<double> prop(5);
2574 double vol =
volume(boxside);
2575 double ndensity = m_object.size()/vol;
2576 double mps = pow(ndensity, -1./3.);
2577 double numdensity_error = pow(m_object.size(), 1./2)/vol;
2578 double mps_error = mps*(1./3)*(numdensity_error/ndensity);
2580 coutCBL <<
"Sample volume = " << vol <<
" (Mpc/h)^3" << endl;
2581 coutCBL <<
"Sample density = " << ndensity <<
" \u00b1 " << numdensity_error <<
" (Mpc/h)^-3" << endl;
2582 coutCBL <<
"Sample mps = " << mps <<
" \u00b1 " << mps_error <<
" Mpc/h" << endl;
2587 prop[3]=numdensity_error;
2597 std::vector<vector<double>> prop(7, vector<double>(nbin));
2598 prop[0] = z_bins(nbin);
2601 double THETA_min = -DEC_range[1]+
par::pi/2, THETA_max = -DEC_range[0]+
par::pi/2;
2602 double delta_PHI = RA_range[1]-RA_range[0];
2605 for (
int i=0; i<(int)nbin; i++) {
2606 auto temp_cat = sub_catalogue(Var::_Redshift_, bin_limits[i], bin_limits[i+1]);
2607 prop[1][i]=temp_cat.nObjects();
2608 prop[2][i]=(-(std::cos(THETA_max)-std::cos(THETA_min))*delta_PHI)/(4*
cbl::par::pi)*
2610 prop[3][i]=temp_cat.nObjects()/prop[2][i];
2611 prop[4][i]=pow(prop[3][i], -1./3.);
2612 vol = vol + prop[2][i];
2613 prop[5][i]=sqrt(prop[1][0])/prop[2][i];
2614 prop[6][i]=prop[4][i]*(1./3)*(prop[5][i]/prop[3][i]);
2617 double numdensity = m_object.size()/vol;
2618 double mps = pow(numdensity, -1./3.);
2619 double numdensity_error = pow(m_object.size(), 1./2)/vol;
2620 double mps_error = mps*(1./3)*(numdensity_error/numdensity);
2622 coutCBL <<
"Sample volume = " << vol <<
" (Mpc/h)^3" << endl;
2623 coutCBL <<
"Sample density = " << numdensity <<
" \u00b1 " << numdensity_error <<
" (Mpc/h)^-3" << endl;
2624 coutCBL <<
"Sample mps = " << mps <<
" \u00b1 " << mps_error <<
" Mpc/h" << endl;
2625 coutCBL <<
"In addiction, volume, density and mps (with errors) have been calculated for " << nbin <<
" slices in redshift, from z = " << bin_limits[0] <<
" to z = " << bin_limits[nbin] << endl;
#define coutCBL
CBL print message.
std::string DirCosmo()
get the directory where the CosmoBolognaLbi are stored
Catalogue()=default
default constructor
size_t nRegions()
get the private member m_nRegions
void remove_objects()
remove all objects remove all objects of the catalogue
void add_objects(std::vector< std::shared_ptr< Object > > sample)
add some objects to the catalogue
void restoreComovingCoordinates()
restore comoving coordinates
double Min(const Var var_name) const
get the minimum value of a variable of the catalogue objects
void normalizeComovingCoordinates()
normalize comoving coordinates
Catalogue sub_catalogue(const Var var_name, const double down, const double up, const bool excl=false) const
create a sub-catalogue
double weightedN_condition(const Var var_name, const double down, const double up, const bool excl=false)
return the weighted number of objectes following a condition on the variable VAR
Catalogue mangle_cut(const std::string mangle_mask, const bool excl=false) const
create a sub-catalogue
size_t nObjects() const
get the number of objects of the catalogue
void set_region_number(const size_t nRegions)
set the private variable m_nRegion
void set_ra_dec_tile(const std::vector< double > RA_tile, const std::vector< double > Dec_tile, const CoordinateUnits inputUnits=CoordinateUnits::_degrees_)
set the central R.A. and Dec of the tiles
void write_comoving_coordinates(const std::string outputFile) const
write the comoving coordinates of the catalogue to an output file
bool isSetVar(const int index, const Var var_name) const
check if the given variable of the i-th object is set
double ra_tile(const int i) const
get the private member Catalogue::m_object[i]->m_ra_tile
void add_object(std::shared_ptr< Object > object)
add one single object to the catalogue
std::shared_ptr< Object > catalogue_object(const int i) const
get the i-th object of the catalogue
void var_distr(const Var var_name, std::vector< double > &_var, std::vector< double > &dist, std::vector< double > &err, const int nbin, const bool linear=true, const std::string file_out=par::defaultString, const double Volume=1., const bool norm=false, const double V1=par::defaultDouble, const double V2=par::defaultDouble, const std::string bin_type="Linear", const bool convolution=false, const double sigma=0.) const
get the distribution of a variable
void set_field(const std::vector< std::string > field)
set a private variable
void write_obs_coordinates(const std::string outputFile) const
write the polar coordinates of the catalogue to an output file
double var(const int index, const Var var_name) const
get the value of the i-th object variable
std::vector< std::vector< double > > compute_catalogueProperties_lightCone(cbl::cosmology::Cosmology cosmology, const std::vector< double > RA_range, const std::vector< double > DEC_range, const unsigned int nbin)
compute catalogue volume, number density and mean particle separation in light cones
void sort(const Var var_name, const bool increasing=false)
bubble sort of a catalogue wrt a variable
data::ScalarField3D density_field(const double cell_size, const Catalogue mask_catalogue, const int interpolation_type=0, const double kernel_radius=0., const bool useMass=false) const
return the density field from object position
double angsep_xyz(const int i, std::shared_ptr< Object > obj) const
get the angular distrance between the i-th object of the catalogue and another object
void computeComovingCoordinates(const cosmology::Cosmology &cosm, const CoordinateUnits inputUnits=CoordinateUnits::_radians_)
compute the comoving coordinates (x, y, z) from the observed coordinates (R.A., Dec,...
int nObjects_condition(const Var var_name, const double down, const double up, const bool excl=false)
return the number of objectes following a condition on the variable VAR
double Max(const Var var_name) const
get the maximum value of a variable of the catalogue objects
double weightedN() const
get the total weight of the objects of the catalogue
void replace_objects(std::vector< T > sample)
replace existing objects with new ones
long region(const int i) const
get the private member Catalogue::m_object[i]->m_region
void computePolarCoordinates(const CoordinateUnits outputUnits=CoordinateUnits::_radians_)
compute the polar coordinates (R.A., Dec, dc) from the comoving coordinates (x, y,...
double distance(const int i, std::shared_ptr< Object > obj) const
get the distrance between the i-th object of the catalogue and another object
void set_region(const std::vector< long > region, const int nRegions=-1)
set a private variable
void set_var(const int index, const Var var_name, const double value, const cosmology::Cosmology cosmology={}, const bool update_coordinates=true)
set a private variable
std::vector< double > compute_catalogueProperties_box(const double boxside)
compute catalogue volume, number density and mean particle separation
std::vector< std::string > field() const
get the values of the object fields
std::vector< double > stats_var(const Var var_name) const
get the mean, the median, the standard deviation, and the difference between the third and first quar...
void write_data(const std::string outputFile, const std::vector< Var > var_name={}, const std::string sep=" ", const std::string header="") const
write both the comoving and polar coordinates, and the regions (if present) of the catalogue to an ou...
std::shared_ptr< Catalogue > smooth(const double gridsize, const cosmology::Cosmology cosmology, const std::vector< Var > vars={}, const int SUB=1)
create a smoothed version of the catalogue averaging quantities on a X, Y, Z grid
void swap_objects(const int ind1, const int ind2)
swap two existing objects
double dec_tile(const int i) const
get the private member Catalogue::m_object[i]->m_dec_tile
int var_int(const int index, const Var var_name) const
get the value of the i-th object integer variable
std::vector< long > region_list() const
get the list of regions in which the catalogue is divided
void Order()
restore the original vector (i.e. the opposite of Order(std::vector<int>))
void shuffle(const int seed)
shuffle objects in the catalogue
std::vector< long > region() const
get the values of the object regions
data::ScalarField3D counts_in_cell(const double cell_size, const int interpolation_type=0, const bool useMass=false, const double minX=par::defaultDouble, const double maxX=par::defaultDouble, const double minY=par::defaultDouble, const double maxY=par::defaultDouble, const double minZ=par::defaultDouble, const double maxZ=par::defaultDouble) const
return the density field from object positions
Catalogue diluted_catalogue(const double nSub, const int seed=3213) const
create a diluted catalogue
The class CatalogueChainMesh.
void set_xx(const double xx)
set the member m_xx
long nCell() const
get the private member ChainMesh::m_nCell_tot
std::vector< long > get_list(const long cell_index) const
get the index of the object inside a cell
double Redshift(const double d_c=1., const double z1_guess=0., const double z2_guess=10., const double prec=0.0001) const
redshift at a given comoving distance
double D_C(const double redshift) const
the comoving line-of-sight distance at a given redshift
double deltaX() const
get the private member m_deltaX
double MaxY() const
get the private member m_MaxY
double MinY() const
get the private member m_MinY
double XX(const int i) const
get the value of the X coordinates at the i-th cell
double deltaZ() const
get the private member m_deltaZ
int ny() const
get the private member m_nY
double MinX() const
get the private member m_MinX
int nx() const
get the private member m_nX
double MaxZ() const
get the private member m_MaxZ
double ZZ(const int i) const
get the value of the Z coordinates at the i-th cell
double deltaY() const
get the private member m_deltaY
int nz() const
get the private member m_nZ
double MinZ() const
get the private member m_MinZ
double YY(const int i) const
get the value of the Y coordinates at the i-th cell
double MaxX() const
get the private member m_MaxX
double ScalarField(const int i, const int j, const int k) const
get the value of the scalar field
void GaussianConvolutionField(const double kernel_size)
perform a smoothing of the field with a gaussian kernel
void set_ScalarField(const double value, const int i, const int j, const int k, const bool add=0)
set the value of the scalar field
static const char fINT[]
conversion symbol for: int -> std::string
static const double defaultDouble
default double value
static const double pi
: the ratio of a circle's circumference to its diameter
static const double cc
: the speed of light in vacuum (the value is exact) [km/sec]
std::function< bool(const std::shared_ptr< Object > obj)> mask_function
Definition of a new type to manage mask function.
Var
the catalogue variables
ObjectType
the object types
CharEncode
character encoding of input file
The global namespace of the CosmoBolognaLib
void distribution(std::vector< double > &xx, std::vector< double > &fx, std::vector< double > &err, const std::vector< double > FF, const std::vector< double > WW, const int nbin, const bool linear=true, const std::string file_out=par::defaultString, const double fact=1., const double V1=par::defaultDouble, const double V2=par::defaultDouble, const std::string bin_type="Linear", const bool conv=false, const double sigma=0.)
derive and store the number distribution of a given std::vector
T Min(const std::vector< T > vect)
minimum element of a std::vector
std::string conv(const T val, const char *fact)
convert a number to a std::string
double Average(const std::vector< double > vect)
the average of a std::vector
CoordinateType
the coordinate type
@ _observed_
observed coordinates (R.A., Dec, redshift)
@ _comoving_
comoving coordinates (x, y, z)
std::vector< T > different_elements(const std::vector< T > vect_input)
get the unique elements of a std::vector
T volume_sphere(const T RR)
the volume of a sphere of a given radius
double j2(const double xx)
the l=2 spherical Bessel function
bool isSet(const std::string var)
check if the value of a [string] variable has already been set
std::vector< T > linear_bin_vector(const size_t nn, const T min, const T max)
fill a std::vector with linearly spaced values
void checkDim(const std::vector< T > vect, const int val, const std::string vector, bool equal=true)
check if the dimension of a std::vector is equal/lower than an input value
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened
void cartesian_coord(const double ra, const double dec, const double dd, double &XX, double &YY, double &ZZ)
conversion from polar coordinates to Cartesian coordinates
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
T Max(const std::vector< T > vect)
maximum element of a std::vector
std::vector< std::vector< T > > transpose(std::vector< std::vector< T >> matrix)
transpose a matrix
double radians(const double angle, const CoordinateUnits inputUnits=CoordinateUnits::_degrees_)
conversion to radians
double Sigma(const std::vector< double > vect)
the standard deviation of a std::vector
std::vector< double > Quartile(const std::vector< double > Vect)
the first, second and third quartiles of a std::vector
double volume(const double boxSize, const int frac, const double Bord, const double mean_redshift, cosmology::Cosmology &real_cosm)
get the volume of a simulation box
double degrees(const double angle, const CoordinateUnits inputUnits=CoordinateUnits::_radians_)
conversion to degrees
CoordinateUnits
the coordinate units
void WarningMsgCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL)
internal CBL warning message
void convolution(const std::vector< double > f1, const std::vector< double > f2, std::vector< double > &res, const double deltaX)
convolution of two functions
double arcseconds(const double angle, const CoordinateUnits inputUnits=CoordinateUnits::_radians_)
conversion to arcseconds
void polar_coord(const double XX, const double YY, const double ZZ, double &ra, double &dec, double &dd)
conversion from Cartesian coordinates to polar coordinates
double arcminutes(const double angle, const CoordinateUnits inputUnits=CoordinateUnits::_radians_)
conversion to arcminutes
object that encapsulate the mask function.