Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a2c4fcc
Added tclap library
kzscisoft Jun 12, 2020
325464a
Started working on command line arguments
kzscisoft Jun 12, 2020
6e0518d
Added additional source files
kzscisoft Jun 12, 2020
17eaf87
Re-ordered output
kzscisoft Jun 12, 2020
818a36a
Updated docstrings
kzscisoft Jun 12, 2020
fd2463d
Updated README
kzscisoft Jun 12, 2020
476f564
Updated CMake coverage command
kzscisoft Jun 12, 2020
19d5476
Manually set flags for coverage
kzscisoft Jun 12, 2020
f9954cd
Fixed duplicate line
kzscisoft Jun 15, 2020
dc4deff
Added TCLAP build to CMake as opposed to including files
kzscisoft Jun 16, 2020
7c585d5
Updated README to mention TCLAP
kzscisoft Jun 16, 2020
3cdf77e
Updated README to mention instructions if TCLAP remote not found
kzscisoft Jun 16, 2020
7f0ab2f
Delete extra file that could cause later confusion 'Makefile.am'
kzscisoft Jun 16, 2020
cbd5c28
Added missing option append line
kzscisoft Jun 16, 2020
fefe614
Removed model parameter from tests
kzscisoft Jun 16, 2020
df69642
Removed non-working getArg function and updated to struct style
kzscisoft Jun 16, 2020
07370e8
Updated Logging Output
kzscisoft Jun 16, 2020
20ab7f7
Removed TCLAP from Clang Tidy
kzscisoft Jun 16, 2020
c759a6c
Started working on Abstraction Layer
kzscisoft Jun 16, 2020
66b2b77
Added Additional File Addresses
kzscisoft Jun 16, 2020
c631853
Data now read from DataSource object
kzscisoft Jun 16, 2020
cd5622a
Fixed Output Directory
kzscisoft Jun 16, 2020
2a2a450
Corrected Abstraction Layer
kzscisoft Jun 17, 2020
1aabf98
Removed Cyclic Dependency
kzscisoft Jun 17, 2020
3aefc12
Removed unneeded headers
kzscisoft Jun 17, 2020
ce283ba
Added DocStrings
kzscisoft Jun 17, 2020
b87ccef
DocString update
kzscisoft Jun 17, 2020
f750225
Added skeletal framework for Remote method
kzscisoft Jun 17, 2020
a9efae7
Added Template 'Remote' libary
kzscisoft Jun 17, 2020
9760ac7
Changed Remote to RemoteSource
kzscisoft Jun 17, 2020
020b7cc
Removed unneeded duplicate function
kzscisoft Jun 17, 2020
f2f8a39
Cherry picked with dev
kzscisoft Jun 29, 2020
dd913d5
Made compatible with dev
kzscisoft Jun 29, 2020
37c3cec
Fixed unaddressed merge complaints
kzscisoft Jun 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)

set(PROJECT_NAME Covid19EERAModel)

project(${PROJECT_NAME} VERSION 0.0.0 LANGUAGES CXX)
project(${PROJECT_NAME} VERSION 0.3.2 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
Expand Down
6 changes: 5 additions & 1 deletion src/ArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ void ArgumentParser::logArguments(Utilities::logging_stream::Sptr log)
(*log) << "\t" << "Output Directory: " << _args.output_dir << std::endl;
}

void ArgumentParser::AppendOptions(ModelInputParameters& input_params)
void ArgumentParser::AppendOptions(DataSourcing::DataSource& data_source)
{
ModelInputParameters input_params = data_source.getInputParameters();

// Only set model structure to default of "original" if no option specified
// in parameters file
if(input_params.model_structure == ModelStructureId::UNKNOWN)
Expand All @@ -119,5 +121,7 @@ void ArgumentParser::AppendOptions(ModelInputParameters& input_params)
{
input_params.run_type = _args.mode;
}

data_source.setModelInputParameters(input_params);
}
};
5 changes: 3 additions & 2 deletions src/ArgumentParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Utilities.h"
#include "ModelTypes.h"
#include "DataSourcing.h"

#ifndef VERSION
#error Macro VERSION must be defined!
Expand Down Expand Up @@ -56,9 +57,9 @@ class ArgumentParser
* Specifies options for structure, mode and input location
* these overwrite values specified within a parameter file.
*
* @param input_params model input parameter object to update
* @param data_source data source for which to append options
*/
void AppendOptions(ModelInputParameters& input_params);
void AppendOptions(DataSourcing::DataSource& data_source);

bool runLocal() const {return _args.isLocal;}

Expand Down
49 changes: 49 additions & 0 deletions src/DataSourcing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "DataSourcing.h"

