Go to the documentation of this file.
23 #ifndef O2SCL_HIST_2D_H
24 #define O2SCL_HIST_2D_H
31 #include <boost/numeric/ublas/vector.hpp>
32 #include <boost/numeric/ublas/matrix.hpp>
34 #include <o2scl/convert_units.h>
35 #include <o2scl/interp.h>
36 #include <o2scl/uniform_grid.h>
37 #include <o2scl/table3d.h>
48 void hdf_output(hdf_file &hf,
o2scl::hist_2d &t, std::string name);
51 #ifndef DOXYGEN_NO_O2NS
149 void allocate(
size_t nx,
size_t ny);
169 template<
class vec_t,
class vec2_t>
hist_2d
170 (
size_t nv,
const vec_t &v,
const vec2_t &v2,
size_t n_bins_x,
180 double min_x, max_x, min_y, max_y;
187 for(
size_t i=0;i<nv;i++) {
196 template<
class vec_t,
class vec2_t,
class vec3_t>
hist_2d
197 (
size_t nv,
const vec_t &v,
const vec2_t &v2,
const vec3_t &v3,
198 size_t n_bins_x,
size_t n_bins_y) {
207 double min_x, max_x, min_y, max_y;
214 for(
size_t i=0;i<nv;i++) {
222 template<
class vec_t,
class vec2_t>
hist_2d
223 (
const vec_t &v,
const vec2_t &v2,
size_t n_bins_x,
226 hist_2d(v.size(),v,v2,n_bins_x,n_bins_y);
234 template<
class vec_t,
class vec2_t,
class vec3_t>
hist_2d
235 (
const vec_t &v,
const vec2_t &v2,
const vec3_t &v3,
size_t n_bins_x,
238 hist_2d(v.size(),v,v2,v3,n_bins_x,n_bins_y);
246 size_t n_bins_x,
size_t n_bins_y) {
256 std::string colz,
size_t n_bins_x,
size_t n_bins_y) {
293 size_t ny, vec_t &vy) {
296 O2SCL_ERR2(
"Requested binning change in non-empty ",
297 "histogram in hist_2d::set_bin_edges().",
302 for(
size_t i=0;i<nx;i++)
xa[i]=vx[i];
303 for(
size_t i=0;i<ny;i++)
ya[i]=vy[i];
314 void update_i(
size_t i,
size_t j,
double val=1.0) {
320 void update(
double x,
double y,
double val=1.0) {
328 const double &
get_wgt_i(
size_t i,
size_t j)
const;
331 const double &
get_wgt(
double x,
double y)
const {
348 void set_wgt_i(
size_t i,
size_t j,
double val);
351 void set_wgt(
double x,
double y,
double val) {
418 static const size_t rmode_avg=0;
419 static const size_t rmode_user=1;
420 static const size_t rmode_low=2;
421 static const size_t rmode_high=3;
422 static const size_t rmode_gmean=4;
428 template<
class vec_t>
void set_reps(
size_t nx, vec_t &vx,
429 size_t ny, vec_t &vy) {
431 std::string s=
"Expected vectors of size "+
itos(
hsize_x)+
433 ", "+
itos(ny)+
" in hist_2d::set_reps().";
442 for(
size_t i=0;i<nx;i++)
user_xrep[i]=vx[i];
443 for(
size_t i=0;i<ny;i++)
user_yrep[i]=vy[i];
448 template<
class vec_t>
void set_x_reps(
size_t nx, vec_t &vx) {
450 std::string s=
"Expected vector of size "+
itos(
hsize_x)+
451 " and got a vector of size "+
itos(nx)+
" in hist_2d::set_reps().";
457 for(
size_t i=0;i<nx;i++)
user_xrep[i]=vx[i];
462 template<
class vec_t>
void set_y_reps(
size_t ny, vec_t &vy) {
464 std::string s=
"Expected vector of size "+
itos(
hsize_y)+
465 " and got a vector of size "+
itos(ny)+
" in hist_2d::set_reps().";
471 for(
size_t i=0;i<ny;i++)
user_yrep[i]=vy[i];
521 O2SCL_ERR(
"Not user mode in hist::get_user_reps_x().",
540 O2SCL_ERR(
"Not user mode in hist::get_user_reps_y().",
580 std::string yreps_name, std::string weights);
589 #ifndef DOXYGEN_NO_O2NS
void copy_to_table3d(table3d &t, std::string xreps_name, std::string yreps_name, std::string weights)
Create a table3d object based on the histogram data.
size_t get_nlines() const
Return the number of lines.
void from_table(o2scl::table<> &t, std::string colx, std::string coly, size_t n_bins_x, size_t n_bins_y)
Create a 2D histogram object from a table.
double & get_wgt(double x, double y)
Return contents of bin for x.
size_t xrmode
Rep mode for x.
const ubvector & get_y_bins() const
Get a reference to the full vector of bin specifications.
double integ_wgts()
Return the integral under the histogram.
@ exc_efailed
generic failure
double & get_x_high_i(size_t i)
Get the upper edge of bin of index i.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
const ubmatrix & get_wgts() const
Get a const reference to the full matrix of data.
void set_y_reps(size_t ny, vec_t &vy)
Set the representative y-values for each bin.
double sum_wgts()
Return the sum of all of the weights.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
void set_x_reps(size_t nx, vec_t &vx)
Set the representative x-values for each bin.
void set_reps_auto()
An internal function to automatically set xrep and yrep.
void is_valid() const
Internal consistency check.
ubvector xa
Bin locations (Nx+1)
size_t get_x_rep_mode() const
Get mode used to compute bin reps.
void vector_minmax_value(size_t n, vec_t &data, data_t &min, data_t &max)
Compute the minimum and maximum of the first n elements of a vector.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
void set_wgt_i(size_t i, size_t j, double val)
Set contents of bin at (i,j) to value val.
const ubvector & get_user_reps_y() const
Get a reference to the user-specified reps for y coordinates.
const double & get_wgt_i(size_t i, size_t j) const
Return contents of bin at (i,j)
ubvector yrep
"Central" values for y-axis (N)
void set_bin_edges(uniform_grid< double > gx, uniform_grid< double > gy)
Set the bins from two uniform_grid objects.
hist_2d & operator=(const hist_2d &h)
Copy from operator=()
void clear()
Clear the entire histogram.
void clear_wgts()
Clear the data, but leave the bins as is.
ubvector ya
Bin locations (Ny+1)
@ exc_einval
invalid argument supplied by user
void update(double x, double y, double val=1.0)
Increment bin for x by value val.
size_t size_y() const
Return the histogram size of the y coordinate.
const double & get_wgt(double x, double y) const
Return contents of bin for x.
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
void get_bin_indices(double x, double y, size_t &i, size_t &j) const
Get the index of the bin which holds x and the bin which holds y.
size_t yrmode
Rep mode for y.
void set_rep_mode(size_t x_mode, size_t y_mode)
Set mode used to compute bin reps.
void update_i(size_t i, size_t j, double val=1.0)
Increment bin at (i,j) by value val.
bool extend_lhs
If true, allow abcissa smaller than smallest bin limit to correspond to the lowest bin (default false...
ubmatrix wgt
Values (Nx,Ny)
const ubvector & get_x_bins() const
Get a reference to the full vector of bin specifications.
ubmatrix & get_wgts()
Get a reference to the full matrix of data.
void set_bin_edges(size_t nx, vec_t &vx, size_t ny, vec_t &vy)
Set the bins from a vector.
double & get_x_low_i(size_t i)
Get the lower edge of bin of index i.
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
std::string itos(int x)
Convert an integer to a string.
size_t get_y_rep_mode() const
Get mode used to compute bin reps.
const ubvector & get_user_reps_x() const
Get a reference to the user-specified reps for x coordinates.
size_t get_y_bin_index(double y) const
Get the indey of the bin which holds y.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
void from_table(o2scl::table<> &t, std::string colx, std::string coly, std::string colz, size_t n_bins_x, size_t n_bins_y)
Create a 2D histogram object from a table, obtaining weights from the third column.
double & get_y_high_i(size_t j)
Get the upper edge of bin of index j.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
double get_y_rep_i(size_t j)
Return the rep of bin of index j.
double & get_y_low_i(size_t j)
Get the lower edge of bin of index j.
ubvector user_yrep
User-defined central values for y-axis (N)
size_t size_x() const
Return the histogram size of the x coordinate.
double get_x_rep_i(size_t i)
Return the rep of bin of index i.
size_t hsize_x
Number of x-bins.
void set_wgt(double x, double y, double val)
Set contents of bin for x to value val.
void allocate(size_t nx, size_t ny)
Allocate for a histogram of size nx, ny.
size_t get_x_bin_index(double x) const
Get the index of the bin which holds x.
bool extend_rhs
If true, allow abcissa larger than largest bin limit to correspond to the highest bin (default false)...
size_t hsize_y
Number of y-bins.
void set_reps(size_t nx, vec_t &vx, size_t ny, vec_t &vy)
Set the representative x-values for each bin.
ubvector xrep
"Central" values for x-axis (N)
A data structure containing one or more slices of two-dimensional data points defined on a grid.
ubvector user_xrep
User-defined central values for x-axis (N)
A two-dimensional histogram class.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).