Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solar activity Data parser + extractor + data structure of A. Ronse + reader #24

Merged
merged 10 commits into from
Apr 5, 2016
10 changes: 10 additions & 0 deletions Tudat/InputOutput/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ set(INPUTOUTPUT_SOURCES
"${SRCROOT}${INPUTOUTPUTDIR}/twoLineElementsTextFileReader.cpp"
"${SRCROOT}${INPUTOUTPUTDIR}/matrixTextFileReader.cpp"
"${SRCROOT}${INPUTOUTPUTDIR}/streamFilters.cpp"
"${SRCROOT}${INPUTOUTPUTDIR}/parseSolarActivityData.cpp"
"${SRCROOT}${INPUTOUTPUTDIR}/extractSolarActivityData.cpp"
"${SRCROOT}${INPUTOUTPUTDIR}/solarActivityData.cpp"
)

# Add header files.
Expand All @@ -74,6 +77,9 @@ set(INPUTOUTPUT_HEADERS
"${SRCROOT}${INPUTOUTPUTDIR}/basicInputOutput.h"
"${SRCROOT}${INPUTOUTPUTDIR}/matrixTextFileReader.h"
"${SRCROOT}${INPUTOUTPUTDIR}/streamFilters.h"
"${SRCROOT}${INPUTOUTPUTDIR}/parseSolarActivityData.h"
"${SRCROOT}${INPUTOUTPUTDIR}/extractSolarActivityData.h"
"${SRCROOT}${INPUTOUTPUTDIR}/solarActivityData.h"
)

