Skip to content

Commit

Permalink
Merge pull request #88 from rogerfraser/master
Browse files Browse the repository at this point in the history
Extend discontinuity renaming functionality, bug fix and other enhancements
  • Loading branch information
rogerfraser authored Apr 13, 2021
2 parents 8506399 + 66bfe0d commit e4f85c7
Show file tree
Hide file tree
Showing 10 changed files with 4,880 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dynadjust/bin/
*.db-wal
*.user
/.idea/
.vscode/launch.json
.vscode/*

# readme and other files not requiring external contribution
README.md
5 changes: 5 additions & 0 deletions dynadjust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ if (BUILD_TESTING)
add_test (NAME ref-itrf-pmm-05 COMMAND $<TARGET_FILE:dnaimportwrapper> -n apr -r itrf2008 ${CMAKE_SOURCE_DIR}/../sampleData/apr.ITRF2008.04.06.2020.stn ${CMAKE_SOURCE_DIR}/../sampleData/apr.ITRF2008.04.06.2020.msr)
add_test (NAME ref-itrf-pmm-06 COMMAND $<TARGET_FILE:dnareftranwrapper> apr -r itrf2008 -e 01.01.2021 --export-dna --verb 2 --plate-model-option 1 -b ${CMAKE_SOURCE_DIR}/../sampleData/MORVEL56_plates.dig -m ${CMAKE_SOURCE_DIR}/../sampleData/NNR-MORVEL56_poles.dat)
add_test (NAME ref-itrf-pmm-07 COMMAND bash -c "diff <(tail -n +6 apr.ITRF2008.01.01.2021.stn) <(tail -n +4 ${CMAKE_SOURCE_DIR}/../sampleData/apr.ITRF2008.01.01.2021.stn.expected)")

add_test (NAME imp-discont-01 COMMAND $<TARGET_FILE:dnaimportwrapper> -n discont -r itrf2005 ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx)
add_test (NAME imp-discont-02 COMMAND $<TARGET_FILE:dnaimportwrapper> -n discont -r itrf2005 ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx --split-gnss --include-stn "ALIC" --export-dna)

add_test (NAME imp-m2s-sort-01 COMMAND $<TARGET_FILE:dnaimportwrapper> -n gnss ${CMAKE_SOURCE_DIR}/../sampleData/gnss-network.stn ${CMAKE_SOURCE_DIR}/../sampleData/gnss-network.msr --output-msr-to-stn --sort-msr-to-stn-field 1 -r GDA94)

# set execution dependencies (the execution of tests must be sequential)
set_tests_properties(
import-gnss-network geoid-gnss-network adjust-gnss-network
Expand Down
6 changes: 3 additions & 3 deletions dynadjust/dynadjust/dnaadjust/dnaadjust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9641,9 +9641,9 @@ void dna_adjust::PrintAdjStation(ostream& os,
StringFromTW(sqrt(var_local.get(2, 2)), STDDEV, PRECISION_MTR_STN);
else
os <<
StringFromT(sqrt(var_local.get(0, 0)), PRECISION_MTR_STN) <<
StringFromT(sqrt(var_local.get(1, 1)), PRECISION_MTR_STN) <<
StringFromT(sqrt(var_local.get(2, 2)), PRECISION_MTR_STN);
setw(STDDEV) << right << StringFromT(sqrt(var_local.get(0, 0)), PRECISION_MTR_STN) <<
setw(STDDEV) << right << StringFromT(sqrt(var_local.get(1, 1)), PRECISION_MTR_STN) <<
setw(STDDEV) << right << StringFromT(sqrt(var_local.get(2, 2)), PRECISION_MTR_STN);

if (projectSettings_.o._stn_corr)
{
Expand Down
98 changes: 74 additions & 24 deletions dynadjust/dynadjust/dnaimport/dnainterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,46 @@ void dna_import::BuildExtractStationsList(const string& stnList, pvstring vstnLi
ss << "BuildExtractStationsList(): An error was encountered when parsing " << stnList << "." << endl;
SignalExceptionParse(ss.str(), 0);
}

// Have discontinuities been applied?
if (!projectSettings_.i.apply_discontinuities)
return;

if (stn_renamed_.empty())
return;

it_string_pair _it_discont_ren;

_it_vstr _it_stn;
string station_name;
vstring renamed_stations;

// loop through all station names in vstnList
for (_it_stn = vstnList->begin();
_it_stn != vstnList->end();
_it_stn++)
{
station_name = *_it_stn;

_it_discont_ren = stn_renamed_.begin();

// Advance through _it_discont_ren for all occurrences of station_name
while ((_it_discont_ren = lower_bound(_it_discont_ren, stn_renamed_.end(),
station_name, ComparePairFirst<string>())) != stn_renamed_.end())
{
// found a station that has been renamed.
// add the discontinuity name to the list
renamed_stations.push_back(_it_discont_ren->second);
_it_discont_ren++;
}
}

// Add discontinuity sites and remove duplicates
if (!renamed_stations.empty())
{
vstnList->insert(vstnList->end(), renamed_stations.begin(), renamed_stations.end());
strip_duplicates(vstnList);
}
}


Expand Down Expand Up @@ -719,25 +759,32 @@ void dna_import::ParseDiscontinuities(const string& fileName)
discont_file.close();
}

// Station names in SINEX files are automatically renamed to account for discontinuities and added
// to vStations. For non SINEX files, any renamed stations are tracked in stn_renamed_. After
// all files have been loaded, this function is called to (1) find any discontinuity stations not in the
// station list and (2) add a duplicate for it, renamed to the respective discontinuity site name.
void dna_import::AddDiscontinuityStations(vdnaStnPtr* vStations)
{
_it_vdnastnptr _it_stn(vStations->begin());
it_string_pair stn_renames_it;
it_string_pair stn_renames_it(stn_renamed_.begin());

dnaStnPtr stn_ptr;
string stationName;

UINT32 i, station_count(static_cast<UINT32>(vStations->size()));
UINT32 station_index(station_count);

sort(vStations->begin(), vStations->end(), CompareStationName<dnaStnPtr>());

for (i=0; i<station_count; ++i)
{
stationName = vStations->at(i)->GetName();

// For each occurrence of stationName in stn_renamed_, create a clone and add it to
// vStations so that the measurement stations renamed by ApplyDiscontinuitiesMeasurements
// are supported by corresponding stations
while ((stn_renames_it = binary_search_index_pair(stn_renamed_.begin(), stn_renamed_.end(), stationName)) != stn_renamed_.end())
// vStations so that the measurement stations in non SINEX files that are
// renamed by ApplyDiscontinuitiesMeasurements (via TrackDiscontinuitySite) are
// supported by corresponding stations.
while ((stn_renames_it = binary_search_index_pair(stn_renames_it, stn_renamed_.end(), stationName)) != stn_renamed_.end())
{
// If a sinex file has been loaded and stationName exists in the sinex file, stn_renames_it->second may
// already exist in vStations. In this case, the following code will add a duplicate station.
Expand All @@ -752,15 +799,13 @@ void dna_import::AddDiscontinuityStations(vdnaStnPtr* vStations)
stn_ptr->SetfileOrder(++station_index);
vStations->push_back(stn_ptr);

if (!stn_renamed_.empty())
stn_renamed_.erase(stn_renames_it);
stn_renames_it++;
}

if (stn_renamed_.empty())
break;
stn_renames_it = stn_renamed_.begin();
}

// Removde duplicates which may have been added through the above process
// Remove duplicates which may have been added through the above process
sort(vStations->begin(), vStations->end(), CompareStationName<dnaStnPtr>());
_it_vdnastnptr _it_stn_newend = unique(vStations->begin(), vStations->end(), EqualStationName<dnaStnPtr>());
if (_it_stn_newend != vStations->end())
Expand All @@ -771,11 +816,6 @@ void dna_import::AddDiscontinuityStations(vdnaStnPtr* vStations)

void dna_import::ApplyDiscontinuities(vdnaStnPtr* vStations, vdnaMsrPtr* vMeasurements, project_settings* p)
{
#ifndef _MSDEBUG
// return on release
return;
#endif

if (stn_discontinuities_.empty())
return;

Expand All @@ -786,11 +826,16 @@ void dna_import::ApplyDiscontinuities(vdnaStnPtr* vStations, vdnaMsrPtr* vMeasur
m_discontsSortedbyName = true;
}

// There isn't any need to apply discontinuities to a station file, since those
// stations will be introduced via the process of handling a discontinuity file.
// DynAdjust should load the stations as normal. If a station becomes renamed
// through the process of applying discontinuities to measurements, then it will
// be flagged as unused (since it won't be found in the measurements).
// If the only input file is a SINEX file, there isn't any need to apply discontinuities
// to a station file, since those stations will be introduced via the process of
// handling a discontinuity file.
// However, if other station and measurement file types are loaded, there may be a case
// where station discontinuities exist but have not been accounted for at this point.
// For this purpose, a call to ApplyDiscontinuitiesStations will be made after all files
// have been imported.
// If a station becomes renamed through the process of applying discontinuities to
// measurements, then it will be flagged as unused (since it won't be found in the
// measurements).

if (!vMeasurements->empty())
ApplyDiscontinuitiesMeasurements(vMeasurements, p);
Expand All @@ -805,9 +850,10 @@ void dna_import::TrackDiscontinuitySite(const string& site, const string& site_r
}
}


// This function renames stations in each measurement based on a discontinuity file
// NOTE: A fundamental prerequisite for the proper renaming of discontinuity sites
// in this function is a valid epoch for each measurement!s
// in this function is a valid epoch for each measurement!
void dna_import::ApplyDiscontinuitiesMeasurements(vdnaMsrPtr* vMeasurements, project_settings* p)
{
_it_vdiscontinuity_tuple _it_discont(stn_discontinuities_.begin());
Expand Down Expand Up @@ -1434,6 +1480,12 @@ void dna_import::ParseDNASTN(vdnaStnPtr* vStations, PUINT32 stnCount, string* su
catch (...) {
switch (stn_ptr->GetMyCoordTypeC())
{
case LLh_type_i:
case LLH_type_i:
case ENU_type_i:
case AED_type_i:
case XYZ_type_i:
break;
case UTM_type_i: // Hemisphere and zone is only essential for UTM types
stringstream ss;
ss << "ParseDNASTN(): Could not extract station hemisphere and zone from the record: " << endl << " " << sBuf << endl;
Expand Down Expand Up @@ -3066,7 +3118,7 @@ void dna_import::ExtractStnsAndAssociatedMsrs(const string& stnListInclude, cons
// backup station vector
vdnaStnPtr bvStations = *vStations;

const string *stnListIn, *stnListEx;
const string *stnListIn;

vstring vIncludedStns;
pvstring pvStnsIn, pvStnsEx;
Expand All @@ -3077,15 +3129,13 @@ void dna_import::ExtractStnsAndAssociatedMsrs(const string& stnListInclude, cons
pvStnsIn = &vIncludedStns;
pvStnsEx = vExcludedStns;
stnListIn = &stnListInclude;
stnListEx = &stnListExclude;
}
// Has the user provided a list of stations to exclude?
else if (!stnListExclude.empty())
{
pvStnsIn = vExcludedStns;
pvStnsEx = &vIncludedStns;
stnListIn = &stnListExclude;
stnListEx = &stnListInclude;
}
else
{
Expand Down
1 change: 0 additions & 1 deletion dynadjust/dynadjust/dnaimport/dnainterop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class dna_import {
void RenameStations(vdnaStnPtr* vStations, vdnaMsrPtr* vMeasurements, project_settings* p);
void ApplyDiscontinuities(vdnaStnPtr* vStations, vdnaMsrPtr* vMeasurements, project_settings* p);
void TrackDiscontinuitySite(const string& site, const string& site_renamed);
void ApplyDiscontinuitiesStations(vdnaStnPtr* vStations, project_settings* p);
void ApplyDiscontinuitiesMeasurements(vdnaMsrPtr* vMeasurements, project_settings* p);

void ApplyDiscontinuitiesMeasurements_GX(vector<CDnaGpsBaseline>* vGpsBaselines);
Expand Down
32 changes: 16 additions & 16 deletions dynadjust/dynadjust/dnaimportwrapper/dnaimportwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ void ExportStationsandMeasurements(dna_import* parserDynaML, const project_setti
cout << "Done." << endl;
cout.flush();
}
*imp_file << "Done." << endl;
}
else
{
Expand Down Expand Up @@ -584,6 +585,7 @@ void ExportStationsandMeasurements(dna_import* parserDynaML, const project_setti
cout << "Done." << endl;
cout.flush();
}
*imp_file << "Done." << endl;
}
}

Expand Down Expand Up @@ -1442,6 +1444,18 @@ int main(int argc, char* argv[])
}
}

/////////////////////////////////////////////////////////////////////////
// Add discontinuity sites to vStations
//
// WARNING: If discontinuity sites are present in the renaming file, and
// the renaming file changes the name from the four-character id in the
// discontinuity file to another name, this function call will not work
// properly. Hence, sites in the discontinuity file must be consistently
// named in the station and measurement files and not renamed to another
// name.
if (p.i.apply_discontinuities && !vstationsTotal.empty())
parserDynaML.AddDiscontinuityStations(&vstationsTotal);

UINT32 stn;

// Extract user-defined stations and all connected measurements
Expand Down Expand Up @@ -1861,24 +1875,11 @@ int main(int argc, char* argv[])
imp_file.close();
return EXIT_FAILURE;
}

/////////////////////////////////////////////////////////////////////////
// Add discontinuity sites to vStations
//
// WARNING: If discontinuity sites are present in the renaming file, and
// the renaming file changes the name from the four-character id in the
// discontinuity file to another name, this function call will not work
// properly. Hence, sites in the discontinuity file must be consistently
// named in the station and measurement files and not renamed to another
// name.
if (p.i.apply_discontinuities && stnCount > 0)
parserDynaML.AddDiscontinuityStations(&vstationsTotal);

/////////////////////////////////////////////////////////////////
// Now commence sorting and mapping
// 1. Sort stations
// 2. Add new discontinuity sites
// 3. Create station map
// 2. Create station map
try {
if (!p.g.quiet)
{
Expand Down Expand Up @@ -2218,8 +2219,7 @@ int main(int argc, char* argv[])
}
}

// Create ASL and AML files
// Export to text if required
// Export ASL and AML to text if required
if (measurements_mapped)
{
try {
Expand Down
19 changes: 16 additions & 3 deletions dynadjust/include/functions/dnatemplatefuncs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,15 +959,28 @@ class CompareStnFileOrder


// S = CDnaStation
template<typename S>
template<typename S, typename T>
class CompareStnName_CDnaStn
{
public:
bool operator()(const boost::shared_ptr<S> lhs, const boost::shared_ptr<S> rhs) {
if (lhs.get()->GetName() == rhs.get()->GetName())
return (lhs.get()->GetfileOrder() < rhs.get()->GetfileOrder());
return (lhs.get()->GetName() < rhs.get()->GetName());

return keyLess(lhs.get()->GetName(), rhs.get()->GetName());
}

bool operator()(const T lhs, const boost::shared_ptr<S> rhs) {
return keyLess(lhs, rhs.get()->GetName());
}

bool operator()(const boost::shared_ptr<S> lhs, const T rhs) {
return keyLess(lhs.get()->GetName(), rhs);
}

private:
// the "real" comparison function
bool keyLess(const T& k1, const T& k2) const {
return k1 < k2;
}
};

Expand Down
2 changes: 1 addition & 1 deletion dynadjust/include/io/dnaiosnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class dna_io_snx : public dna_io_base
public:
dna_io_snx(void)
: blockCount_(0), block_(0), measurementParams_(0), unknownParams_(0)
, sigmaZero_(0.), uniqueStationCount_(0)
, sigmaZero_(0.), blockStationsMap_(0), uniqueStationCount_(0)
, containsVelocities_(false), containsDiscontinuities_(false), applyDiscontinuities_(false)
, siteIDsRead_(false), solutionEpochsRead_(false) {
}
Expand Down
1 change: 1 addition & 0 deletions dynadjust/include/measurement_types/dnastation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef boost::shared_ptr<CDnaStation> dnaStnPtr;
typedef vector<dnaStnPtr> vdnaStnPtr; // vector of dnaStnPtr
typedef vdnaStnPtr::iterator _it_vdnastnptr;
typedef vdnaStnPtr::const_iterator _it_vdnastnptr_const;
typedef pair<_it_vdnastnptr, _it_vdnastnptr> it_pair_dnastnptr;

typedef vector<CAStationList> vASL, *pvASL;
typedef vASL::iterator _it_vasl;
Expand Down
Loading

0 comments on commit e4f85c7

Please sign in to comment.