mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 15:21:11 +00:00
Merged in python3 (pull request #5)
Port to python3, large code cleanup * Fixed command line for cosmotool * Fix path * Dump command line is log file * Fix important typo * Modify paths for example * Fix path again * Use an explicit constructor * Change file to open (python 2->3) * python3 fix for xrange in periodic_kdtree.py * Fixed index for Np, numPart, numZones, numZonesTot, partID, zoneID in catalogUtil.py
This commit is contained in:
parent
8249256508
commit
affb56ff48
392 changed files with 4092 additions and 260938 deletions
|
@ -17,118 +17,121 @@
|
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
+*/
|
||||
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <netcdfcpp.h>
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include "particleInfo.hpp"
|
||||
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include <cstdlib>
|
||||
#include <netcdf>
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
using namespace netCDF;
|
||||
|
||||
template<bool failure>
|
||||
double retrieve_attr_safe_double(NcFile& f, const char *name, double defval)
|
||||
{
|
||||
NcAtt *a = f.get_att(name);
|
||||
if (a == 0)
|
||||
{
|
||||
if (failure)
|
||||
abort();
|
||||
return defval;
|
||||
}
|
||||
return a->as_double(0);
|
||||
template <bool failure>
|
||||
double retrieve_attr_safe_double(NcFile& f, const char* name, double defval) {
|
||||
NcGroupAtt a = f.getAtt(name);
|
||||
if (a.isNull()) {
|
||||
if (failure) abort();
|
||||
return defval;
|
||||
}
|
||||
if (a.getAttLength() != 1) {
|
||||
abort();
|
||||
}
|
||||
double x;
|
||||
a.getValues(&x);
|
||||
return x;
|
||||
}
|
||||
|
||||
template<bool failure>
|
||||
int retrieve_attr_safe_int(NcFile& f, const char *name, int defval)
|
||||
{
|
||||
NcAtt *a = f.get_att(name);
|
||||
if (a == 0)
|
||||
{
|
||||
if (failure)
|
||||
abort();
|
||||
return defval;
|
||||
}
|
||||
return a->as_int(0);
|
||||
template <bool failure>
|
||||
int retrieve_attr_safe_int(NcFile& f, const char* name, int defval) {
|
||||
NcGroupAtt a = f.getAtt(name);
|
||||
if (a.isNull()) {
|
||||
if (failure) abort();
|
||||
return defval;
|
||||
}
|
||||
if (a.getAttLength() != 1) {
|
||||
abort();
|
||||
}
|
||||
int x;
|
||||
a.getValues(&x);
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
bool loadParticleInfo(ParticleInfo& info, const std::string& particles,
|
||||
const std::string& extra_info) {
|
||||
int numpart;
|
||||
int isObservation;
|
||||
|
||||
bool loadParticleInfo(ParticleInfo& info,
|
||||
const std::string& particles,
|
||||
const std::string& extra_info)
|
||||
{
|
||||
int numpart;
|
||||
int isObservation;
|
||||
try {
|
||||
NcFile f_info(extra_info, NcFile::read);
|
||||
|
||||
NcFile f_info(extra_info.c_str());
|
||||
NcError nerr(NcError::verbose_nonfatal);
|
||||
|
||||
if (!f_info.is_valid())
|
||||
return false;
|
||||
info.ranges[0][0] =
|
||||
retrieve_attr_safe_double<true>(f_info, "range_x_min", 0);
|
||||
info.ranges[0][1] =
|
||||
retrieve_attr_safe_double<true>(f_info, "range_x_max", 0);
|
||||
info.ranges[1][0] =
|
||||
retrieve_attr_safe_double<true>(f_info, "range_y_min", 0);
|
||||
info.ranges[1][1] =
|
||||
retrieve_attr_safe_double<true>(f_info, "range_y_max", 0);
|
||||
info.ranges[2][0] =
|
||||
retrieve_attr_safe_double<true>(f_info, "range_z_min", 0);
|
||||
info.ranges[2][1] =
|
||||
retrieve_attr_safe_double<true>(f_info, "range_z_max", 0);
|
||||
info.mask_index = retrieve_attr_safe_int<true>(f_info, "mask_index", 0);
|
||||
isObservation = retrieve_attr_safe_int<false>(f_info, "is_observation", 0);
|
||||
|
||||
info.ranges[0][0] = retrieve_attr_safe_double<true>(f_info, "range_x_min", 0);
|
||||
info.ranges[0][1] = retrieve_attr_safe_double<true>(f_info, "range_x_max", 0);
|
||||
info.ranges[1][0] = retrieve_attr_safe_double<true>(f_info, "range_y_min", 0);
|
||||
info.ranges[1][1] = retrieve_attr_safe_double<true>(f_info, "range_y_max", 0);
|
||||
info.ranges[2][0] = retrieve_attr_safe_double<true>(f_info, "range_z_min", 0);
|
||||
info.ranges[2][1] = retrieve_attr_safe_double<true>(f_info, "range_z_max", 0);
|
||||
info.mask_index = retrieve_attr_safe_int<true>(f_info, "mask_index", 0);
|
||||
isObservation = retrieve_attr_safe_int<false>(f_info, "is_observation", 0);
|
||||
for (int i = 0; i < 3; i++)
|
||||
info.length[i] = info.ranges[i][1] - info.ranges[i][0];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
info.length[i] = info.ranges[i][1] - info.ranges[i][0];
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
UnformattedRead f(particles);
|
||||
|
||||
float mul, offset;
|
||||
|
||||
|
||||
f.beginCheckpoint();
|
||||
numpart = f.readInt32();
|
||||
f.endCheckpoint();
|
||||
|
||||
|
||||
info.particles.resize(numpart);
|
||||
|
||||
|
||||
offset = info.ranges[0][0];
|
||||
// TEST PMS NON-COBIC BOXES
|
||||
//mul = 1.0;
|
||||
// mul = 1.0;
|
||||
mul = info.ranges[0][1] - info.ranges[0][0];
|
||||
f.beginCheckpoint();
|
||||
for (int i = 0; i < numpart; i++)
|
||||
info.particles[i].x = mul*f.readReal32();
|
||||
info.particles[i].x = mul * f.readReal32();
|
||||
f.endCheckpoint();
|
||||
|
||||
|
||||
offset = info.ranges[1][0];
|
||||
//mul = 1.0;
|
||||
// mul = 1.0;
|
||||
mul = info.ranges[1][1] - info.ranges[1][0];
|
||||
f.beginCheckpoint();
|
||||
for (int i = 0; i < numpart; i++)
|
||||
info.particles[i].y = mul*f.readReal32();
|
||||
info.particles[i].y = mul * f.readReal32();
|
||||
f.endCheckpoint();
|
||||
|
||||
|
||||
offset = info.ranges[2][0];
|
||||
//mul = 1.0;
|
||||
// mul = 1.0;
|
||||
mul = info.ranges[2][1] - info.ranges[2][0];
|
||||
f.beginCheckpoint();
|
||||
for (int i = 0; i < numpart; i++)
|
||||
info.particles[i].z = mul*f.readReal32();
|
||||
info.particles[i].z = mul * f.readReal32();
|
||||
f.endCheckpoint();
|
||||
|
||||
if (!isObservation) {
|
||||
for (int i = 0; i < numpart; i++) {
|
||||
info.particles[i].x += info.ranges[0][0];
|
||||
info.particles[i].y += info.ranges[1][0];
|
||||
info.particles[i].z += info.ranges[2][0];
|
||||
info.particles[i].x += info.ranges[0][0];
|
||||
info.particles[i].y += info.ranges[1][0];
|
||||
info.particles[i].z += info.ranges[2][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const NoSuchFileException& e)
|
||||
{
|
||||
} catch (NoSuchFileException const& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (exceptions::NcCantRead const&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue