#include <xydata.h>
Public Member Functions | |
XYData () | |
virtual | ~XYData () |
int | read_file (const string &filename) |
int | write_file (const string &filename) const |
float | calc_correlation (XYData *xy, float minx, float maxx) const |
void | update () |
float | get_yatx (float x, bool outzero=true) |
float | get_x (size_t i) const |
void | set_x (size_t i, float x) |
float | get_y (size_t i) const |
void | set_y (size_t i, float y) |
vector< float > | get_xlist () const |
vector< float > | get_ylist () const |
void | set_xy_list (const vector< float > &xlist, const vector< float > &ylist) |
size_t | get_size () const |
void | set_size (size_t n) |
float | get_miny () |
float | get_maxy () |
bool | is_validx (float x) const |
Private Attributes | |
vector< Pair > | data |
float | ymin |
float | ymax |
float | mean_x_spacing |
Definition at line 49 of file xydata.h.
|
Definition at line 52 of file xydata.cpp. 00053 : ymin(FLT_MAX), ymax(-FLT_MAX), mean_x_spacing(1.0) 00054 { 00055 }
|
|
Definition at line 70 of file xydata.h. 00071 { 00072 }
|
|
Definition at line 130 of file xydata.cpp. References data, get_yatx(), is_validx(), LOGERR, sqrt(), update(), and x. 00131 { 00132 size_t n = data.size(); 00133 float x0 = data[0].x; 00134 float xn = data[n - 1].x; 00135 00136 if (maxx <= minx || minx >= xn || maxx <= x0) { 00137 LOGERR("incorrect minx, maxx=%f,%f for this XYData range [%f,%f]", 00138 minx, maxx, x0, xn); 00139 return 0; 00140 } 00141 00142 float scc = 0; 00143 float norm1 = 0; 00144 float norm2 = 0; 00145 00146 xy->update(); 00147 for (size_t i = 0; i < n; i++) { 00148 float x = data[i].x; 00149 if (x >= minx && x <= maxx && xy->is_validx(x)) { 00150 float selfy = data[i].y; 00151 float xyy = xy->get_yatx(x); 00152 00153 scc += selfy * xyy; 00154 norm1 += selfy * selfy; 00155 norm2 += xyy * xyy; 00156 } 00157 } 00158 00159 float result = scc / sqrt(norm1 * norm2); 00160 return result; 00161 }
|
|
Definition at line 126 of file xydata.h. 00127 { 00128 // update(); 00129 return ymax; 00130 }
|
|
Definition at line 120 of file xydata.h. 00121 { 00122 // update(); 00123 return ymin; 00124 }
|
|
Definition at line 113 of file xydata.h. References data. Referenced by EMAN::SNRProcessor::process_inplace(), and EMAN::TestUtil::to_emobject(). 00114 { 00115 return data.size(); 00116 }
|
|
Definition at line 85 of file xydata.h. References data. Referenced by EMAN::MatchSFProcessor::create_radial_func(), and EMAN::TestUtil::to_emobject(). 00086 { 00087 return data[i].x; 00088 }
|
|
Definition at line 213 of file xydata.cpp. References data. 00214 { 00215 vector<float> xlist; 00216 vector<Pair>::const_iterator cit; 00217 for(cit=data.begin(); cit!=data.end(); ++cit) { 00218 xlist.push_back( (*cit).x); 00219 } 00220 00221 return xlist; 00222 }
|
|
Definition at line 96 of file xydata.h. References data. Referenced by EMAN::SNRProcessor::process_inplace(), and EMAN::TestUtil::to_emobject(). 00097 { 00098 return data[i].y; 00099 }
|
|
Definition at line 164 of file xydata.cpp. References data, mean_x_spacing, nx, x, and y. Referenced by calc_correlation(), EMAN::EMAN2Ctf::compute_1d(), EMAN::EMAN1Ctf::compute_1d(), EMAN::EMAN2Ctf::compute_2d_complex(), EMAN::EMAN1Ctf::compute_2d_complex(), EMAN::SetSFProcessor::create_radial_func(), and EMAN::MatchSFProcessor::create_radial_func(). 00165 { 00166 // You MUST be kidding. Do you know how expensive update() is !?!? 00167 // the correct answer is to call update after you change the data, just like with EMData objects. --steve 00168 // update(); //update to set the mean_x_spacing value 00169 00170 if (data.size()==0 || mean_x_spacing==0) return 0.0; 00171 00172 int s = (int) floor((x - data[0].x) / mean_x_spacing); 00173 int nx = (int) data.size(); 00174 00175 if (data[s].x > x) { 00176 while (data[s].x > x && s >= 0) { 00177 s--; 00178 } 00179 } 00180 else if (data[s + 1].x < x) { 00181 while (data[s + 1].x < x && s < (nx - 1)) { 00182 s++; 00183 } 00184 } 00185 00186 if (s >= nx || s < 0) { 00187 if (outzero) return 0.0; // if outzero is set, any x point beyond the edges of the data will be 0 00188 if (s>=nx) return data[nx-1].y; // otherwise return the edge value 00189 return data[0].y; 00190 } 00191 00192 float f = (x - data[s].x) / (data[s + 1].x - data[s].x); 00193 float y = data[s].y * (1 - f) + data[s + 1].y * f; 00194 return y; 00195 }
|
|
Definition at line 224 of file xydata.cpp. References data. 00225 { 00226 vector<float> ylist; 00227 vector<Pair>::const_iterator cit; 00228 for(cit=data.begin(); cit!=data.end(); ++cit) { 00229 ylist.push_back( (*cit).y); 00230 } 00231 00232 return ylist; 00233 }
|
|
Definition at line 132 of file xydata.h. Referenced by calc_correlation(). 00133 { 00134 if (x < data[0].x || x > data[data.size() - 1].x) 00135 { 00136 return false; 00137 } 00138 return true; 00139 }
|
|
Definition at line 79 of file xydata.cpp. References data, in, LOGERR, update(), x, and y. Referenced by EMAN::SNRProcessor::process_inplace(). 00080 { 00081 FILE *in = fopen(filename.c_str(), "rb"); 00082 if (!in) { 00083 LOGERR("cannot open xydata file '%s'", filename.c_str()); 00084 return 1; 00085 } 00086 00087 char buf[MAXPATHLEN]; 00088 char tmp_str[MAXPATHLEN]; 00089 00090 while (fgets(buf, MAXPATHLEN, in)) { 00091 if (buf[0] != '#') { 00092 float x = 0; 00093 float y = 0; 00094 00095 if (sscanf(buf, " %f%[^.0-9-]%f", &x, tmp_str, &y) != 3) { 00096 break; 00097 } 00098 data.push_back(Pair(x, y)); 00099 } 00100 } 00101 00102 fclose(in); 00103 in = 0; 00104 00105 update(); 00106 00107 return 0; 00108 }
|
|
Definition at line 208 of file xydata.cpp. References data. 00209 { 00210 data.resize(n, Pair(0.0f, 0.0f)); 00211 }
|
|
Definition at line 90 of file xydata.h. References data. Referenced by EMAN::MatchSFProcessor::create_radial_func().
|
|
Definition at line 197 of file xydata.cpp. References data, and InvalidParameterException. 00198 { 00199 if(xlist.size() != ylist.size()) { 00200 throw InvalidParameterException("xlist and ylist size does not match!"); 00201 } 00202 00203 for(unsigned int i=0; i<xlist.size(); ++i) { 00204 data.push_back(Pair(xlist[i], ylist[i])); 00205 } 00206 }
|
|
Definition at line 101 of file xydata.h. References data. Referenced by EMAN::MatchSFProcessor::create_radial_func(), and EMAN::SNRProcessor::process_inplace().
|
|
Definition at line 57 of file xydata.cpp. References data, mean_x_spacing, ymax, and ymin. Referenced by calc_correlation(), EMAN::SNRProcessor::process_inplace(), and read_file(). 00058 { 00059 std::sort(data.begin(), data.end()); 00060 00061 ymin = FLT_MAX; 00062 ymax = -FLT_MAX; 00063 00064 typedef vector < Pair >::const_iterator Ptype; 00065 for (Ptype p = data.begin(); p != data.end(); p++) { 00066 if (p->y > ymax) { 00067 ymax = p->y; 00068 } 00069 if (p->y < ymin) { 00070 ymin = p->y; 00071 } 00072 } 00073 00074 size_t n = data.size(); 00075 mean_x_spacing = (data[n - 1].x - data[0].x) / (float) n; 00076 }
|
|
Definition at line 110 of file xydata.cpp. Referenced by EMAN::MatchSFProcessor::create_radial_func(). 00111 { 00112 FILE *out = fopen(filename.c_str(), "wb"); 00113 if (!out) { 00114 LOGERR("cannot open xydata file '%s' to write", filename.c_str()); 00115 return 1; 00116 } 00117 00118 typedef vector < Pair >::const_iterator Ptype; 00119 for (Ptype p = data.begin(); p != data.end(); p++) { 00120 fprintf(out, "%1.6g\t%1.6g\n", p->x, p->y); 00121 } 00122 00123 fclose(out); 00124 out = 0; 00125 00126 return 0; 00127 }
|
|
Definition at line 142 of file xydata.h. Referenced by calc_correlation(), get_xlist(), get_yatx(), get_ylist(), read_file(), set_size(), set_xy_list(), update(), and write_file(). |
|
Definition at line 145 of file xydata.h. Referenced by get_yatx(), and update(). |
|
Definition at line 144 of file xydata.h. Referenced by update(). |
|
Definition at line 143 of file xydata.h. Referenced by update(). |