Xmipp  v3.23.11-Nereus
Functions
Collaboration diagram for Spider:

Functions

void generate_Spider_count (int imax, DocFile &DF_out)
 
void translate_to_Spider_sel (MetaData &SF_in, DocFile &DF_out, bool new_style)
 
void extract_angles (MetaData &SF_in, DocFile &DF_out, const std::string &ang1="rot", const std::string &ang2="tilt", const std::string &ang3="psi", bool fromMetadata=false)
 
void rename_for_Spider (MetaData &SF_in, MetaData &SF_out, const FileName &fn_root, const FileName &out_ext)
 

Detailed Description

Function Documentation

◆ extract_angles()

void extract_angles ( MetaData SF_in,
DocFile DF_out,
const std::string &  ang1 = "rot",
const std::string &  ang2 = "tilt",
const std::string &  ang3 = "psi",
bool  fromMetadata = false 
)

Extract angles from a SelFile and store them in a DocFile. You can specify the order of the angle extraction by default (rot, tilt, psi). An exception is thrown if the angles are not one of these.

Definition at line 88 of file spider.cpp.

91 {
92  checkAngle(ang1);
93  checkAngle(ang2);
94  checkAngle(ang3);
95 
96  DF_out.clear();
97 
98  FileName auxFn;
99 
100  SF_in.getValue( MDL_IMAGE, auxFn, SF_in.firstRowId() );
101 
102  DF_out.append_comment((std::string)"Angles for " + auxFn +
103  ". Angle order: " + ang1 + " " + ang2 + " " + ang3);
104 
105  int i = 0;
106  time_config();
107  std::cerr << "Extracting angles ...\n";
108  init_progress_bar(SF_in.size());
109  Image<double> P;
110  FileName fn_img;
111  ApplyGeoParams params;
112  params.datamode = HEADER;
113 
114  for (size_t objId: SF_in.ids())
115  {
116  if (fromMetadata)
117  {
118  double rot;
119  SF_in.getValue(MDL_ANGLE_ROT, rot, objId);
120  double tilt;
121  SF_in.getValue(MDL_ANGLE_TILT, tilt, objId);
122  double psi;
123  SF_in.getValue(MDL_ANGLE_PSI, psi, objId);
124  DF_out.append_angles(rot, tilt, psi,
125  ang1, ang2, ang3);
126  }
127  else
128  {
129  // Read image
130  SF_in.getValue(MDL_IMAGE, fn_img, objId);
131  if (fn_img=="")
132  break;
133  P.readApplyGeo(fn_img, SF_in, objId, params);
134  DF_out.append_angles(P.rot(), P.tilt(), P.psi(),
135  ang1, ang2, ang3);
136  }
137  i++;
138  if (i % 10 == 0)
139  progress_bar(i);
140  }
141 
142  progress_bar(SF_in.size());
143 }
void init_progress_bar(long total)
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
virtual size_t firstRowId() const =0
int append_angles(double rot, double tilt, double psi, const std::string &ang1, const std::string &ang2, const std::string &ang3)
Definition: docfile.cpp:1014
Special label to be used when gathering MDs in MpiMetadataPrograms.
virtual IdIteratorProxy< false > ids()
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
#define i
void time_config()
void checkAngle(const String &str)
void progress_bar(long rlen)
void clear()
Definition: docfile.cpp:181
virtual size_t size() const =0
double psi(const double x)
void append_comment(const std::string &comment)
Definition: docfile.cpp:1005
Name of an image (std::string)

◆ generate_Spider_count()

void generate_Spider_count ( int  imax,
DocFile DF_out 
)

Generate a Spider "count" file. This function returns a DocFile with (1, 2, 3, ..., imax)

Definition at line 33 of file spider.cpp.

34 {
35  Matrix1D<double> aux(1);
36 
37  DF_out.clear();
38  DF_out.append_comment((std::string)"Count for Spider up to " + integerToString(imax));
39 
40  for (aux(0) = 1; aux(0) <= imax; aux(0)++)
41  DF_out.append_data_line(aux);
42 }
String integerToString(int I, int _width, char fill_with)
int append_data_line(int no_lines_to_append=1)
Definition: docfile.cpp:975
void clear()
Definition: docfile.cpp:181
void append_comment(const std::string &comment)
Definition: docfile.cpp:1005

◆ rename_for_Spider()

void rename_for_Spider ( MetaData SF_in,
MetaData SF_out,
const FileName fn_root,
const FileName out_ext 
)

Rename ACTIVE images in a selfile. The images are renamed with the fn_root given, consecutive numbers starting at 1, and the extension given. If no extension is given the same one as the input one is used. The correspondence between files is shown in stdout. A selFile is returned with the new set of images. The renaming is done by calls to cp in the Operating System, so there is no restriction on th einput names.

Definition at line 146 of file spider.cpp.

148 {
149  FileName fn_in, fn_out;
150  int counter = 1;
151  size_t id;
152 
153  for (size_t objId : SF_out.ids())
154  {
155  SF_in.getValue( MDL_IMAGE, fn_in, objId);
156  if (fn_in=="")
157  break;
158  fn_out = fn_root + integerToString(counter, 5);
159  if (out_ext == "")
160  fn_out = fn_out.addExtension(fn_in.getExtension());
161  else
162  fn_out = fn_out.addExtension(out_ext);
163  id = SF_out.addObject();
164  SF_out.setValue( MDL_IMAGE, fn_out, id);
165  SF_out.setValue( MDL_ENABLED, 1, id);
166 
167  std::cout << "Renaming " << fn_in << " as " << fn_out << std::endl;
168  std::string command = (std::string)"cp " + fn_in + " " + fn_out;
169  if (!system(command.c_str()))
170  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot copy files");
171 
172  counter++;
173  }
174 
175 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
virtual size_t addObject()=0
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName addExtension(const String &ext) const
String integerToString(int I, int _width, char fill_with)
virtual IdIteratorProxy< false > ids()
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
Is this image enabled? (int [-1 or 1])
String getExtension() const
bool setValue(const MDLabel label, const T &valueIn, size_t id)
Name of an image (std::string)

◆ translate_to_Spider_sel()

void translate_to_Spider_sel ( MetaData SF_in,
DocFile DF_out,
bool  new_style 
)

From a Xmipp selfile to Spider selfile. Comments are lost. A Spider Selfile is created in which the -1 of the Xmipp Selfiles are translated into 0.

Set new_style to produce the new style of Spider selfiles.

Definition at line 45 of file spider.cpp.

46 {
47  Matrix1D<double> aux(1);
48  //int selline = 1;
49 
50  DF_out.clear();
51  DF_out.append_comment((std::string)"Translation for Spider of " + SF_in.getFilename());
52  int i=1;
53  for (size_t objId : SF_in.ids())
54  {
55  bool store = true;
56  //if (!SF_in.Is_COMMENT())
57  {
58  int enabled;
59 
60  SF_in.getValue(MDL_ENABLED, enabled, objId);
61 
62  if ( enabled ==1)
63  {
64  if (!new_style)
65  aux(0) = 1;
66  //else aux(0) = ((FileName)SF_in.get_current_file()).get_number();
67  else
68  aux(0) = i++;
69  }
70  else
71  {
72  if (!new_style)
73  aux(0) = 0;
74  else
75  {
76  store = false;
77  i++;
78  }
79  }
80  if (store)
81  DF_out.append_data_line(aux);
82  }
83  }
84 
85 }
virtual IdIteratorProxy< false > ids()
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
#define i
Is this image enabled? (int [-1 or 1])
int append_data_line(int no_lines_to_append=1)
Definition: docfile.cpp:975
void clear()
Definition: docfile.cpp:181
void append_comment(const std::string &comment)
Definition: docfile.cpp:1005
virtual FileName getFilename() const