# Add unit test files.
Expand Down Expand Up @@ -143,3 +149,7 @@ target_link_libraries(test_SeparatedParser tudat_input_output ${Boost_LIBRARIES}
add_executable(test_LinearFieldTransform "${SRCROOT}${INPUTOUTPUTDIR}/UnitTests/unitTestLinearFieldTransform.cpp")
setup_custom_test_program(test_LinearFieldTransform "${SRCROOT}${INPUTOUTPUTDIR}")
target_link_libraries(test_LinearFieldTransform tudat_input_output ${Boost_LIBRARIES})

add_executable(test_SolarActivityData "${SRCROOT}${INPUTOUTPUTDIR}/UnitTests/unitTestSolarActivityData.cpp")
setup_custom_test_program(test_SolarActivityData "${SRCROOT}${INPUTOUTPUTDIR}")
target_link_libraries(test_SolarActivityData tudat_input_output tudat_basic_astrodynamics ${Boost_LIBRARIES})
21,565 changes: 21,565 additions & 0 deletions Tudat/InputOutput/UnitTests/sw19571001.txt

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions Tudat/InputOutput/UnitTests/testSolarActivity.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
DATATYPE UnitTestFile

# --------------------------------------------------------------------------------------------------------------------------------
#
# See http://celestrak.com/SpaceData/SpaceWx-format.asp for format details.
#
# FORMAT(I4,I3,I3,I5,I3,8I3,I4,8I4,I4,F4.1,I2,I4,F6.1,I2,5F6.1)
# --------------------------------------------------------------------------------------------------------------------------------
# Adj Adj Adj Obs Obs Obs
# yy mm dd BSRN ND Kp Kp Kp Kp Kp Kp Kp Kp Sum Ap Ap Ap Ap Ap Ap Ap Ap Avg Cp C9 ISN F10.7 Q Ctr81 Lst81 F10.7 Ctr81 Lst81
# --------------------------------------------------------------------------------------------------------------------------------
#
NUM_OBSERVED_POINTS
BEGIN OBSERVED
1957 10 01 1700 19 43 40 30 20 37 23 43 37 273 32 27 15 7 22 9 32 22 21 1.1 5 236 268.0 0 265.2 230.6 269.3 266.6 230.9
1957 10 02 1700 20 37 37 17 17 27 23 17 30 203 22 22 6 6 12 9 6 15 12 0.7 3 234 252.0 0 266.0 231.4 253.3 267.4 231.7
1957 10 03 1700 21 27 20 13 33 37 47 43 30 250 12 7 5 18 22 39 32 15 19 1.0 5 242 265.0 0 266.7 232.3 266.3 268.1 232.7
2012 03 01 2436 22 10 30 30 30 30 20 40 40 230 4 15 15 15 15 7 27 27 15 24 103.0 0 110.6 118.9 108.2 111.6 123.8
2012 03 02 2436 23 30 30 30 10 30 20 20 20 190 15 15 15 4 15 7 7 7 10 24 108.0 0 110.1 118.6 116.4 111.0 123.6
2012 03 03 2436 24 20 30 30 20 10 20 10 20 160 7 15 15 7 4 7 4 7 8 52 116.0 0 109.6 118.5 120.1 110.4 123.5
2012 04 29 2438 27 20 20 10 10 10 10 10 0 90 7 7 4 4 4 4 4 0 4 114 116.0 0 115.9 111.4 114.3 114.3 111.9
2012 04 30 2439 1 10 10 10 10 0 10 0 0 50 4 4 4 4 0 4 0 0 2 104 114.0 0 116.3 111.6 112.3 114.7 111.9
2012 05 01 2439 2 0 10 10 22 22 22 22 22 130 0 4 4 8 8 8 8 8 6 114.0 0 116.7 111.7 112.2 115.0 111.9
END OBSERVED

NUM_DAILY_PREDICTED_POINTS 44
BEGIN DAILY_PREDICTED
2012 05 02 2439 3 22 22 22 22 22 22 22 22 176 8 8 8 8 8 8 8 8 8 115.0 117.1 111.8 113.2 115.3 111.9
2012 05 03 2439 4 13 13 13 13 13 13 13 13 104 5 5 5 5 5 5 5 5 5 115.0 117.5 111.9 113.1 115.7 112.0
2012 05 04 2439 5 13 13 13 13 13 13 13 13 104 5 5 5 5 5 5 5 5 5 115.0 117.9 112.0 113.1 116.1 112.0
END DAILY_PREDICTED

NUM_MONTHLY_PREDICTED_POINTS 90
BEGIN MONTHLY_PREDICTED
2012 07 01 2441 9 132.6 128.6 118.6 128.3 125.0 116.6
2012 08 01 2442 13 134.4 133.6 126.5 130.5 130.1 123.1
2012 09 01 2443 17 136.9 135.7 130.6 134.5 133.5 127.0
END MONTHLY_PREDICTED

NUM_MONTHLY_FIT_POINTS 37
MONTHLY_FIT_TYPE F10.7ADJ = 145 + 75*COS(0.001696*T + 0.35*SIN(0.001696*T)), T = MJD - 44605
BEGIN MONTHLY_FIT
2022 11 01 2581 4 183.8 183.8 189.1 186.6 186.3 187.8
2022 12 01 2582 7 179.7 179.7 185.1 184.8 184.3 186.8
2023 01 01 2583 11 175.3 0.0 0.0 181.3 0.0 0.0
END MONTHLY_FIT
189 changes: 189 additions & 0 deletions Tudat/InputOutput/UnitTests/unitTestSolarActivityData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/* Copyright (c) 2010-2016, Delft University of Technology
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* - Neither the name of the Delft University of Technology nor the names of its contributors
* may be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changelog
* YYMMDD Author Comment
* 120701 A. Ronse Creation of code.
* 160324 R. Hoogendoorn Update for use in current version of Tudat
*
* References
* Data source for validation figures:
* http://celestrak.com/SpaceData/sw19571001.txt
*
*/

#define BOOST_TEST_MAIN

#include <istream>
#include <string>
#include <vector>
#include <map>

#include <boost/shared_ptr.hpp>
#include <boost/test/unit_test.hpp>

#include <Eigen/Core>

#include "Tudat/InputOutput/parsedDataVectorUtilities.h"
#include "Tudat/InputOutput/parseSolarActivityData.h"
#include "Tudat/InputOutput/extractSolarActivityData.h"
#include "Tudat/InputOutput/solarActivityData.h"
#include "Tudat/InputOutput/basicInputOutput.h"

#include <tudat/Basics/testMacros.h>

namespace tudat
{
namespace unit_tests
{

BOOST_AUTO_TEST_SUITE( test_Solar_Activity_Parser_Extractor )

//! Test parsing and extraction process of solar dummy activity file
BOOST_AUTO_TEST_CASE( test_parsing_and_extraction )
{
tudat::input_output::parsed_data_vector_utilities::ParsedDataVectorPtr parsedDataVectorPtr;

tudat::input_output::solar_activity::ParseSolarActivityData solarActivityParser;
tudat::input_output::solar_activity::ExtractSolarActivityData solarActivityExtractor;

// Parse file
// save path of cpp file
std::string cppPath( __FILE__ );

// Strip filename from temporary string and return root-path string.
std::string folder = cppPath.substr( 0, cppPath.find_last_of("/\\")+1);
std::string filePath = folder + "testSolarActivity.txt" ;

// Open dataFile
std::ifstream dataFile;
dataFile.open(filePath.c_str(), std::ifstream::in);
parsedDataVectorPtr = solarActivityParser.parse( dataFile );
dataFile.close();

// Extract data to object of solarActivityData class
std::vector< boost::shared_ptr<tudat::input_output::solar_activity::SolarActivityData> >
solarActivityData( 6 );
solarActivityData[0] = solarActivityExtractor.extract( parsedDataVectorPtr->at( 0 ) );
solarActivityData[1] = solarActivityExtractor.extract( parsedDataVectorPtr->at( 3 ) );
solarActivityData[2] = solarActivityExtractor.extract( parsedDataVectorPtr->at( 8 ) );
solarActivityData[3] = solarActivityExtractor.extract( parsedDataVectorPtr->at( 9 ) );
solarActivityData[4] = solarActivityExtractor.extract( parsedDataVectorPtr->at( 12 ) );
solarActivityData[5] = solarActivityExtractor.extract( parsedDataVectorPtr->at( 15 ) );

// Check single parameters
BOOST_CHECK_EQUAL( solarActivityData[0]->dataType, 1 );
BOOST_CHECK_EQUAL( solarActivityData[1]->planetaryDailyCharacterFigure, 0.0 );
BOOST_CHECK_EQUAL( solarActivityData[1]->solarRadioFlux107Adjusted, 103.0 );
BOOST_CHECK_EQUAL( solarActivityData[2]->month, 5 );
BOOST_CHECK_EQUAL( solarActivityData[2]->internationalSunspotNumber, 0 );
BOOST_CHECK_EQUAL( solarActivityData[3]->planetaryRangeIndexSum, 176 );
BOOST_CHECK_EQUAL( solarActivityData[3]->planetaryDailyCharacterFigureConverted, 0 );
BOOST_CHECK_EQUAL( solarActivityData[4]->bartelsSolarRotationNumber, 2441 );
BOOST_CHECK_EQUAL( solarActivityData[5]->last81DaySolarRadioFlux107Observed, 187.8 );

// Check planetaryEquivalentAmplitudeVectors
Eigen::VectorXd correctPlanetaryEquivalentAmplitudeVector1( 8 );
correctPlanetaryEquivalentAmplitudeVector1 << 32, 27, 15, 7, 22, 9, 32, 22;
Eigen::VectorXd correctPlanetaryEquivalentAmplitudeVector2 = Eigen::VectorXd::Zero( 8 );

TUDAT_CHECK_MATRIX_CLOSE( solarActivityData[0]->planetaryEquivalentAmplitudeVector,
correctPlanetaryEquivalentAmplitudeVector1, 0 );
TUDAT_CHECK_MATRIX_CLOSE( solarActivityData[4]->planetaryEquivalentAmplitudeVector,
correctPlanetaryEquivalentAmplitudeVector2 , 0);
TUDAT_CHECK_MATRIX_CLOSE( solarActivityData[5]->planetaryEquivalentAmplitudeVector,
correctPlanetaryEquivalentAmplitudeVector2, 0 );
}

BOOST_AUTO_TEST_CASE( test_function_readSolarActivityData ){
using tudat::input_output::solar_activity::SolarActivityDataMap ;
using tudat::input_output::solar_activity::SolarActivityData ;

// Parse file
// save path of cpp file
std::string cppPath( __FILE__ );

// Strip filename from temporary string and return root-path string.
std::string folder = cppPath.substr( 0, cppPath.find_last_of("/\\")+1);
std::string filePath = folder + "testSolarActivity.txt" ;

SolarActivityDataMap SolarActivity = tudat::input_output::solar_activity::readSolarActivityData(filePath) ;

double JulianDate ;
JulianDate = tudat::basic_astrodynamics::convertCalendarDateToJulianDay(
1957,
10,
3,
0, 0, 0.0) ;

SolarActivityDataMap::iterator it;
it = SolarActivity.find(JulianDate) ;

BOOST_CHECK_EQUAL( it->second->day , 3 );
BOOST_CHECK_EQUAL( it->second->centered81DaySolarRadioFlux107Observed , 268.1 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryEquivalentAmplitudeAverage , 19 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryRangeIndexSum , 250 ) ;

JulianDate = tudat::basic_astrodynamics::convertCalendarDateToJulianDay(
2023,
1,
1,
0, 0, 0.0) ;

it = SolarActivity.find(JulianDate) ;

BOOST_CHECK_EQUAL( it->second->day , 1 );
BOOST_CHECK_EQUAL( it->second->bartelsSolarRotationNumber , 2583 ) ;
BOOST_CHECK_EQUAL( it->second->centered81DaySolarRadioFlux107Observed , 0.0 ) ;
BOOST_CHECK_EQUAL( it->second->last81DaySolarRadioFlux107Adjusted , 0.0 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryEquivalentAmplitudeAverage , 0.0 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryRangeIndexSum , 0.0 ) ;

std::string filePath2 = folder + "sw19571001.txt" ;

SolarActivityDataMap SolarActivity2 = tudat::input_output::solar_activity::readSolarActivityData(filePath2) ;

JulianDate = tudat::basic_astrodynamics::convertCalendarDateToJulianDay(
1993,
12,
11,
0, 0, 0.0) ;

it = SolarActivity2.find(JulianDate) ;

BOOST_CHECK_EQUAL( it->second->day , 11 );
BOOST_CHECK_EQUAL( it->second->bartelsSolarRotationNumber , 2190 ) ;
BOOST_CHECK_EQUAL( it->second->centered81DaySolarRadioFlux107Observed , 104.0 ) ;
BOOST_CHECK_EQUAL( it->second->last81DaySolarRadioFlux107Adjusted , 97.6 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryEquivalentAmplitudeAverage , 7 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryRangeIndexSum , 143 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryDailyCharacterFigure , 0.4 ) ;
BOOST_CHECK_EQUAL( it->second->planetaryDailyCharacterFigureConverted , 2 ) ;
BOOST_CHECK_EQUAL( it->second->internationalSunspotNumber , 31 ) ;
}

BOOST_AUTO_TEST_SUITE_END( )

} // unit_tests
} // tudat
Loading