Update settings
This commit is contained in:
parent
2e044a0b76
commit
12d0c703a7
2 changed files with 149 additions and 20 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
from warnings import warn
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
"""
|
"""
|
||||||
Settings manager
|
Settings manager
|
||||||
|
@ -8,16 +11,16 @@ class Settings:
|
||||||
|
|
||||||
def __init__( self , arguments ):
|
def __init__( self , arguments ):
|
||||||
# Default configuration
|
# Default configuration
|
||||||
self.cache = None
|
self.set_cache()
|
||||||
self.filename = None
|
self.set_input()
|
||||||
self.inte_cal = None
|
self.set_inte_cal()
|
||||||
self.no_cache = False
|
self.set_no_cache()
|
||||||
self.output = 'data.fits'
|
self.set_output()
|
||||||
self.verbose = False
|
self.set_verbose()
|
||||||
self.wave_cal = None
|
self.set_wave_cal()
|
||||||
|
|
||||||
# configuration change
|
# configuration change
|
||||||
if len( arguments ) < 2:
|
if len( arguments ) < 1:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'type \'' + __file__ + ' -h\' for more information'
|
'type \'' + __file__ + ' -h\' for more information'
|
||||||
)
|
)
|
||||||
|
@ -91,29 +94,29 @@ class Settings:
|
||||||
print( self.version() )
|
print( self.version() )
|
||||||
exit()
|
exit()
|
||||||
elif argument == '--verbose':
|
elif argument == '--verbose':
|
||||||
self.verbose = True
|
self.set_verbose( True )
|
||||||
elif argument == '--no-cache':
|
elif argument == '--no-cache':
|
||||||
self.no_cache = True
|
self.set_no_cache( True )
|
||||||
elif (
|
elif (
|
||||||
len( argument ) > 8 and
|
len( argument ) > 8 and
|
||||||
argument[ : 8 ] == '--cache='
|
argument[ : 8 ] == '--cache='
|
||||||
):
|
):
|
||||||
self.cache = argument[ 8 : ]
|
self.set_cache( argument[ 8 : ] )
|
||||||
elif (
|
elif (
|
||||||
len( argument ) > 9 and
|
len( argument ) > 9 and
|
||||||
argument[ : 9 ] == '--output='
|
argument[ : 9 ] == '--output='
|
||||||
):
|
):
|
||||||
self.output = argument[ 9 : ]
|
self.set_output( argument[ 9 : ] )
|
||||||
elif (
|
elif (
|
||||||
len( argument ) > 13 and
|
len( argument ) > 13 and
|
||||||
argument[ : 13 ] == '--wavelength='
|
argument[ : 13 ] == '--wavelength='
|
||||||
):
|
):
|
||||||
self.wave_cal = argument[ 13 : ]
|
self.set_wave_cal( argument[ 13 : ] )
|
||||||
elif (
|
elif (
|
||||||
len( argument ) > 12 and
|
len( argument ) > 12 and
|
||||||
argument[ : 12 ] == '--intensity='
|
argument[ : 12 ] == '--intensity='
|
||||||
):
|
):
|
||||||
self.inte_cal = argument[ 12 : ]
|
self.set_inte_cal( argument[ 12 : ] )
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'unknown argument "' + argument + \
|
'unknown argument "' + argument + \
|
||||||
|
@ -121,15 +124,127 @@ class Settings:
|
||||||
'for more information'
|
'for more information'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.filename = argument
|
self.set_input( argument )
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
if self.filename == None:
|
if self.input == None:
|
||||||
raise Exception( 'filename should be given' )
|
raise Exception( 'input should be given' )
|
||||||
|
|
||||||
|
def set_cache( self , cache = None ):
|
||||||
|
"""
|
||||||
|
Setter for cache (None or path)
|
||||||
|
"""
|
||||||
|
if isinstance( cache , str ):
|
||||||
|
self.cache = Path( cache )
|
||||||
|
elif isinstance( cache , Path ):
|
||||||
|
self.cache = cache
|
||||||
|
elif cache == None:
|
||||||
|
self.cache = cache
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'cache should be a path'
|
||||||
|
)
|
||||||
|
def set_input( self , input = None ):
|
||||||
|
"""
|
||||||
|
Setter for input file (None or path)
|
||||||
|
"""
|
||||||
|
if isinstance( input , str ):
|
||||||
|
self.input = Path( input )
|
||||||
|
elif isinstance( input , Path ):
|
||||||
|
self.input = input
|
||||||
|
elif input == None:
|
||||||
|
self.input = input
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'input should be a path'
|
||||||
|
)
|
||||||
|
if self.input != None and not self.input.is_file():
|
||||||
|
raise IOError(
|
||||||
|
'could not open ' + str( self.input )
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_inte_cal( self , intensity_calibration = None ):
|
||||||
|
"""
|
||||||
|
Setter for intensity calibration (None or path)
|
||||||
|
"""
|
||||||
|
if isinstance( intensity_calibration , str ):
|
||||||
|
self.inte_cal = Path( intensity_calibration )
|
||||||
|
elif isinstance( intensity_calibration , Path ):
|
||||||
|
self.inte_cal = intensity_calibration
|
||||||
|
elif intensity_calibration == None:
|
||||||
|
self.inte_cal = intensity_calibration
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'intensity calibration should be a path'
|
||||||
|
)
|
||||||
|
if self.inte_cal != None and not self.inte_cal.is_file():
|
||||||
|
raise IOError(
|
||||||
|
'could not open ' + str( self.inte_cal )
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_no_cache( self , no_cache = False ):
|
||||||
|
"""
|
||||||
|
Setter for no_cache (bool)
|
||||||
|
"""
|
||||||
|
if isinstance( no_cache , bool ):
|
||||||
|
self.no_cache = no_cache
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'no_cache option should be a boolean'
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_output( self , output = 'data.fits' ):
|
||||||
|
"""
|
||||||
|
Setter for output (path)
|
||||||
|
"""
|
||||||
|
if isinstance( output , str ):
|
||||||
|
self.output = Path( output )
|
||||||
|
elif isinstance( output , Path ):
|
||||||
|
self.output = output
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'output should be a path'
|
||||||
|
)
|
||||||
|
if self.output.is_file():
|
||||||
|
warn(
|
||||||
|
str( self.output ) + ' already exists, it will be ' +
|
||||||
|
'overwritten',
|
||||||
|
UserWarning ,
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_verbose( self , verbose = False ):
|
||||||
|
"""
|
||||||
|
Setter for verbosity flag (bool)
|
||||||
|
"""
|
||||||
|
if isinstance( verbose , bool ):
|
||||||
|
self.verbose = verbose
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'verbose should be a boolean'
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_wave_cal( self , wavelength_calibration = None ):
|
||||||
|
"""
|
||||||
|
Setter for wavelength calibration (None or path)
|
||||||
|
"""
|
||||||
|
if isinstance( wavelength_calibration , str ):
|
||||||
|
self.wave_cal = Path( wavelength_calibration )
|
||||||
|
elif isinstance( wavelength_calibration , Path ):
|
||||||
|
self.wave_cal = wavelength_calibration
|
||||||
|
elif wavelength_calibration == None:
|
||||||
|
self.wave_cal = wavelength_calibration
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'wavelength calibration should be a path'
|
||||||
|
)
|
||||||
|
if self.wave_cal != None and not self.wave_cal.is_file():
|
||||||
|
raise IOError(
|
||||||
|
'could not open ' + str( self.wave_cal )
|
||||||
|
)
|
||||||
|
|
||||||
def help( self ):
|
def help( self ):
|
||||||
return '\
|
return '\
|
||||||
naroo_reader [options...] filename\
|
naroo_reader [options...] input\
|
||||||
\n -w wavelength wavelength calibration file, default to None.\
|
\n -w wavelength wavelength calibration file, default to None.\
|
||||||
\n None means no wavelength interpolation\
|
\n None means no wavelength interpolation\
|
||||||
\n -i intensity intensity calibration file, default to None.\
|
\n -i intensity intensity calibration file, default to None.\
|
||||||
|
@ -145,3 +260,15 @@ naroo_reader [options...] filename\
|
||||||
\n -V --version show version number and quit\
|
\n -V --version show version number and quit\
|
||||||
\n -v --verbose show more information to help debugging\
|
\n -v --verbose show more information to help debugging\
|
||||||
'
|
'
|
||||||
|
|
||||||
|
def __str__( self ):
|
||||||
|
return '\
|
||||||
|
current settings:\
|
||||||
|
\n cache: ' + str( self.cache ) + '\
|
||||||
|
\n input: ' + str( self.input ) + '\
|
||||||
|
\n intensity calibration: ' + str( self.inte_cal ) + '\
|
||||||
|
\n no cache flag: ' + str( self.no_cache ) + '\
|
||||||
|
\n output: ' + str( self.output ) + '\
|
||||||
|
\n verbose flag: ' + str( self.verbose ) + '\
|
||||||
|
\n wavelength calibration: ' + str( self.wave_cal ) + '\
|
||||||
|
'
|
||||||
|
|
6
main.py
6
main.py
|
@ -5,9 +5,11 @@ from classes.utils.settings import Settings
|
||||||
from astropy.io.fits import open
|
from astropy.io.fits import open
|
||||||
from sys import argv as arguments
|
from sys import argv as arguments
|
||||||
|
|
||||||
settings = Settings( arguments )
|
settings = Settings( arguments[ 1 : ] )
|
||||||
|
|
||||||
hdul = open( settings.filename )
|
print( settings )
|
||||||
|
|
||||||
|
hdul = open( settings.input )
|
||||||
plate = Plate( hdul[0].data )
|
plate = Plate( hdul[0].data )
|
||||||
head = hdul[0].header
|
head = hdul[0].header
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue