34 #define MAXPATHLEN MAX_PATH
52int TestUtil::ti[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
53float TestUtil::tf[] = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5};
55const char * TestUtil::EMDATA_HEADER_EXT =
".head";
56const char * TestUtil::EMDATA_DATA_EXT =
".data";
58string TestUtil::progname =
"";
60int TestUtil::get_debug_int(
int i)
73 sprintf(a,
"%d%d", i+1, i+1);
79 vector<Transform> v(3);
80 for (
int j=0; j<3; j++) {
90 char imgpath[MAXPATHLEN];
91 char * path_env = getenv(
"DEBUG_IMAGE_PATH");
93 sprintf(imgpath,
"%s/%s", path_env, imagename.c_str());
96 sprintf(imgpath,
"%s/images/%s", getenv(
"HOME"), imagename.c_str());
98 return string(imgpath);
103 char imgpath[MAXPATHLEN];
104 char * path_env = getenv(
"DEBUG_IMAGE_PATH");
106 sprintf(imgpath,
"%s/testdata/%s", path_env, imagename.c_str());
109 sprintf(imgpath,
"%s/images/testdata/%s", getenv(
"HOME"), imagename.c_str());
111 return string(imgpath);
117 vector<float> array = d[
"floatarray"];
118 for (
size_t i = 0; i < array.size(); i++) {
120 LOGDEBUG(
"floatarray[%d] = %f\n", i, array[i]);
125 EMData * img = d[
"emdata"];
127 int nx = img->get_xsize();
128 int ny = img->get_ysize();
129 int nz = img->get_zsize();
133 LOGDEBUG(
"image size = (%d, %d, %d)\n", nx, ny, nz);
144 float f = d[
"float"];
150 int l = (int)d[
"long"];
156 string s = (
const char*)d[
"string"];
163 XYData *xyd = d[
"xydata"];
165 for (
size_t i = 0; i < nitems; i++) {
166 float xi = xyd->
get_x(i);
167 float yi = xyd->
get_y(i);
168 LOGDEBUG(
"xydata[%d] = (%f,%f)\n", i, xi, yi);
174 if (d.
has_key(
"stringarray")) {
175 vector<string> array = d[
"stringarray"];
176 for (
size_t i = 0; i < array.size(); i++) {
178 LOGDEBUG(
"stringarray[%d] = %s\n", i, array[i].c_str());
182 if (d.
has_key(
"transformarray")) {
183 vector<Transform> array = d[
"transformarray"];
184 for (
size_t i = 0; i < array.size(); i++) {
198 LOGDEBUG(
"IntPoint p = (%d, %d, %d)\n", p[0], p[1], p[2]);
207 LOGDEBUG(
"FloatPoint p = (%f, %f, %f)\n", p[0], p[1], p[2]);
217 LOGDEBUG(
"IntSize p = (%d, %d, %d)\n", p[0], p[1], p[2]);
227 LOGDEBUG(
"FloatSize p = (%f, %f, %f)\n", p[0], p[1], p[2]);
237 LOGDEBUG(
"Vec3i p = (%d, %d, %d)\n", p[0], p[1], p[2]);
246 LOGDEBUG(
"Vec3f p = (%f, %f, %f)\n", p[0], p[1], p[2]);
254 map<string, int>::const_iterator p;
255 for (p = d.begin(); p != d.end(); p++) {
256 LOGDEBUG(
"map[\"%s\"] = %d; ", p->first.c_str(), p->second);
257 r[p->first] = p->second;
266 map<string, long>::const_iterator p;
267 for (p = d.begin(); p != d.end(); p++) {
268 LOGDEBUG(
"map[\"%s\"] = %d; ", p->first.c_str(), p->second);
269 r[p->first] = p->second;
277 map<string, float> r;
278 map<string, float>::const_iterator p;
279 for (p = d.begin(); p != d.end(); p++) {
280 LOGDEBUG(
"map[\"%s\"] = %f; ", p->first.c_str(), p->second);
281 r[p->first] = p->second;
289 map<string, string> r;
290 map<string, string>::const_iterator p;
291 for (p = d.begin(); p != d.end(); p++) {
292 LOGDEBUG(
"map[\"%s\"] = %s; ", p->first.c_str(), p->second.c_str());
293 r[p->first] = p->second;
301 map<string, EMObject> r;
302 map<string, EMObject>::const_iterator p;
303 for (p = d.begin(); p != d.end(); p++) {
304 LOGDEBUG(
"map[\"%s\"] = %f; ", p->first.c_str(), (
float)(p->second));
314 map<string, vector<string> > r;
322 for (
size_t i = 0; i < v.size(); i++) {
334 for (
size_t i = 0; i < v.size(); i++) {
346 for (
size_t i = 0; i < v.size(); i++) {
347 LOGDEBUG(
"v[%d]=%d; ", i, (
int)v[i]);
358 for (
size_t i = 0; i < v.size(); i++) {
359 LOGDEBUG(
"v[%d]=%s; ", i, v[i].c_str());
369 for (
size_t i = 0; i < v.size(); i++) {
371 LOGDEBUG(
"Image(%d,%d,%d); ", e->get_xsize(), e->get_ysize(), e->get_zsize());
381 for (
size_t i = 0; i < v.size(); i++) {
395 vector<string> keys = d.
keys();
396 sort(keys.begin(), keys.end());
398 for (
size_t i = 0; i < keys.size(); i++) {
399 LOGDEBUG(
"keys[%s] = %f\n", keys[i].c_str(), (
float)d[keys[i]]);
401 Assert(((
float)d[keys[i]]) ==
tf[i]);
402 r[keys[i]] = d[keys[i]];
415 char imgpath[MAXPATHLEN];
416 char * path_env = getenv(
"DEBUG_IMAGE_PATH");
418 sprintf(imgpath,
"%s/testdata/%s/", path_env,
progname.c_str());
421 sprintf(imgpath,
"%s/images/testdata/%s/", getenv(
"HOME"),
progname.c_str());
424 string headerfile2 = string(imgpath) + headerfile1;
425 string datafile2 = string(imgpath) + datafile1;
440 string diffcmd1 =
"diff " + headerfile1 +
" " + headerfile2;
442 int err = system(diffcmd1.c_str());
444 string diffcmd2 =
"diff " + datafile1 +
" " + datafile2;
445 err = system(diffcmd2.c_str());
448 LOGERR(
"check_image on %s FAILED\n", imagefile.c_str());
459 e->read_image(filename);
474 FILE *hfile = fopen(headerfile.c_str(),
"wb");
479 vector<string> excl_keys;
480 excl_keys.push_back(
"MRC.label");
481 excl_keys.push_back(
"IMAGIC.minute");
482 excl_keys.push_back(
"IMAGIC.sec");
484 Dict attr_dict = image->get_attr_dict();
485 vector < string > keys = attr_dict.
keys();
489 for (
size_t i = 0; i < keys.size(); i++) {
491 bool is_exclude =
false;
492 for (
size_t j = 0; j < excl_keys.size(); j++) {
499 fprintf(hfile,
"%s = %s\n", keys[i].c_str(),
500 attr_dict[keys[i]].
to_str().c_str());
505 fprintf(hfile,
"nx = %d\n", image->get_xsize());
506 fprintf(hfile,
"ny = %d\n", image->get_ysize());
507 fprintf(hfile,
"nz = %d\n", image->get_zsize());
512 FILE *dfile = fopen(datafile.c_str(),
"wb");
517 int nx = image->get_xsize();
518 int ny = image->get_ysize();
519 int nz = image->get_zsize();
521 size_t row_size = nx *
sizeof(float);
522 size_t nxy = nx * ny;
523 float *
rdata = image->get_data();
525 for (
int i = 0; i < nz; i++) {
526 for (
int j = 0; j < ny; j++) {
527 fwrite(&
rdata[i * nxy + j * nx], row_size, 1, dfile);
543 int nx,
int ny,
int nz)
546 e->set_size(nx, ny, nz);
550 e->set_attr(
"datatype", (
int)datatype);
551 float * data = e->get_data();
554 for (
int i = 0; i < nz; i++) {
555 for (
int j = 0; j < ny; j++) {
556 for (
int k = 0; k < nx; k++) {
560 else if (mode == 2) {
569 e->write_image(filename, 0, image_type,
false, 0, datatype,
true);
573 e->set_attr(
"is_complex",
false);
574 EMData * fft = e->do_fft();
575 fft->write_image(filename, 0, image_type,
false, 0, datatype,
true);
593 int nx,
int ny,
int nz)
598 e->read_image(filename);
600 Dict attr_dict = e->get_attr_dict();
607 if (nx != (
int) attr_dict[
"nx"]) {
608 LOGERR(
"nx: %d != %d\n", nx, (
int) attr_dict[
"nx"]);
612 if (ny != (
int) attr_dict[
"ny"]) {
613 LOGERR(
"ny: %d != %d\n", ny, (
int) attr_dict[
"ny"]);
617 if (nz != (
int) attr_dict[
"nz"]) {
618 LOGERR(
"nz: %d != %d\n", nz, (
int) attr_dict[
"nz"]);
622 if (datatype != (
int) attr_dict[
"datatype"]) {
623 LOGERR(
"datatype: %d != %d\n", datatype, (
int) attr_dict[
"datatype"]);
628 if ((
int)
is_complex != (
int) attr_dict[
"is_complex"]) {
629 LOGERR(
"is_complex: %d != %d\n",
is_complex, (
int) attr_dict[
"is_complex"]);
635 float * data = e->get_data();
637 for (
int i = 0; i < nz; i++) {
638 for (
int j = 0; j < ny; j++) {
639 for (
int k = 0; k < nx; k++) {
645 else if (mode == 2) {
649 if ((
int)data[l] != d2) {
650 LOGERR(
"(%d,%d,%d): %d != %d\n", i,j,k,(
int)data[l], d2);
709 for (
int i = 0; i < 3; i++) {
719 for (
int i = 0; i < 3; i++) {
727 vector<Transform> v(3);
728 for (
int i=0; i<3; i++) {
Ctf is the base class for all CTF model.
Dict is a dictionary to store <string, EMObject> pair.
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
vector< string > keys() const
Get a vector containing all of the (string) keys in this dictionary.
EMData stores an image's data and defines core image processing routines.
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
EMDataType
Image pixel data type used in EMAN.
static bool is_complex_type(EMDataType datatype)
ImageType
Image format types.
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
FloatSize is used to describe a 1D, 2D or 3D rectangular size in floating numbers.
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
IntSize is used to describe a 1D, 2D or 3D rectangular size in integers.
Pixel describes a 3D pixel's coordinates and its intensity value.
static map< string, string > test_map_string(const map< string, string > &d)
static string get_golden_image(const string &imagename)
static vector< int > test_vector_int(const vector< int > &v)
static string get_debug_image(const string &imagename)
static const char * EMDATA_HEADER_EXT
static vector< long > test_vector_long(const vector< long > &v)
static void set_progname(const string &cur_progname)
static string get_debug_string(int i)
static float get_pixel_value_by_dist2(int nx, int ny, int nz, int x, int y, int z)
static vector< EMData * > test_vector_emdata(const vector< EMData * > &v)
static float get_pixel_value_by_dist1(int nx, int ny, int nz, int x, int y, int z)
static int verify_image_file_by_mode(const string &filename, EMUtil::ImageType image_type, int mode, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static EMObject emobject_transformarray_to_py()
static int check_image(const string &imagefile, EMData *image=0)
static EMObject emobject_farray_to_py()
static float get_debug_float(int i)
static map< string, long > test_map_long(const map< string, long > &d)
static IntSize test_IntSize(const IntSize &p)
static void dump_image_from_file(const string &filename)
static Dict test_dict(const Dict &d)
static Vec3i test_Vec3i(const Vec3i &p)
static const char * EMDATA_DATA_EXT
static map< string, vector< string > > test_map_vecstring(const map< string, vector< string > > &d)
static vector< Pixel > test_vector_pixel(const vector< Pixel > &v)
static void make_image_file_by_mode(const string &filename, EMUtil::ImageType image_type, int mode, EMUtil::EMDataType datatype=EMUtil::EM_FLOAT, int nx=16, int ny=16, int nz=1)
static void to_emobject(const Dict &d)
static FloatSize test_FloatSize(const FloatSize &p)
static EMObject emobject_strarray_to_py()
static IntPoint test_IntPoint(const IntPoint &p)
static Transform get_debug_transform(int i)
static map< string, int > test_map_int(const map< string, int > &d)
static EMObject emobject_to_py(bool b)
static FloatPoint test_FloatPoint(const FloatPoint &p)
static vector< string > test_vector_string(const vector< string > &v)
static Vec3f test_Vec3f(const Vec3f &p)
static map< string, EMObject > test_map_emobject(const map< string, EMObject > &d)
static vector< float > test_vector_float(const vector< float > &v)
static void dump_emdata(EMData *image, const string &filename)
static map< string, float > test_map_float(const map< string, float > &d)
static bool sstrncmp(const char *s1, const char *s2)
Safe string compare.
static bool is_file_exist(const string &filename)
check whether a file exists or not
static string sbasename(const string &filename)
Get a filename's basename.
XYData defines a 1D (x,y) data set.
float get_y(size_t i) const
float get_x(size_t i) const
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
#define FileAccessException(filename)
const char * to_str(Gatan::TagData::Type type)