Jvinniec / CppEphem

CppEphem is a self-contained ephemeris package written in C++. It allows computation of celestial coordinate and date conversions and planet ephemerides by leveraging the Standards of Fundamental Astronomy (SOFA) software (included in the repo). It is C++11 compatible.
2 stars 2 forks source link

Enable downloading dut1, x-polar, and y-polar-motion corrections #13

Closed Jvinniec closed 5 years ago

Jvinniec commented 5 years ago

Quick note: This idea is taken directly from how Astropy obtains their correction values.

The idea is to use libcurl to optionally download the corrections to a local file, which can then be loaded when the program is run to obtain more accurate position values for specific dates.

I've already implemented a short test of this and it works! I did a small test comparing the results with Astropy and without the corrections the difference is ~648 arcsec and with the corrections the agreement is within 0.002 arcsec!

The only question I want to take comments on is where should the file be downloaded? Also, it would be nice to make libcurl an optional dependency, so people can still use the code on non-connected devices by downloading the file. I will provide the following options:

(1) Download the file to a predefined location (maybe something like $HOME/.cppephem/corrections.txt) (2) Add a compilation flag for the corrections file path. Then if the file is not present, it will be downloaded to that location. I could also add a flag '-Dnocurl' so that libcurl would be excluded, and then the user would be on the hook for downloading the corrections and placing them into the correct path.

I'm leaning towards (2). Any users with suggestions?

Jvinniec commented 5 years ago

TL;DR: Going forward, if you install the code in the standard way with no special flags (and you have libcurl installed) you will get the corrections files by default, and thus more accurate observed coordinate values. The method now also downloads TT-UT1 correction values since 1973 and predicted values into 2027.

Judging by the resounding number of replies ;) I'm going to go with option 2 above. This will mean two things:

  1. libcurl will become an optional dependency. By default, it will be included and the build will fail if it can't find a suitable libcurl. In the next release the '-Dnocurl=1' flag can be used when compiling with CMake to turn off all libcurl parts of the CECorrections class enabling the code to at least compile. However, in order to still have the feature of being able to load the corrections, see point 2.
  2. The correction files will be downloaded to a predefined location under ${CMAKE_INSTALL_PREFIX}/share/cppephem/. However, there are two ways to change where the code looks for the file.
    • Using the CMake compiler flag -DCORRFILEPATH=/your/path/to/files/ will change the default directory where the files are expected to be loaded from (or downloaded to). This hardcodes the default path into the code and cannot be changed without recompiling with a different value. To set the filename(s) at execution time see the next point.
    • Setting the file path in your code using CppEphem::SetNutationFile (nutation corrections), CppEphem::SetTtUt1HistFile (historical TT-UT1), or CppEphem::SetTtUt1PredFile (predicted future TT-UT1) will tell the code to look for the files in a location other than the default (or download the corrections to this location if libcurl is enabled).

Note: The full nutation corrections file is a few megabytes in size. It is also subject to change over time as new corrections are published. Because of this, the file is not shipped with the code, only a small sample file used for testing purposes that contains about 20 days worth of correction values. If you do not compile the code with libcurl AND you want more accurate observed coordinates, you will need to download the corrections file separately (and probably update it every few months or so) and make the code knows where to find it using one of the above methods. The same goes for the TT-UT1 corrections file.

The correction values are defined at specific MJD's. By default, the closest MJD before the queried date is used (e.g. if requesting DUT1 for MJD=55317.9, the value at MJD=55317 is returned). This is done for speed reasons. You can instead return the linearly interpolated value by calling CppEphem::CorrectionsInterp(true) at the start of your code, which will give a slightly more accurate value.

Jvinniec commented 5 years ago

Resolved by pull request #15.