EMAN2
emdata_metadata.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
36#ifndef emdata__metadata_h__
37#define emdata__metadata_h__
38
39public:
45EMData *get_fft_amplitude();
46
52EMData *get_fft_amplitude2D();
53
59EMData *get_fft_phase();
60
64#ifdef EMAN2_USING_CUDA
65inline float *get_data() const
66{
67 if(rdata == 0){
68 rdata = (float*)malloc(num_bytes);
69 cudadirtybit = 1;
70 }
71 if(cudadirtybit == 1){
72 cudadirtybit = 0;
73 cudaMemcpy(rdata,cudarwdata,num_bytes,cudaMemcpyDeviceToHost);
74 }
75 return rdata;
76}
77#else
78inline float *get_data() const { return rdata; }
79#endif
80
84inline const float * get_const_data() const { return get_data(); }
85
93inline void set_data(float* data, const int x, const int y, const int z) {
94 if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
95#ifdef EMAN2_USING_CUDA
96 //cout << "set data" << endl;
97// free_cuda_memory();
98#endif
99 rdata = data;
100 nx = x; ny = y; nz = z;
101 nxy = nx*ny;
102 nxyz = (size_t)nx*ny*nz;
103 update();
104}
105
106inline void set_data(float* data) {
107 rdata = data;
108}
109
120void write_data(string fsp,size_t loc,const Region* const area=0,const int file_nx=0, const int file_ny=0, const int file_nz=0);
121
133void read_data(string fsp,size_t loc,const Region* area=0,const int file_nx=0, const int file_ny=0, const int file_nz=0);
134
135
136
138inline void update()
139{
140 flags |= EMDATA_NEEDUPD;
141 changecount++;
142#ifdef FFT_CACHING
143 if (fftcache!=0) { delete fftcache; fftcache=0; }
144#endif //FFT_CACHING
145
146}
147
149inline void clearupdate()
150{
151 flags &= ~EMDATA_NEEDUPD;
152 changecount--;
153}
154
158inline bool has_ctff() const
159{
160 if (this->has_attr("ctf")) {
161 return true;
162 }
163 else {
164 return false;
165 }
166}
167
168
173float calc_center_density();
174
175
180float calc_sigma_diff();
181
182
186IntPoint calc_min_location() const;
187
188
192IntPoint calc_max_location() const;
193
202IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1, float *value = 0);
203
211vector<float> calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
212
217FloatPoint calc_center_of_mass(const float threshold=0);
218
223size_t calc_min_index() const;
224
225
230size_t calc_max_index() const;
231
232
242vector<Pixel> calc_highest_locations(float threshold) const;
243
249vector<Pixel> calc_n_highest_locations(int n);
250
255vector<Pixel> find_pixels_with_value(float val);
256
262float get_edge_mean() const;
263
264
269float get_circle_mean();
270
271
275Ctf * get_ctf() const;
276
277
281void set_ctf(Ctf * ctf);
282
283
289inline Vec3f get_translation() const
290{
291 return all_translation;
292}
293
294
299inline void set_translation(const Vec3f &t)
300{
301 all_translation = t;
302}
303
304
311inline void set_translation(float dx, float dy, float dz)
312{
313 all_translation = Vec3f(dx, dy, dz);
314}
315
316
320inline Transform get_transform() const
321{
322 Dict rotation_dict;
323 rotation_dict["type"] = "eman";
324 rotation_dict["alt"] = attr_dict["euler_alt"];
325 rotation_dict["az"] = attr_dict["euler_az"];
326 rotation_dict["phi"] = attr_dict["euler_phi"];
327
328 Transform trans;
329 trans.to_identity();
330 trans.set_rotation(rotation_dict);
331
332 return trans;
333}
334
342inline void set_rotation(float az, float alt, float phi)
343{
344 attr_dict["orientation_convention"] = "EMAN";
345 attr_dict["euler_alt"]=alt;
346 attr_dict["euler_az"]=az;
347 attr_dict["euler_phi"]=phi;
348}
349
350
356inline void set_rotation(const Transform& t3d)
357{
358 Dict d = t3d.get_rotation("eman");
359 attr_dict["orientation_convention"] = "EMAN";
360 attr_dict["euler_alt"] = (float) d["alt"];
361 attr_dict["euler_az"] = (float) d["az"];
362 attr_dict["euler_phi"] = (float) d["phi"];;
363}
364
365
373void set_size(int nx, int ny=1, int nz=1, bool noalloc=false);
374
375#ifdef EMAN2_USING_CUDA
383void set_size_cuda(int nx, int ny=1, int nz=1);
384#endif //#EMAN2_USING_CUDA
385
386
393void set_complex_size(int nx, int ny=1, int nz=1) {
394 set_size(nx*2, ny, nz);
395}
396
397
401inline void set_path(const string & new_path)
402{
403 path = new_path;
404}
405
406
410inline void set_pathnum(int n)
411{
412 pathnum = n;
413}
414
415
424MArray2D get_2dview() const;
425
426
435MArray3D get_3dview() const;
436
437
445MCArray2D get_2dcview() const;
446
447
455MCArray3D get_3dcview() const;
456
457
466EMObject get_attr(const string & attr_name) const;
467
477EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
478
484void set_attr(const string & key, EMObject val);
485
486
492void set_attr_python(const string & key, EMObject val);
493
498inline bool has_attr(const string& key) const {
499 return attr_dict.has_key(key);
500}
501
508Dict get_attr_dict() const;
509
510#ifdef EMAN2_USING_CUDA
516inline Dict get_attr_dict_cuda() const {return attr_dict;}
517#endif
518
523void set_attr_dict(const Dict & new_dict);
524
525
526
531 void del_attr(const string & attr_name);
532
533
538 void del_attr_dict(const vector<string> & del_keys);
539
540
544inline int get_xsize() const
545{
546 return nx;
547}
548
549
553inline int get_ysize() const
554{
555 return ny;
556}
557
558
562inline int get_zsize() const
563{
564 return nz;
565}
566
567
568inline IntSize get_sizes() const
569{
570 return IntSize(get_xsize(), get_ysize(), get_zsize());
571}
572
573
577inline size_t get_size() const
578{
579 return (size_t)nx*(size_t)ny*(size_t)nz;
580}
581
585inline vector<float> get_data_as_vector() const {
586 size_t size = get_size();
587 vector<float> v(size);
588 float* data = get_data();
589 std::copy(data,data+size,v.begin());
590 return v;
591}
592
596inline int get_ndim() const
597{
598 if (nz <= 1) {
599 if (ny <= 1) {
600 return 1;
601 }
602 else {
603 return 2;
604 }
605 }
606
607 return 3;
608}
609
610
614inline bool is_shuffled() const
615{ // PRB
616 if (flags & EMDATA_SHUFFLE) {
617 return true;
618 }
619
620 if(has_attr("is_shuffled")) {
621 return get_attr("is_shuffled");
622 }
623
624 return false;
625}
626
627
631inline bool is_FH() const
632{ // PRB
633 if (flags & EMDATA_FH) {
634 return true;
635 }
636
637 if(has_attr("is_fh")) {
638 return get_attr("is_fh");
639 }
640
641 return false;
642}
643
644
648inline bool is_complex() const
649{
650 if(attr_dict.has_key("is_complex")) {
651 if (int(attr_dict["is_complex"])) {
652 return true;
653 }
654 else {
655 return false;
656 }
657 }
658 else {
659 return false;
660 }
661}
662
663
667inline bool is_real() const
668{
669 return !is_complex();
670}
671
672
677inline void set_shuffled(bool is_shuffled)
678{ // PRB
679 if (is_shuffled) {
680// printf("entered correct part of set_shuffled \n");
681// flags |= EMDATA_SHUFFLE;
682 set_attr("is_shuffled", (int)1);
683 }
684 else {
685// flags &= ~EMDATA_SHUFFLE;
686 set_attr("is_shuffled", (int)0);
687 }
688}
689
690
695inline void set_FH(bool is_FH)
696{ // PRB
697 if (is_FH) {
698// flags |= EMDATA_FH;
699 set_attr("is_fh", (int)1);
700 }
701 else {
702// flags &= ~EMDATA_FH;
703 set_attr("is_fh", (int)0);
704 }
705}
706
707
712inline void set_complex(bool is_complex)
713{
714 if (is_complex) {
715 attr_dict["is_complex"] = int(1);
716 }
717 else {
718 attr_dict["is_complex"] = int(0);
719 }
720}
721
722
727inline bool is_complex_x() const
728{
729 if(attr_dict.has_key("is_complex_x")) {
730 if (int(attr_dict["is_complex_x"])) {
731 return true;
732 }
733 else {
734 return false;
735 }
736 }
737 else {
738 return false;
739 }
740}
741
742;
748{
749 if (is_complex_x) {
750 attr_dict["is_complex_x"] = int(1);
751 }
752 else {
753 attr_dict["is_complex_x"] = int(0);
754 }
755}
756
757
761inline bool is_flipped() const
762{
763 if (flags & EMDATA_FLIP) { //keep here for back compatibility
764 return true;
765 }
766
767 if(attr_dict.has_key("is_flipped")) {
768 if(get_attr("is_flipped")) {
769 return true;
770 }
771 }
772
773 return false;
774
775}
776
777
782inline void set_flipped(bool is_flipped)
783{
784 if (is_flipped) {
785 set_attr("is_flipped", (int)1);
786 }
787 else {
788 set_attr("is_flipped", (int)0);
789 }
790}
791
792
797inline bool is_ri() const
798{
799 if(attr_dict.has_key("is_complex_ri")) {
800 if (int(attr_dict["is_complex_ri"])) {
801 return true;
802 }
803 else {
804 return false;
805 }
806 }
807 else {
808 return false;
809 }
810}
811
812
817inline void set_ri(bool is_ri)
818{
819 if (is_ri) {
820 attr_dict["is_complex_ri"] = int(1);
821 }
822 else {
823 attr_dict["is_complex_ri"] = int(0);
824 }
825}
826
827
831inline bool is_fftpadded() const
832{
833 if (flags & EMDATA_PAD) {
834 return true;
835 }
836
837 if(has_attr("is_fftpad")) {
838 return get_attr("is_fftpad");
839 }
840
841 return false;
842
843}
844
845
850inline void set_fftpad(bool is_fftpadded)
851{
852 if (is_fftpadded) {
853 set_attr("is_fftpad", int(1));
854 }
855 else {
856 set_attr("is_fftpad", int(0));
857 }
858}
859
860
864inline bool is_fftodd() const
865{
866 if(flags & EMDATA_FFTODD) {
867 return true;
868 }
869 else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
870 return true;
871 }
872 else {
873 return false;
874 }
875}
876
877
882inline void set_fftodd(bool is_fftodd)
883{
884 if (is_fftodd) {
885 set_attr("is_fftodd", int(1));
886 }
887 else {
888 set_attr("is_fftodd", int(0));
889 }
890}
891
892
896inline void set_nxc(int nxc)
897{
898 attr_dict["nxc"] = nxc;
899}
900
901/******************************************************************************
902 ** These functions are used for EMData's pickling, do not use it for *
903 * other purpose, e.g. get flags of a EMData object *
904 * ***************************************************************************/
905inline int get_flags() const
906{
907 return flags;
908}
909
910inline void set_flags(int f)
911{
912 flags = f;
913}
914
915inline int get_changecount() const
916{
917 return changecount;
918}
919
920inline void set_changecount(int c)
921{
922 changecount = c;
923}
924
925inline int get_xoff() const
926{
927 return xoff;
928}
929
930inline int get_yoff() const
931{
932 return yoff;
933}
934
935inline int get_zoff() const
936{
937 return zoff;
938}
939
940inline void set_xyzoff(int x, int y, int z)
941{
942 xoff = x;
943 yoff = y;
944 zoff = z;
945}
946
952void scale_pixel(float scale_factor) const;
953
954inline string get_path() const
955{
956 return path;
957}
958
959inline int get_pathnum() const
960{
961 return pathnum;
962}
963
964//vector<float> get_data_pickle() const;
965EMBytes get_data_pickle() const;
966
967//void set_data_pickle(const vector<float>& vf);
968void set_data_pickle(std::string vf);
969
970//we don't actually pickle supp, just a place holder to set supp to NULL
971int get_supp_pickle() const;
972
973void set_supp_pickle(int i);
974
975vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
976
982float get_amplitude_thres(float thres);
983
984private:
990void set_attr_dict_explicit(const Dict & new_dict);
991
992/*****************************************************************************/
993
994#endif //emdata__metadata_h__
#define rdata(i)
Definition: analyzer.cpp:592
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
void set_path(const string &new_path)
Set the path.
void read_data(string fsp, size_t loc, const Region *area=0, const int file_nx=0, const int file_ny=0, const int file_nz=0)
Read the image pixel data in native byte order from a disk file.
bool is_fftodd() const
Does this image correspond to a (real-space) odd nx?
vector< Pixel > calc_n_highest_locations(int n)
Calculate and return a sorted list of N highest pixels in the map.
EMObject get_attr(const string &attr_name) const
The generic way to get any image header information given a header attribute name.
EMData * get_fft_amplitude()
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
int get_flags() const
void set_flags(int f)
const float * get_const_data() const
Get the image pixel density data in a 1D float array - const version of get_data.
bool is_fftpadded() const
Is this image already extended along x for ffts?
void set_fftodd(bool is_fftodd)
Mark this image as having (real-space) odd nx.
void set_rotation(float az, float alt, float phi)
Define the 3D orientation of this particle, also used to indicate relative rotations for reconstructi...
float get_amplitude_thres(float thres)
return the FFT amplitude which is greater than thres %
void set_pathnum(int n)
Set the number of paths.
IntSize get_sizes() const
void set_complex_size(int nx, int ny=1, int nz=1)
Resize 'this' complex image.
bool is_real() const
Is this a real image?
int get_changecount() const
vector< Vec3i > mask_contig_region(const float &val, const Vec3i &seed)
int get_ysize() const
Get the image y-dimensional size.
void set_fftpad(bool is_fftpadded)
Mark this image as already extended along x for ffts.
void set_ri(bool is_ri)
Mark this image as a real/imaginary format complex image.
void del_attr_dict(const vector< string > &del_keys)
Delete the attributes from the dictionary.
bool has_ctff() const
check whether the image physical file has the CTF info or not.
int get_zoff() const
vector< Pixel > find_pixels_with_value(float val)
Find pixels in the image with exactly the specified values.
vector< float > calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1)
Calculates the wrapped coordinates of the maximum value, and uses quadration intp to subpixel prec Th...
Transform get_transform() const
Get the 3D orientation of 'this' image.
void set_attr_dict_explicit(const Dict &new_dict)
Make the attributes of this EMData exactly equal to the argument dictionary Originally introduced bec...
void set_FH(bool is_FH)
Mark this complex image as a FH image.
void set_attr_python(const string &key, EMObject val)
Set a header attribute's value from Python.
void set_attr_dict(const Dict &new_dict)
Merge the new values with the existing dictionary.
void set_flipped(bool is_flipped)
Mark this image as flipped.
void set_changecount(int c)
void write_data(string fsp, size_t loc, const Region *const area=0, const int file_nx=0, const int file_ny=0, const int file_nz=0)
Dump the image pixel data in native byte order to a disk file.
int get_yoff() const
MArray2D get_2dview() const
Get image raw pixel data in a 2D multi-array format.
size_t calc_max_index() const
Calculates the index of maximum-value pixel when assuming all pixels are in a 1D array.
bool is_ri() const
Is this image a real/imaginary format complex image?
Ctf * get_ctf() const
Get ctf parameter of this image.
bool is_complex() const
Is this a complex image?
void set_nxc(int nxc)
Set the number of complex elements along x.
IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1, float *value=0)
Calculates the wrapped coordinates of the maximum value This function is useful in the context of Fou...
string get_path() const
int get_xoff() const
EMData * get_fft_amplitude2D()
return the amplitudes of the 2D FFT including the left half PRB
IntPoint calc_min_location() const
Calculates the coordinates of the minimum-value pixel.
void set_translation(const Vec3f &t)
Set 'this' images' translation vector from the original location.
void set_supp_pickle(int i)
bool is_flipped() const
Is this image flipped?
void set_shuffled(bool is_shuffled)
Mark this image as a shuffled image.
bool is_shuffled() const
Has this image been shuffled?
void set_data_pickle(std::string vf)
EMBytes get_data_pickle() const
Dict get_attr_dict() const
Get the image attribute dictionary containing all the image attribute names and attribute values.
void scale_pixel(float scale_factor) const
Scale the angstrom per pixel of this image by a uniform amount Alters the EMData metadata I had to ma...
int get_zsize() const
Get the image z-dimensional size.
void del_attr(const string &attr_name)
Delete the attribute from dictionary.
int get_xsize() const
Get the image x-dimensional size.
void set_data(float *data, const int x, const int y, const int z)
Set the data explicitly data pointer must be allocated using malloc!
int get_pathnum() const
MCArray3D get_3dcview() const
Get complex image raw pixel data in a 3D multi-array format.
EMData * get_fft_phase()
return the phases of the FFT including the left half
int get_ndim() const
Get image dimension.
size_t calc_min_index() const
Calculates the index of minimum-value pixel when assuming all pixels are in a 1D array.
void set_ctf(Ctf *ctf)
Set the CTF parameter of this image.
bool is_complex_x() const
Is this image a 1D FFT image in X direction?
void clearupdate()
turn off updates.
vector< float > get_data_as_vector() const
Get the pixel data as a vector.
IntPoint calc_max_location() const
Calculates the coordinates of the maximum-value pixel.
bool has_attr(const string &key) const
Ask if the header has a particular attribute.
void set_size(int nx, int ny=1, int nz=1, bool noalloc=false)
Resize this EMData's main board memory pointer.
float get_circle_mean()
Calculates the circular edge mean by applying a circular mask on 'this' image.
void update()
Mark EMData as changed, statistics, etc will be updated at need.
MCArray2D get_2dcview() const
Get complex image raw pixel data in a 2D multi-array format.
float calc_center_density()
Calculates the density value at the peak of the image histogram, sort of like the mode of the density...
bool is_FH() const
Is this a FH image?
MArray3D get_3dview() const
Get image raw pixel data in a 3D multi-array format.
EMObject get_attr_default(const string &attr_name, const EMObject &em_obj=EMObject()) const
The generic way to get any image header information given a header attribute name.
float * get_data() const
Get the image pixel density data in a 1D float array.
void set_attr(const string &key, EMObject val)
Set a header attribute's value.
void set_xyzoff(int x, int y, int z)
size_t get_size() const
Get the number of allocated floats in the image (nx*ny*nz)
void set_complex_x(bool is_complex_x)
Marks this image a 1D FFT image in X direction.
Vec3f get_translation() const
Get 'this' image's translation vector from the original location.
vector< Pixel > calc_highest_locations(float threshold) const
Calculate and return a sorted list of pixels whose values are above a specified threshold.
float calc_sigma_diff()
Calculates sigma above and below the mean and returns the difference between them.
void set_complex(bool is_complex)
Mark this image as a complex image.
int get_supp_pickle() const
float get_edge_mean() const
Calculates the mean pixel values around the (1 pixel) edge of the image.
FloatPoint calc_center_of_mass(const float threshold=0)
Calculate the center of mass with a threshold (Default 0, so only positive values are considered)
boost::multi_array_ref< std::complex< float >, 3 > MCArray3D
Definition: emdata.h:71
boost::multi_array_ref< float, 3 > MArray3D
Definition: emdata.h:69
Vec3< float > Vec3f
Definition: vec3.h:693
boost::multi_array_ref< float, 2 > MArray2D
Definition: emdata.h:68
Vec3< int > Vec3i
Definition: vec3.h:694
boost::multi_array_ref< std::complex< float >, 2 > MCArray2D
Definition: emdata.h:70
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517