Skip to content

Commit

Permalink
Parameters files refactoring and code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalhorton committed Jul 19, 2017
1 parent 251a6fa commit 16ebc6f
Show file tree
Hide file tree
Showing 140 changed files with 1,013 additions and 959 deletions.
2 changes: 1 addition & 1 deletion src/app_forecaster/core/AtmoswingAppForecaster.cpp
Expand Up @@ -295,7 +295,7 @@ bool AtmoswingAppForecaster::OnCmdLineParsed(wxCmdLineParser &parser)
wxString numberOfDaysStr = wxEmptyString;
if (parser.Found("forecast-past", &numberOfDaysStr)) {
long numberOfDays;
if(!numberOfDaysStr.ToLong(&numberOfDays)) {
if (!numberOfDaysStr.ToLong(&numberOfDays)) {
wxPrintf(_("The value provided for 'forecast-past' could not be interpreted."));
return false;
}
Expand Down
12 changes: 4 additions & 8 deletions src/app_forecaster/core/asMethodForecasting.cpp
Expand Up @@ -954,8 +954,7 @@ bool asMethodForecasting::GetAnalogsDates(asResultsForecast &results, asParamete
}

// Instanciate an archive predictor object
asPredictorArch *predictorArchive = new asPredictorArch(
*m_storagePredictorsArchivePreprocess[0]);
asPredictorArch *predictorArchive = new asPredictorArch(*m_storagePredictorsArchivePreprocess[0]);
if (!predictorArchive) {
return false;
}
Expand All @@ -968,8 +967,7 @@ bool asMethodForecasting::GetAnalogsDates(asResultsForecast &results, asParamete
}

// Instanciate an realtime predictor object
asPredictorOper *predictorRealtime = new asPredictorOper(
*m_storagePredictorsRealtimePreprocess[0]);
asPredictorOper *predictorRealtime = new asPredictorOper(*m_storagePredictorsRealtimePreprocess[0]);
if (!predictorRealtime) {
wxDELETE(predictorArchive);
return false;
Expand Down Expand Up @@ -1439,8 +1437,7 @@ bool asMethodForecasting::GetAnalogsSubDates(asResultsForecast &results, asParam
}

// Instanciate an archive predictor object
asPredictorArch *predictorArchive = new asPredictorArch(
*m_storagePredictorsArchivePreprocess[0]);
asPredictorArch *predictorArchive = new asPredictorArch(*m_storagePredictorsArchivePreprocess[0]);
if (!predictorArchive) {
return false;
}
Expand All @@ -1453,8 +1450,7 @@ bool asMethodForecasting::GetAnalogsSubDates(asResultsForecast &results, asParam
}

// Instanciate an realtime predictor object
asPredictorOper *predictorRealtime = new asPredictorOper(
*m_storagePredictorsRealtimePreprocess[0]);
asPredictorOper *predictorRealtime = new asPredictorOper(*m_storagePredictorsRealtimePreprocess[0]);
if (!predictorRealtime) {
wxDELETE(predictorArchive);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/app_forecaster/core/asMethodForecasting.h
Expand Up @@ -76,8 +76,8 @@ class asMethodForecasting

bool GetAnalogsDates(asResultsForecast &results, asParametersForecast &params, int iStep);

bool GetAnalogsSubDates(asResultsForecast &results, asParametersForecast &params,
asResultsForecast &resultsPrev, int iStep);
bool GetAnalogsSubDates(asResultsForecast &results, asParametersForecast &params, asResultsForecast &resultsPrev,
int iStep);

bool GetAnalogsValues(asResultsForecast &results, asParametersForecast &params, int iStep);

Expand Down
7 changes: 3 additions & 4 deletions src/app_forecaster/gui/asFramePredictandDB.cpp
Expand Up @@ -246,7 +246,7 @@ void asFramePredictandDB::BuildDatabase(wxCommandEvent &event)

// Instantiate a predictand object
asPredictandPrecipitation predictand(asPredictand::Precipitation, temporalResolution,
spatialAggregation);
spatialAggregation);
predictand.SetHasReferenceValues(m_checkBoxReturnPeriod->GetValue());
predictand.SetIsSqrt(m_checkBoxSqrt->GetValue());
predictand.BuildPredictandDB(catalogFilePath, pathDataDir, pathPatternsDir, pathDestinationDir);
Expand All @@ -256,15 +256,14 @@ void asFramePredictandDB::BuildDatabase(wxCommandEvent &event)
{
// Instantiate a predictand object
asPredictandTemperature predictand(asPredictand::AirTemperature, temporalResolution,
spatialAggregation);
spatialAggregation);
predictand.BuildPredictandDB(catalogFilePath, pathDataDir, pathPatternsDir, pathDestinationDir);
break;
}
case 2: // Lightnings
{
// Instantiate a predictand object
asPredictandLightnings predictand(asPredictand::Lightnings, temporalResolution,
spatialAggregation);
asPredictandLightnings predictand(asPredictand::Lightnings, temporalResolution, spatialAggregation);
predictand.BuildPredictandDB(catalogFilePath, pathDataDir, pathPatternsDir, pathDestinationDir);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/app_optimizer/core/AtmoswingAppOptimizer.cpp
Expand Up @@ -433,7 +433,7 @@ bool AtmoswingAppOptimizer::OnCmdLineParsed(wxCmdLineParser &parser)
wxString logLevelStr = wxEmptyString;
if (parser.Found("log-level", &logLevelStr)) {
long logLevel = -1;
if(!logLevelStr.ToLong(&logLevel)) {
if (!logLevelStr.ToLong(&logLevel)) {
wxPrintf(_("The value provided for 'log-level' could not be interpreted."));
return false;
}
Expand Down Expand Up @@ -795,7 +795,7 @@ void AtmoswingAppOptimizer::CleanUp()
{
#if wxUSE_GUI
// Instance checker
wxDELETE(m_singleInstanceChecker);
wxDELETE(m_singleInstanceChecker);
#endif

// Config file (from wxWidgets samples)
Expand All @@ -807,7 +807,7 @@ void AtmoswingAppOptimizer::CleanUp()

#if wxUSE_GUI
// Delete images
cleanup_images();
cleanup_images();
#endif

// CleanUp
Expand Down
23 changes: 11 additions & 12 deletions src/app_optimizer/core/asMethodCalibrator.cpp
Expand Up @@ -204,8 +204,7 @@ void asMethodCalibrator::SortScoresAndParametersTemp()
}
}

bool asMethodCalibrator::PushBackInTempIfBetter(asParametersCalibration &params,
asResultsTotalScore &scoreFinal)
bool asMethodCalibrator::PushBackInTempIfBetter(asParametersCalibration &params, asResultsTotalScore &scoreFinal)
{
float thisScore = scoreFinal.GetScore();

Expand Down Expand Up @@ -690,8 +689,8 @@ bool asMethodCalibrator::PreloadDataWithoutPreprocessing(asParametersScoring &pa
for (unsigned int iLevel = 0; iLevel < preloadLevels.size(); iLevel++) {
for (unsigned int iHour = 0; iHour < preloadTimeHours.size(); iHour++) {
// Loading the dataset information
asPredictorArch *predictor = asPredictorArch::GetInstance(
params.GetPredictorDatasetId(iStep, iPtor), preloadDataIds[iPre], m_predictorDataDir);
asPredictorArch *predictor = asPredictorArch::GetInstance(params.GetPredictorDatasetId(iStep, iPtor),
preloadDataIds[iPre], m_predictorDataDir);
if (!predictor) {
return false;
}
Expand Down Expand Up @@ -1153,8 +1152,7 @@ bool asMethodCalibrator::ExtractPreloadedData(std::vector<asPredictor *> &predic

// Copy the data
wxASSERT(m_preloadedArchive[iStep][iPtor][iPre][iLevel][iHour]);
asPredictorArch *desiredPredictor = new asPredictorArch(
*m_preloadedArchive[iStep][iPtor][iPre][iLevel][iHour]);
asPredictorArch *desiredPredictor = new asPredictorArch(*m_preloadedArchive[iStep][iPtor][iPre][iLevel][iHour]);

// Area object instantiation
asGeoAreaCompositeGrid *desiredArea = asGeoAreaCompositeGrid::GetInstance(params.GetPredictorGridType(iStep, iPtor),
Expand Down Expand Up @@ -1216,8 +1214,8 @@ bool asMethodCalibrator::ExtractDataWithoutPreprocessing(std::vector<asPredictor

// Loading the datasets information
asPredictorArch *predictor = asPredictorArch::GetInstance(params.GetPredictorDatasetId(iStep, iPtor),
params.GetPredictorDataId(iStep, iPtor),
m_predictorDataDir);
params.GetPredictorDataId(iStep, iPtor),
m_predictorDataDir);
if (!predictor) {
return false;
}
Expand Down Expand Up @@ -1374,7 +1372,8 @@ va1f asMethodCalibrator::GetClimatologyData(asParametersScoring &params)

// Check if data are effectively available for this period
int indexPredictandTimeStart = asTools::SortedArraySearchCeil(&predictandTime[0],
&predictandTime[predictandTime.size() - 1], timeStart);
&predictandTime[predictandTime.size() - 1],
timeStart);
int indexPredictandTimeEnd = asTools::SortedArraySearchFloor(&predictandTime[0],
&predictandTime[predictandTime.size() - 1], timeEnd);

Expand Down Expand Up @@ -1806,8 +1805,8 @@ bool asMethodCalibrator::GetAnalogsTotalScore(asResultsTotalScore &results, asPa
return true;
}

bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration &params,
asResultsDates &anaDatesPrevious, int iStep)
bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration &params, asResultsDates &anaDatesPrevious,
int iStep)
{
vi analogsNbVect = params.GetAnalogsNumberVector(iStep);

Expand All @@ -1824,7 +1823,7 @@ bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration &params
asResultsDates anaDates;
asResultsValues anaValues;

if (rowEnd<0) {
if (rowEnd < 0) {
wxLogError(_("Error assessing the number of analogues."));
return false;
}
Expand Down
29 changes: 13 additions & 16 deletions src/app_optimizer/core/asMethodCalibrator.h
Expand Up @@ -61,20 +61,17 @@ class asMethodCalibrator

bool GetAnalogsDates(asResultsDates &results, asParametersScoring &params, int iStep, bool &containsNaNs);

bool GetAnalogsSubDates(asResultsDates &results, asParametersScoring &params,
asResultsDates &anaDates, int iStep, bool &containsNaNs);
bool GetAnalogsSubDates(asResultsDates &results, asParametersScoring &params, asResultsDates &anaDates, int iStep,
bool &containsNaNs);

bool GetAnalogsValues(asResultsValues &results, asParametersScoring &params, asResultsDates &anaDates,
int iStep);
bool GetAnalogsValues(asResultsValues &results, asParametersScoring &params, asResultsDates &anaDates, int iStep);

bool GetAnalogsScores(asResultsScores &results, asParametersScoring &params,
asResultsValues &anaValues, int iStep);
bool GetAnalogsScores(asResultsScores &results, asParametersScoring &params, asResultsValues &anaValues, int iStep);

bool GetAnalogsTotalScore(asResultsTotalScore &results, asParametersScoring &params,
asResultsScores &anaScores, int iStep);
bool GetAnalogsTotalScore(asResultsTotalScore &results, asParametersScoring &params, asResultsScores &anaScores,
int iStep);

bool SubProcessAnalogsNumber(asParametersCalibration &params, asResultsDates &anaDatesPrevious,
int iStep = 0);
bool SubProcessAnalogsNumber(asParametersCalibration &params, asResultsDates &anaDatesPrevious, int iStep = 0);

bool PreloadDataWithoutPreprocessing(asParametersScoring &params, int iStep, int iPtor, int iPre);

Expand Down Expand Up @@ -180,8 +177,8 @@ class asMethodCalibrator

bool PreloadData(asParametersScoring &params);

bool LoadData(std::vector<asPredictor *> &predictors, asParametersScoring &params, int iStep,
double timeStartData, double timeEndData);
bool LoadData(std::vector<asPredictor *> &predictors, asParametersScoring &params, int iStep, double timeStartData,
double timeEndData);

va1f GetClimatologyData(asParametersScoring &params);

Expand All @@ -206,11 +203,11 @@ class asMethodCalibrator
bool ExtractPreloadedData(std::vector<asPredictor *> &predictors, asParametersScoring &params, int iStep,
int iPtor);

bool ExtractDataWithoutPreprocessing(std::vector<asPredictor *> &predictors, asParametersScoring &params,
int iStep, int iPtor, double timeStartData, double timeEndData);
bool ExtractDataWithoutPreprocessing(std::vector<asPredictor *> &predictors, asParametersScoring &params, int iStep,
int iPtor, double timeStartData, double timeEndData);

bool ExtractDataWithPreprocessing(std::vector<asPredictor *> &predictors, asParametersScoring &params,
int iStep, int iPtor, double timeStartData, double timeEndData);
bool ExtractDataWithPreprocessing(std::vector<asPredictor *> &predictors, asParametersScoring &params, int iStep,
int iPtor, double timeStartData, double timeEndData);

bool HasPreloadedData(int iStep, int iPtor) const;

Expand Down
3 changes: 1 addition & 2 deletions src/app_optimizer/core/asMethodCalibratorClassic.cpp
Expand Up @@ -432,8 +432,7 @@ bool asMethodCalibratorClassic::EvaluateRelevanceMap(const asParametersCalibrati
return true;
}

bool asMethodCalibratorClassic::AssessDomainResizing(asParametersCalibration &params,
asResultsDates &anaDatesPrevious,
bool asMethodCalibratorClassic::AssessDomainResizing(asParametersCalibration &params, asResultsDates &anaDatesPrevious,
asResultsParametersArray &resultsTested, int iStep,
const asMethodCalibrator::ParamExploration &explo)
{
Expand Down
15 changes: 9 additions & 6 deletions src/app_optimizer/core/asMethodOptimizerGeneticAlgorithms.cpp
Expand Up @@ -319,8 +319,9 @@ bool asMethodOptimizerGeneticAlgorithms::ManageOneRun()
vf scoreClim = m_scoreClimatology;

// Push the first parameters set
asThreadGeneticAlgorithms *firstThread = new asThreadGeneticAlgorithms(
this, newParams, &m_scoresCalib[m_iterator], &m_scoreClimatology);
asThreadGeneticAlgorithms *firstThread = new asThreadGeneticAlgorithms(this, newParams,
&m_scoresCalib[m_iterator],
&m_scoreClimatology);
int threadType = firstThread->GetType();
ThreadsManager().AddThread(firstThread);

Expand Down Expand Up @@ -356,8 +357,9 @@ bool asMethodOptimizerGeneticAlgorithms::ManageOneRun()
}

// Add it to the threads
asThreadGeneticAlgorithms *thread = new asThreadGeneticAlgorithms(
this, nextParams, &m_scoresCalib[m_iterator], &m_scoreClimatology);
asThreadGeneticAlgorithms *thread = new asThreadGeneticAlgorithms(this, nextParams,
&m_scoresCalib[m_iterator],
&m_scoreClimatology);
ThreadsManager().AddThread(thread);

wxASSERT(m_scoresCalib.size() <= (unsigned) m_paramsNb);
Expand Down Expand Up @@ -393,8 +395,9 @@ bool asMethodOptimizerGeneticAlgorithms::ManageOneRun()
}

// Add it to the threads
asThreadGeneticAlgorithms *thread = new asThreadGeneticAlgorithms(
this, nextParams, &m_scoresCalib[m_iterator], &m_scoreClimatology);
asThreadGeneticAlgorithms *thread = new asThreadGeneticAlgorithms(this, nextParams,
&m_scoresCalib[m_iterator],
&m_scoreClimatology);
ThreadsManager().AddThread(thread);

wxASSERT(m_scoresCalib.size() <= (unsigned) m_paramsNb);
Expand Down
15 changes: 6 additions & 9 deletions src/app_optimizer/core/asMethodOptimizerRandomSet.cpp
Expand Up @@ -126,9 +126,8 @@ bool asMethodOptimizerRandomSet::Manager()
vf scoreClim = m_scoreClimatology;

// Push the first parameters set
asThreadRandomSet *firstThread = new asThreadRandomSet(this, nextParams,
&m_scoresCalib[m_iterator],
&m_scoreClimatology);
asThreadRandomSet *firstThread = new asThreadRandomSet(this, nextParams, &m_scoresCalib[m_iterator],
&m_scoreClimatology);
int threadType = firstThread->GetType();
ThreadsManager().AddThread(firstThread);

Expand Down Expand Up @@ -157,9 +156,8 @@ bool asMethodOptimizerRandomSet::Manager()
nextParams = GetNextParameters();

// Add it to the threads
asThreadRandomSet *thread = new asThreadRandomSet(this, nextParams,
&m_scoresCalib[m_iterator],
&m_scoreClimatology);
asThreadRandomSet *thread = new asThreadRandomSet(this, nextParams, &m_scoresCalib[m_iterator],
&m_scoreClimatology);
ThreadsManager().AddThread(thread);

wxASSERT(m_scoresCalib.size() <= (unsigned) m_paramsNb);
Expand All @@ -183,9 +181,8 @@ bool asMethodOptimizerRandomSet::Manager()
nextParams = GetNextParameters();

// Add it to the threads
asThreadRandomSet *thread = new asThreadRandomSet(this, nextParams,
&m_scoresCalib[m_iterator],
&m_scoreClimatology);
asThreadRandomSet *thread = new asThreadRandomSet(this, nextParams, &m_scoresCalib[m_iterator],
&m_scoreClimatology);
ThreadsManager().AddThread(thread);

wxASSERT(m_scoresCalib.size() <= (unsigned) m_paramsNb);
Expand Down

0 comments on commit 16ebc6f

Please sign in to comment.