Inviwo 0.9.12-pre
Inviwo documentation
|
A reader for comma separated value (CSV) files with customizable delimiters and filters. The default delimiter is ',' and headers are included. Floating point values are stored as float32 unless double precision is enabled. More...
#include <csvreader.h>
Public Types | |
enum class | EmptyField { Throw , EmptyOrZero , NanOrZero } |
Public Member Functions | |
CSVReader (std::string_view delimiters=defaultDelimiters, bool hasHeader=defaultFirstRowHeader, bool doublePrecision=defaultDoublePrecision) | |
CSVReader (const CSVReader &)=default | |
CSVReader (CSVReader &&) noexcept=default | |
CSVReader & | operator= (const CSVReader &)=default |
CSVReader & | operator= (CSVReader &&) noexcept=default |
virtual CSVReader * | clone () const override |
CSVReader & | setDelimiters (const std::string &delim) |
const std::string & | getDelimiters () const |
CSVReader & | setStripQuotes (bool stripQuotes) |
bool | getStripQuotes () const |
CSVReader & | setFirstRowHeader (bool hasHeader) |
bool | hasFirstRowHeader () const |
CSVReader & | setFirstColIndices (bool hasIndices) |
bool | hasFirstColIndices () const |
CSVReader & | setUnitsInHeaders (bool unitInHeaders) |
bool | hasUnitsInHeaders () const |
CSVReader & | setUnitRegexp (std::string_view regexp) |
const std::string & | getUnitRegexp () const |
CSVReader & | setEnableDoublePrecision (bool useDoublePrecision) |
bool | hasDoublePrecision () const |
CSVReader & | setNumberOfExampleRows (size_t rows) |
size_t | getNumberOfExamplesRows () const |
CSVReader & | setLocale (std::string_view loc) |
const std::string & | getLocale () const |
CSVReader & | setFilters (const csvfilters::Filters &filters) |
const csvfilters::Filters & | getFilters () const |
CSVReader & | setHandleEmptyFields (EmptyField emptyField) |
EmptyField | getHandleEmptyFields () const |
virtual std::shared_ptr< DataFrame > | readData (const std::filesystem::path &fileName) override |
std::shared_ptr< DataFrame > | readData (std::istream &stream) const |
virtual bool | setOption (std::string_view key, std::any value) override |
virtual std::any | getOption (std::string_view key) override |
Public Member Functions inherited from inviwo::DataReaderType< DataFrame > | |
DataReaderType (const DataReaderType &rhs)=default | |
DataReaderType (DataReaderType &&rhs) noexcept=default | |
DataReaderType & | operator= (const DataReaderType &that)=default |
DataReaderType & | operator= (DataReaderType &&that) noexcept=default |
virtual std::shared_ptr< DataFrame > | readData (const std::filesystem::path &filePath, MetaDataOwner *) |
Public Member Functions inherited from inviwo::DataReader | |
DataReader (const DataReader &rhs)=default | |
DataReader (DataReader &&rhs) noexcept=default | |
DataReader & | operator= (const DataReader &that)=default |
DataReader & | operator= (DataReader &&that) noexcept=default |
const std::vector< FileExtension > & | getExtensions () const |
void | addExtension (FileExtension ext) |
template<typename T > | |
bool | readsType () const |
Static Public Attributes | |
static constexpr std::string_view | defaultDelimiters = "," |
static constexpr bool | defaultStripQuotes = true |
static constexpr bool | defaultFirstRowHeader = true |
static constexpr bool | defaultFirstColIndices = false |
static constexpr bool | defaultUnitInHeaders = true |
static constexpr std::string_view | defaultUnitRegexp = R"((.*)\[(.*)\])" |
static constexpr bool | defaultDoublePrecision = false |
static constexpr size_t | defaultNumberOfExampleRows = 50 |
static constexpr std::string_view | defaultLocale = "C" |
static constexpr EmptyField | defaultEmptyField = EmptyField::NanOrZero |
Additional Inherited Members | |
Protected Member Functions inherited from inviwo::DataReaderType< DataFrame > | |
virtual bool | canRead (const std::type_index &index) const override |
Protected Member Functions inherited from inviwo::DataReader | |
void | checkExists (const std::filesystem::path &path) const |
std::ifstream | open (const std::filesystem::path &path, std::ios_base::openmode mode=std::ios_base::in) const |
Protected Attributes inherited from inviwo::DataReader | |
std::vector< FileExtension > | extensions_ |
A reader for comma separated value (CSV) files with customizable delimiters and filters. The default delimiter is ',' and headers are included. Floating point values are stored as float32 unless double precision is enabled.
|
strong |
How to handle missing / empty data
Enumerator | |
---|---|
Throw | Throw a DataReaderException. |
EmptyOrZero | "" for categorical and 0 for numerical values |
NanOrZero | "" for categorical, NaN for floating point, and 0 for integer values |
|
overridevirtual |
Implements inviwo::DataReaderType< DataFrame >.
|
overridevirtual |
Get any of the settings supported by the reader, supported keys:
Reimplemented from inviwo::DataReader.
|
overridevirtual |
read a CSV file from a file
fileName | name of the input CSV file |
FileException | if the file cannot be accessed |
DataReaderException | if the file contains no data, the first row should hold column headers, but they cannot be found, or if there are unmatched quotes at the end of the file |
Implements inviwo::DataReaderType< DataFrame >.
std::shared_ptr< DataFrame > inviwo::CSVReader::readData | ( | std::istream & | stream | ) | const |
read a CSV file from a input stream, e.g. a std::ifstream. In case file streams are used, the file must have be opened prior calling this function.
stream | input stream with the CSV data |
DataReaderException | if the given stream is in a bad state, the stream contains no data, the first row should hold column headers, but they cannot be found, or if there are unmatched quotes at the end of the stream |
CSVReader & inviwo::CSVReader::setDelimiters | ( | const std::string & | delim | ) |
CSVReader & inviwo::CSVReader::setEnableDoublePrecision | ( | bool | useDoublePrecision | ) |
Sets the precision for columns containing floating point values. If useDoublePrecision
is true, values are stored as double (64 bits), otherwise float (32 bits) is used.
CSVReader & inviwo::CSVReader::setFilters | ( | const csvfilters::Filters & | filters | ) |
Sets row and column filters.
CSVReader & inviwo::CSVReader::setFirstColIndices | ( | bool | hasIndices | ) |
CSVReader & inviwo::CSVReader::setFirstRowHeader | ( | bool | hasHeader | ) |
CSVReader & inviwo::CSVReader::setHandleEmptyFields | ( | EmptyField | emptyField | ) |
CSVReader & inviwo::CSVReader::setLocale | ( | std::string_view | loc | ) |
CSVReader & inviwo::CSVReader::setNumberOfExampleRows | ( | size_t | rows | ) |
|
overridevirtual |
Set any of the settings supported by the reader, supported keys:
Reimplemented from inviwo::DataReader.
CSVReader & inviwo::CSVReader::setStripQuotes | ( | bool | stripQuotes | ) |
CSVReader & inviwo::CSVReader::setUnitRegexp | ( | std::string_view | regexp | ) |
CSVReader & inviwo::CSVReader::setUnitsInHeaders | ( | bool | unitInHeaders | ) |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |