#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::TestUtil::to_emobject(). 00086 {
00087 return data[i].x;
00088 }
|
|
|
Definition at line 200 of file xydata.cpp. References data. 00201 {
00202 vector<float> xlist;
00203 vector<Pair>::const_iterator cit;
00204 for(cit=data.begin(); cit!=data.end(); ++cit) {
00205 xlist.push_back( (*cit).x);
00206 }
00207
00208 return xlist;
00209 }
|
|
|
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 if (data.size()==0 || mean_x_spacing==0) return 0.0;
00167
00168 int nx = (int) data.size();
00169 // Do the range checking up front before we get into trouble
00170 if (x<data[0].x) return outzero?0.0f:data[0].y;
00171 if (x>data[nx-1].x) return outzero?0.0f:data[nx-1].y;
00172
00173 int s = (int) floor((x - data[0].x) / mean_x_spacing);
00174
00175 // These deal with possibly nonuniform x values. A btree would be better, but this is simple
00176 while (s>0 && data[s].x > x) s--;
00177 while (s<(nx-1) && data[s + 1].x < x ) s++;
00178
00179 float f = (x - data[s].x) / (data[s + 1].x - data[s].x);
00180 float y = data[s].y * (1 - f) + data[s + 1].y * f;
00181 return y;
00182 }
|
|
|
Definition at line 211 of file xydata.cpp. References data. 00212 {
00213 vector<float> ylist;
00214 vector<Pair>::const_iterator cit;
00215 for(cit=data.begin(); cit!=data.end(); ++cit) {
00216 ylist.push_back( (*cit).y);
00217 }
00218
00219 return ylist;
00220 }
|
|
|
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 195 of file xydata.cpp. References data. 00196 {
00197 data.resize(n, Pair(0.0f, 0.0f));
00198 }
|
|
||||||||||||
|
Definition at line 90 of file xydata.h. References data. Referenced by EMAN::MatchSFProcessor::create_radial_func().
|
|
||||||||||||
|
Definition at line 184 of file xydata.cpp. References data, and InvalidParameterException. 00185 {
00186 if(xlist.size() != ylist.size()) {
00187 throw InvalidParameterException("xlist and ylist size does not match!");
00188 }
00189
00190 for(unsigned int i=0; i<xlist.size(); ++i) {
00191 data.push_back(Pair(xlist[i], ylist[i]));
00192 }
00193 }
|
|
||||||||||||
|
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. 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(). |
1.3.9.1