Closed Evidlo closed 2 years ago
Hi @Evidlo, thanks for raising this.
Redirecting stderr to subprocess.PIPE was intended to help convert a uvspec error to a python exception - https://github.com/EdGrrr/pyLRT/blob/master/pyLRT/RadTran.py#L77-L87 checks stderr for any lines that indicate an error, then converts this to a python exception. This setting should not depend on the 'verbose' argument though, so I suggest removing the if statement at https://github.com/EdGrrr/pyLRT/blob/master/pyLRT/RadTran.py#L64, sending all output to stderr to be parsed.
This has the effect of silencing uvspec warnings though (which I didn't realise). To address this, I suggest an extra loop that looks for warnings in the uvspec output then prints them. This can be silenced with the 'quiet' option for RadTran.run(). This would be inserted at L77.
# Check uvspec output for errors/warnings
if not quiet:
print_flag = False
for line in io.StringIO(process.stderr):
if line.startswith('*** Warning'):
# Some uvspec warnings start with three stars
# These have three stars for every line
print(line.strip())
elif line.startswith('*****'):
# Many uvspec warnings are in a star box
print(line.strip())
print_flag = not(print_flag)
elif print_flag:
# Print line if we are within a star box
print(line.strip())
I can see the naming of the 'verbose' option here can be confusing - it comes from the libradtran naming, so the 'verbose' argument shouldn't affect the amount of output printed to screen, but it controls whether we try to parse the uvspec verbose output (which has optical depths, concentrations etc.). I am not sure whether it is a good idea to change this though, as we might want to keep the link to the libradtran name?
Commit https://github.com/EdGrrr/pyLRT/commit/0d0ae0f759278f14cd7d6f701e4c74576dc90bce should include these changes.
As a test, the first two of these calls should return a warning, the third should not.
from pyLRT import RadTran, get_lrt_folder
LIBRADTRAN_FOLDER = get_lrt_folder()
slrt = RadTran(LIBRADTRAN_FOLDER)
slrt.options['rte_solver'] = 'disort'
slrt.options['source'] = 'solar'
slrt.options['wavelength'] = '200 2600'
slrt.options['output_user'] = 'lambda eglo eup edn edir'
slrt.options['zout'] = '0 5 TOA'
slrt.options['albedo'] = '0'
slrt.options['umu'] = '-1.0 1.0'
slrt.options['quiet'] = ''
slrt.options['sza'] = '0'
##############
# Run the RT #
##############
print('Verbose run - prints warning')
sdata, sverb = slrt.run(verbose=True)
print('')
print('Non-verbose run - prints warning')
sdata = slrt.run(verbose=False)
print('')
slrt.options['wavelength'] = '250 2600'
print('Verbose run - doesn\'t print warning')
sdata, sverb = slrt.run(verbose=True)
Which reminds me #4
Thanks for the fix!
I noticed that in https://github.com/EdGrrr/pyLRT/blob/master/pyLRT/RadTran.py#L64-L70, calling
run(verbose=True)
sends stderr tosubprocess.PIPE
. Doesn't this have the effect of turning off error messages from radtran? This seems to be my experience in callingrun()
.