diff --git a/README.md b/README.md index a559438784f686975db33f10eac8e9385f2eba86..58e1922cb270b16d73268fe3cd0cf15489d785c8 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,11 @@ the module will be installed to whichever python executable you call it from. ### Ephemeris installation -The scripts require a path to ephemeris files in order to use the -`lalpulsar.ComputeFstat` module. This can either be specified when initialising +The scripts require paths to earth and sun ephemeris files in order to use the +`lalpulsar.ComputeFstat` module. This should be automatically picked up from +the $LALPULSAR_DATADIR environment variable, defaulting to the +00-40-DE421 ephemerides or 00-19-DE421 as a backup. +Alternatively, these can either be manually specified when initialising each search (as one of the arguments), or simply by placing a file `~/.pyfstat.conf` into your home directory which looks like @@ -106,7 +109,7 @@ each search (as one of the arguments), or simply by placing a file earth_ephem = '/home/<USER>/lalsuite-install/share/lalpulsar/earth00-19-DE421.dat.gz' sun_ephem = '/home/<USER>/lalsuite-install/share/lalpulsar/sun00-19-DE421.dat.gz' ``` -here, we use the default ephemeris files provided with `lalsuite`. +Paths set in this way will take precedence over the environment variable. ### Contributors diff --git a/pyfstat/helper_functions.py b/pyfstat/helper_functions.py index 556503e347080d1ab785de5bd8048be537ed5505..9d22982ef676edceb0e7254ef0e2a2d131cb836b 100644 --- a/pyfstat/helper_functions.py +++ b/pyfstat/helper_functions.py @@ -92,6 +92,8 @@ def set_up_command_line_arguments(): def get_ephemeris_files(): """ Returns the earth_ephem and sun_ephem """ config_file = os.path.expanduser('~')+'/.pyfstat.conf' + env_var = 'LALPULSAR_DATADIR' + please = 'Please provide the ephemerides paths when initialising searches.' if os.path.isfile(config_file): d = {} with open(config_file, 'r') as f: @@ -101,11 +103,27 @@ def get_ephemeris_files(): for item in [' ', "'", '"', '\n']: v = v.replace(item, '') d[k] = v - earth_ephem = d['earth_ephem'] - sun_ephem = d['sun_ephem'] + try: + earth_ephem = d['earth_ephem'] + sun_ephem = d['sun_ephem'] + except: + logging.warning('No [earth/sun]_ephem found in '+config_file+'. '+please) + earth_ephem = None + sun_ephem = None + elif env_var in os.environ.keys(): + earth_ephem = os.path.join(os.environ[env_var],'earth00-40-DE421.dat.gz') + sun_ephem = os.path.join(os.environ[env_var],'sun00-40-DE421.dat.gz') + if not ( os.path.isfile(earth_ephem) and os.path.isfile(sun_ephem) ): + earth_ephem = os.path.join(os.environ[env_var],'earth00-19-DE421.dat.gz') + sun_ephem = os.path.join(os.environ[env_var],'sun00-19-DE421.dat.gz') + if not ( os.path.isfile(earth_ephem) and os.path.isfile(sun_ephem) ): + logging.warning('No [earth/sun]00-[19/40]-DE421 ephemerides ' + 'found in the '+os.environ[env_var]+' directory. '+please) + earth_ephem = None + sun_ephem = None else: - logging.warning('No ~/.pyfstat.conf file found please provide the ' - 'paths when initialising searches') + logging.warning('No '+config_file+' file or $'+env_var+' environment ' + 'variable found. '+please) earth_ephem = None sun_ephem = None return earth_ephem, sun_ephem