-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5a6f86
commit 9b90990
Showing
374 changed files
with
114,644 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include README.md | ||
include LICENSE | ||
include MANIFEST.in | ||
recursive-include dfistpy/ * | ||
recursive-include dfitspy/docs/ * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# dfitspy_RSECon24 | ||
# dfitspy_RSECon24 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
__version__ = '20.7.0' | ||
__place__ = 'ESO Paranal observatory' | ||
__credits__ = "Romain Thomas" | ||
__license__ = "GNU GPL v3" | ||
__maintainer__ = "Romain Thomas" | ||
__email__ = "the.spartan.proj@gmail.com" | ||
__status__ = "released" | ||
__website__ = "https://astrom-tom.github.io/dfitspy/build/html/index.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
__all__ = ["get_files", "get_keys", "test", "read_fitsfile", "dfitsort", \ | ||
"keywords_in_file", "get_all_values", "dfitsort_view", "keywords_view","version"] | ||
|
||
|
||
from dfitspy.get_files_and_keys import get_files, get_keys | ||
from dfitspy.readfits import read_fitsfile, get_all_keyword, keywords_in_file, dfitsort | ||
from dfitspy.display import dfitsort_view, keywords_view | ||
from dfitspy.tests import test | ||
from dfitspy.__info__ import __version__ as version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#!/usr/bin/./python | ||
# -*- coding: utf-8 -*- | ||
|
||
''' | ||
---dfitspy--- | ||
dfitspy is a program aimed at reproducing the dfits program in python. | ||
the functions can be used inside another program or it can also be called | ||
as an executable | ||
usage: dfitspy -f FILE.fits -k OBJECT | ||
@place: ESO - La Silla - Paranal Observatory | ||
@author(s): Romain Thomas | ||
@year(s): ex 2018 | ||
@First version: 19.9-0 | ||
@Current version: 19.9-0 | ||
@Telescope(s): ALL | ||
@Instrument(s): ALL | ||
@Valid for SciOpsPy: v0.1-b | ||
@Documentation url: | ||
@Last SciOps review [date + name]: 18-09-2018 - Romain Thomas | ||
@Usage: dfitspy FILE.fits HEADER_KEY_WORD, diftspy --help for more options | ||
@Licence: GPL | ||
@Testable: Yes | ||
@Test data place (if any required): inside the package | ||
''' | ||
|
||
|
||
###Python standard library | ||
import sys | ||
import os | ||
from subprocess import call | ||
import datetime | ||
import socket | ||
import time | ||
|
||
|
||
###local imports | ||
from . import __info__ as info | ||
from . import cli | ||
from . import display as dp | ||
from . import readfits | ||
from . import get_files_and_keys as get | ||
from . import tests | ||
|
||
def main(): | ||
''' | ||
This is the main function of the program. | ||
''' | ||
###first we load the command line interface | ||
args = cli.command_line(sys.argv[1:]) | ||
|
||
###here we check if at least one argument was given: | ||
if not args.docs and args.file is None and args.grep is None and \ | ||
args.key is None and not args.list and not args.test: | ||
print('\033[1m[DFITSPY Error]> no argument passed ...exit\033[0;0m') | ||
sys.exit() | ||
|
||
if args.docs is True: | ||
##check if there is any internet connection | ||
try: | ||
socket.setdefaulttimeout(3) | ||
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("8.8.8.8", 53)) | ||
url = info.__website__ | ||
##if not we use the local documentation distributed along the software | ||
except: | ||
print('No internet connection detected, open local documentation') | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
url = os.path.join(dir_path, 'docs/build/html/index.html') | ||
|
||
for i in ['firefox', 'falkon', 'open', 'chromium', 'google-chrome']: | ||
##we check if the command exist in the system | ||
exist = call(['which', i]) | ||
if exist == 0: | ||
if i == 'firefox': | ||
call([i, '--no-remote', url]) | ||
sys.exit() | ||
##if it does then we use it to load the documentation | ||
else: | ||
call([i, url]) | ||
##and we stop the loop | ||
sys.exit() | ||
break | ||
|
||
if args.test: | ||
tests.test() | ||
###exit code | ||
sys.exit() | ||
|
||
###get all the files | ||
list_files = get.get_files(args.file) | ||
|
||
if list_files == []: | ||
print('\n\033[1m[DFITSPY Error]>Invalid file name or no fits file found \033[0;0m') | ||
sys.exit() | ||
|
||
if args.list: | ||
###get all keywords | ||
all_keywords = readfits.get_all_keyword(list_files[0], int(args.HDU)) | ||
###display them | ||
print('\n\033[1m[DFITSPY INFO]>keywords in %s \033[0;0m'%\ | ||
os.path.basename(list_files[0])) | ||
dp.keywords_view(all_keywords) | ||
sys.exit() | ||
|
||
##display number of files | ||
print('\n\033[1m[DFITSPY INFO]> Current directory: %s \033[0;0m'%os.getcwd()) | ||
print('\033[1m[DFITSPY INFO]> %s fits files will be considered \033[0;0m'%len(list_files)) | ||
print('\033[1m[DFITSPY INFO]> We look in HDU %s \033[0;0m\n'%args.HDU) | ||
|
||
###get greeping from command line | ||
if args.grep: | ||
grep = args.grep | ||
else: | ||
grep = False | ||
|
||
if not args.key: | ||
print('\n\033[1m[DFISTPY Error]>no keywords given...exit... \033[0;0m') | ||
sys.exit() | ||
else: | ||
##get all keywords | ||
list_keys = get.get_keys(args.key) | ||
|
||
##get all values for each keys and each files | ||
allvalues = readfits.dfitsort(list_files, list_keys, args.exact, grep, int(args.HDU)) | ||
|
||
##display them in terminal | ||
dp.dfitsort_view(allvalues) | ||
|
||
print('\n\033[1m[DFITSPY INFO]> %s files used in output \033[0;0m'%len(allvalues)) | ||
if args.save: | ||
###if we want to save the list of files into a file: | ||
with open('dfitspy_file_list.txt', 'w') as finalfile: | ||
finalfile.write('##file produced by dfitspy %s\n'%(datetime.datetime.now())) | ||
finalfile.write('##Current directory: %s\n'%os.getcwd()) | ||
for i in allvalues.keys(): | ||
finalfile.write('%s\n'%i) | ||
if os.path.isfile('dfitspy_file_list.txt'): | ||
print('\033[1m[DFITSPY INFO]> File saved: dfitspy_file_list.txt \033[0;0m') | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
''' | ||
---dfitspy--- | ||
dfitspy is a program aimed at reproducing the dfits program in python. | ||
the functions can be used inside another program or it can also be called | ||
as an executable | ||
This file organises the command line interface (and nunit test it) | ||
@place: ESO - La Silla - Paranal Observatory | ||
@author(s): Romain Thomas | ||
@year(s): 2018 | ||
@First version: 18.09-0 | ||
@Current version: 20.7.1 | ||
@Telescope(s): ALL | ||
@Instrument(s): ALL | ||
@Valid for SciOpsPy: v0.1-b | ||
@Documentation url: | ||
@Last SciOps review [date + name]: 18-09-2018 - Romain Thomas | ||
@Usage: inside another code (dfitspy) | ||
@Licence: GPL | ||
@Testable: Yes | ||
@Test data place (if any required): N.A. | ||
''' | ||
|
||
|
||
##standard library | ||
import argparse | ||
|
||
##testing | ||
import unittest | ||
|
||
#local import | ||
from . import __info__ as info | ||
|
||
|
||
def command_line(args): | ||
''' | ||
This function defines the command line interface of the program. | ||
It is used only if dfitspy is used as an executable | ||
Parameters | ||
----------- | ||
None | ||
Returns | ||
------- | ||
args Namespace with arguments | ||
''' | ||
|
||
##create parser object | ||
parser = argparse.ArgumentParser(description='dfitspy: dfits|fitsort in python, version %s, \ | ||
Licence: GPL'%(info.__version__)) | ||
|
||
mand = parser.add_argument_group("Mandatory arguments if you want to dfitsort your files") | ||
mand.add_argument('-file', nargs='*', help='a file, a list of file separated by coma,\ | ||
*.fits is accepted, * as well, test* as well, testdir/test* as well') | ||
mand.add_argument('-key', help='Header keyword or list of header keywords\ | ||
(separated by coma)') | ||
|
||
|
||
###optional arguments | ||
#parser.add_argument('--dir', help='Directory where we search for files. \ | ||
# If none given, the default directory is the one from where dfitspy \ | ||
# is started.', default=os.getcwd()) | ||
opt = parser.add_argument_group("Optional arguments") | ||
opt.add_argument('--list', help='List all keywords in a given file \ | ||
(if a list of file is given the first one is used)', action='store_true') | ||
opt.add_argument('--grep', help='Restrain the files to the one with a given \ | ||
value of a given parameter. It can be used multiple times with different values', \ | ||
type=str, action='append') | ||
opt.add_argument('--exact', '-e', help='Consider only exact matches for keywords', | ||
action='store_true') | ||
opt.add_argument('--HDU', '-H', help='HDU extension, default is 0 (primary header)', type=int, default=0) | ||
opt.add_argument('--save', help='Save the list of files into an ascii file',\ | ||
action='store_true') | ||
opt.add_argument('--test', help='Start the testing of the program', \ | ||
action='store_true') | ||
opt.add_argument('--version', help='Display the version of the program', \ | ||
action='version', version=info.__version__) | ||
opt.add_argument('--docs', help='Diplay the online or local documentation program', \ | ||
action='store_true') | ||
|
||
##create a group of arguments that are mandatory | ||
return parser.parse_args(args) | ||
|
||
|
||
|
||
class Interfacetest(unittest.TestCase): | ||
''' | ||
Class that define the test for the command line interface | ||
''' | ||
def test_cli(self): | ||
''' | ||
This method tests the command line interface | ||
The principle is that we send some argument configuration | ||
and see what the interface is giving back | ||
''' | ||
options = command_line(['--grep', 'testobject',\ | ||
'--list', '--test']) | ||
self.assertEqual(options.grep, ['testobject']) | ||
self.assertEqual(options.list, True) | ||
self.assertEqual(options.test, True) | ||
|
||
options2 = command_line(['-file', '/home/file', \ | ||
'-key', 'testkey']) | ||
self.assertEqual(options2.key, 'testkey') | ||
self.assertEqual(options2.file, ['/home/file']) |
Oops, something went wrong.