namespace EERAModel
{
namespace DataSourcing
{
void DataSource::Setup()
{
// Read prior particle parameters if run type is "Prediction"
if(_input_params.run_type == ModelModeId::PREDICTION)
{
_input_params.posterior_param_list = _posterior_params;
}
}

void LocalSource::_extract_data()
{
setModelInputParameters(IO::ReadParametersFromFile(_data_files, getLogger()));

// Read prior particle parameters if run type is "Prediction"
if(getInputParameters().run_type == ModelModeId::PREDICTION)
{
setPosteriors(IO::ReadPosteriorParametersFromFile(_data_files, getInputParameters().posterior_parameter_select));
}

setInputObservations(IO::ReadObservationsFromFiles(_data_files, getLogger()));
}

void RemoteSource::_extract_data()
{

setModelInputParameters(API::ReadParametersFromAPI(_api_info, getLogger()));

if(getInputParameters().run_type == ModelModeId::PREDICTION)
{
setPosteriors(API::ReadPosteriorParametersFromAPI(_api_info, getInputParameters().posterior_parameter_select));
}

setInputObservations(API::ReadObservationsFromAPI(_api_info, getLogger()));

}

const DataSource getSource(SourceID source_id, Utilities::logging_stream::Sptr log, std::string data_location)
{
return (source_id == SourceID::LOCAL) ? DataSource(LocalSource(data_location, log)) : DataSource(RemoteSource(data_location, log));
}

};
};
191 changes: 191 additions & 0 deletions src/DataSourcing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#pragma once

#include <string>

#include "ModelTypes.h"
#include "LocalFileStructure.h"
#include "IO.h"
#include "Remote.h"

namespace EERAModel
{
/**
* @brief Namespace containing data sourcing objects
*
* This namespace contains definitions for data sources which
* define the location of the various data files.
*/
namespace DataSourcing
{
/**
* @brief Core data source class
*
* Class defining locations of the various data inputs
*/
class DataSource
{
private:
InputObservations _input_obs;
ModelInputParameters _input_params;
std::vector<double> _posterior_params;
Utilities::logging_stream::Sptr _log;
public:
/**
* @brief Constructor for Data Source object
*
* @param log shared pointer for logger
*/
DataSource(Utilities::logging_stream::Sptr log) : _log(log) {}

/**
* @brief Fetch input observations
*
* @return current read input observations
*/
InputObservations getInputObservations() const {return _input_obs;}

/**
* @brief Fetch input parameters
*
* @return current read input parameters
*/
ModelInputParameters getInputParameters() const {return _input_params;}

/**
* @brief Fetch prior parameters
*
* @return current prior parameters
*/
std::vector<double> getPriorParameters() const {return _posterior_params;}

/**
* @brief Fetch current logger
*
* @return shared pointer to current logger
*/
Utilities::logging_stream::Sptr getLogger() const {return _log;}

/**
* @brief Set the current input observations
*/
void setInputObservations(const InputObservations& input_obs) {_input_obs = input_obs;}

/**
* @brief Set the current input parameters
*/
void setModelInputParameters(const ModelInputParameters& model_input) {_input_params = model_input;}

/**
* @brief Set the current prior parameters
*/
void setPosteriors(const std::vector<double>& posteriors) {_posterior_params = posteriors;}

/**
* @brief Run global setup
*
* Runs setup/initialisation that is relevant to all model runs independent
* of the data source location. Must be called at appropriate time within each subclass.
*/
void Setup();
};

/**
* @brief Local data source sub-class
*
* This subclass of DataSource handles the procedure for processing
* and importing data locally.
*/
class LocalSource : public DataSource
{
private:
const DataFiles _data_files;
/**
* @brief Extracts the data using the IO library
*
* Extract the data from local files using the EERAModel::IO library
*/
void _extract_data();
public:
/**
* @brief Constructor for Local Data Source object
*
* @param root_dir the root directory of the data files
* @param log shared pointer for logger
*/
LocalSource(const std::string root_dir, Utilities::logging_stream::Sptr log) :
DataSource(log),
_data_files({
root_dir+"/parameters.ini",
root_dir+"/scot_data.csv",
root_dir+"/scot_deaths.csv",
root_dir+"/scot_age.csv",
{root_dir+"/waifw_norm.csv",
root_dir+"/waifw_home.csv",
root_dir+"/waifw_sdist.csv"},
root_dir+"/cfr_byage.csv",
root_dir+"/scot_frail.csv",
root_dir+"/example_posterior_parameter_sets.txt"})
{
_extract_data();
(*log) << "[Parameters File]:\n " << _data_files.parameters << std::endl;
Setup();
}

/**
* @brief Fetch local data files
*
* @return struct containing local data file locations
*/
DataFiles getDataFiles() const {return _data_files;}
};

/**
* @brief Remote data source sub-class
*
* This subclass of DataSource handles the procedure for processing
* and importing data from the API.
*/
class RemoteSource : public DataSource
{
private:
/**
* @brief Extracts the data from the API
*
* Extract the data from the API
*/
void _extract_data();
const std::string _api_info = "<dummy-info>";
public:
RemoteSource(const std::string APIInfo, Utilities::logging_stream::Sptr log) :
DataSource(log),
_api_info(APIInfo)
{
_extract_data();
Setup();
}
};

/**
* @brief Selection of local or remote file source
*/
enum class SourceID
{
REMOTE, /*!< Files are to be read through an API. */
LOCAL /*!< Files are to be read from local directory. */
};

/**
* @brief Return the relevant source object
*
* Given the specified options return the relevant data source object
* for performing the model run.
*
* @param source_id whether the data is remote or local
* @param data_location if the data is local, the data root directory else the API info
*
* @return an appropriate data source object for the options specified.
*/
const DataSource getSource(SourceID source_id, Utilities::logging_stream::Sptr log, std::string local_data_location="");

};
};
Loading