Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minimum exposure not being honored if higher than camera minimum #1064

Merged
merged 8 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions indi_allsky/allsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(self):

self.exposure_v = Value('f', -1.0) # this must be -1.0 to indicate unset
self.exposure_min_v = Value('f', -1.0)
self.exposure_min_day_v = Value('f', -1.0)
self.exposure_max_v = Value('f', -1.0)
self.gain_v = Value('i', -1) # value set in CCD config
self.bin_v = Value('i', 1) # set 1 for sane default
Expand Down Expand Up @@ -300,6 +301,7 @@ def _startCaptureWorker(self):
self.dec_v,
self.exposure_v,
self.exposure_min_v,
self.exposure_min_day_v,
self.exposure_max_v,
self.gain_v,
self.bin_v,
Expand Down Expand Up @@ -368,6 +370,7 @@ def _startImageWorker(self):
self.dec_v,
self.exposure_v,
self.exposure_min_v,
self.exposure_min_day_v,
self.exposure_max_v,
self.gain_v,
self.bin_v,
Expand Down
31 changes: 28 additions & 3 deletions indi_allsky/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(
dec_v,
exposure_v,
exposure_min_v,
exposure_min_day_v,
exposure_max_v,
gain_v,
bin_v,
Expand Down Expand Up @@ -96,6 +97,7 @@ def __init__(

self.exposure_v = exposure_v
self.exposure_min_v = exposure_min_v
self.exposure_min_day_v = exposure_min_day_v
self.exposure_max_v = exposure_max_v
self.gain_v = gain_v
self.bin_v = bin_v
Expand Down Expand Up @@ -669,21 +671,43 @@ def _initialize(self):

# Some CCD drivers will not accept their stated minimum exposure.
# There might be some python -> C floating point conversion problem causing this.
ccd_min_exp = ccd_min_exp + 0.00000001
ccd_min_exp += 0.00000001


if not self.config.get('CCD_EXPOSURE_MIN_DAY'):
with self.exposure_min_day_v.get_lock():
self.exposure_min_day_v.value = ccd_min_exp
elif self.config.get('CCD_EXPOSURE_MIN_DAY') > ccd_min_exp:
with self.exposure_min_day_v.get_lock():
self.exposure_min_day_v.value = float(self.config.get('CCD_EXPOSURE_MIN_DAY'))
elif self.config.get('CCD_EXPOSURE_MIN_DAY') < ccd_min_exp:
logger.warning(
'Minimum exposure (day) %0.8f too low, increasing to %0.8f',
self.config.get('CCD_EXPOSURE_MIN_DAY'),
ccd_min_exp,
)
with self.exposure_min_day_v.get_lock():
self.exposure_min_day_v.value = ccd_min_exp

logger.info('Minimum CCD exposure: %0.8f (day)', self.exposure_min_day_v.value)


if not self.config.get('CCD_EXPOSURE_MIN'):
with self.exposure_min_v.get_lock():
self.exposure_min_v.value = ccd_min_exp
elif self.config.get('CCD_EXPOSURE_MIN') > ccd_min_exp:
with self.exposure_min_v.get_lock():
self.exposure_min_v.value = float(self.config.get('CCD_EXPOSURE_MIN'))
elif self.config.get('CCD_EXPOSURE_MIN') < ccd_min_exp:
logger.warning(
'Minimum exposure %0.8f too low, increasing to %0.8f',
'Minimum exposure (night) %0.8f too low, increasing to %0.8f',
self.config.get('CCD_EXPOSURE_MIN'),
ccd_min_exp,
)
with self.exposure_min_v.get_lock():
self.exposure_min_v.value = ccd_min_exp

logger.info('Minimum CCD exposure: %0.8f', self.exposure_min_v.value)
logger.info('Minimum CCD exposure: %0.8f (night)', self.exposure_min_v.value)


# set maximum exposure
Expand Down Expand Up @@ -916,6 +940,7 @@ def reload_handler(self):
)
self.config['CCD_EXPOSURE_MIN'] = ccd_min_exp


logger.info('Minimum CCD exposure: %0.8f', self.config['CCD_EXPOSURE_MIN'])


Expand Down
1 change: 1 addition & 0 deletions indi_allsky/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class IndiAllSkyConfigBase(object):
"CCD_EXPOSURE_MAX" : 15.00000,
"CCD_EXPOSURE_DEF" : 0.0,
"CCD_EXPOSURE_MIN" : 0.0,
"CCD_EXPOSURE_MIN_DAY" : 0.0,
"CCD_BIT_DEPTH" : 0, # 0 is auto
"EXPOSURE_PERIOD" : 15.00000,
"EXPOSURE_PERIOD_DAY" : 15.00000,
Expand Down
3 changes: 2 additions & 1 deletion indi_allsky/flask/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2165,7 +2165,8 @@ class IndiAllskyConfigForm(FlaskForm):
CCD_CONFIG__DAY__BINNING = IntegerField('Daytime Bin Mode', validators=[DataRequired(), ccd_BINNING_validator])
CCD_EXPOSURE_MAX = FloatField('Max Exposure', validators=[DataRequired(), CCD_EXPOSURE_MAX_validator])
CCD_EXPOSURE_DEF = FloatField('Default Exposure', validators=[CCD_EXPOSURE_DEF_validator])
CCD_EXPOSURE_MIN = FloatField('Min Exposure', validators=[CCD_EXPOSURE_MIN_validator])
CCD_EXPOSURE_MIN = FloatField('Min Exposure (Night)', validators=[CCD_EXPOSURE_MIN_validator])
CCD_EXPOSURE_MIN_DAY = FloatField('Min Exposure (Day)', validators=[CCD_EXPOSURE_MIN_validator])
CCD_BIT_DEPTH = SelectField('Camera Bit Depth', choices=CCD_BIT_DEPTH_choices, validators=[CCD_BIT_DEPTH_validator])
EXPOSURE_PERIOD = FloatField('Exposure Period (Night)', validators=[DataRequired(), EXPOSURE_PERIOD_validator])
EXPOSURE_PERIOD_DAY = FloatField('Exposure Period (Day)', validators=[DataRequired(), EXPOSURE_PERIOD_DAY_validator])
Expand Down
12 changes: 12 additions & 0 deletions indi_allsky/flask/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
</div>
<div class="col-sm-8">0 = auto</div>
</div>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.CCD_EXPOSURE_MIN.label(class='col-form-label') }}
Expand All @@ -200,6 +201,16 @@
</div>
<div class="col-sm-8">0 = auto</div>
</div>
<div class="form-group row">
<div class="col-sm-2">
{{ form_config.CCD_EXPOSURE_MIN_DAY.label(class='col-form-label') }}
</div>
<div class="col-sm-2">
{{ form_config.CCD_EXPOSURE_MIN_DAY(class='form-control bg-secondary') }}
<div id="CCD_EXPOSURE_MIN_DAY-error" class="invalid-feedback text-danger" style="display: none;"></div>
</div>
<div class="col-sm-8">0 = auto</div>
</div>

<div class="form-group row">
<div class="col-sm-2">
Expand Down Expand Up @@ -3450,6 +3461,7 @@
'CCD_EXPOSURE_MAX',
'CCD_EXPOSURE_DEF',
'CCD_EXPOSURE_MIN',
'CCD_EXPOSURE_MIN_DAY',
'CCD_BIT_DEPTH',
'EXPOSURE_PERIOD',
'EXPOSURE_PERIOD_DAY',
Expand Down
2 changes: 2 additions & 0 deletions indi_allsky/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ def get_context(self):
'CCD_EXPOSURE_MAX' : self.indi_allsky_config.get('CCD_EXPOSURE_MAX', 15.0),
'CCD_EXPOSURE_DEF' : '{0:.6f}'.format(self.indi_allsky_config.get('CCD_EXPOSURE_DEF', 0.0)), # force 6 digits of precision
'CCD_EXPOSURE_MIN' : '{0:.6f}'.format(self.indi_allsky_config.get('CCD_EXPOSURE_MIN', 0.0)),
'CCD_EXPOSURE_MIN_DAY' : '{0:.6f}'.format(self.indi_allsky_config.get('CCD_EXPOSURE_MIN_DAY', 0.0)),
'CCD_BIT_DEPTH' : str(self.indi_allsky_config.get('CCD_BIT_DEPTH', 0)), # string in form, int in config
'EXPOSURE_PERIOD' : self.indi_allsky_config.get('EXPOSURE_PERIOD', 15.0),
'EXPOSURE_PERIOD_DAY' : self.indi_allsky_config.get('EXPOSURE_PERIOD_DAY', 15.0),
Expand Down Expand Up @@ -1417,6 +1418,7 @@ def dispatch_request(self):
self.indi_allsky_config['CCD_EXPOSURE_MAX'] = float(request.json['CCD_EXPOSURE_MAX'])
self.indi_allsky_config['CCD_EXPOSURE_DEF'] = float(request.json['CCD_EXPOSURE_DEF'])
self.indi_allsky_config['CCD_EXPOSURE_MIN'] = float(request.json['CCD_EXPOSURE_MIN'])
self.indi_allsky_config['CCD_EXPOSURE_MIN_DAY'] = float(request.json['CCD_EXPOSURE_MIN_DAY'])
self.indi_allsky_config['CCD_BIT_DEPTH'] = int(request.json['CCD_BIT_DEPTH'])
self.indi_allsky_config['EXPOSURE_PERIOD'] = float(request.json['EXPOSURE_PERIOD'])
self.indi_allsky_config['EXPOSURE_PERIOD_DAY'] = float(request.json['EXPOSURE_PERIOD_DAY'])
Expand Down
12 changes: 8 additions & 4 deletions indi_allsky/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(
dec_v,
exposure_v,
exposure_min_v,
exposure_min_day_v,
exposure_max_v,
gain_v,
bin_v,
Expand All @@ -103,6 +104,7 @@ def __init__(

self.exposure_v = exposure_v
self.exposure_min_v = exposure_min_v
self.exposure_min_day_v = exposure_min_day_v
self.exposure_max_v = exposure_max_v
self.gain_v = gain_v
self.bin_v = bin_v
Expand Down Expand Up @@ -1388,8 +1390,10 @@ def calculate_exposure(self, adu, exposure):

if self.night_v.value:
target_adu = self.config['TARGET_ADU']
exposure_min = self.exposure_min_v.value
else:
target_adu = self.config['TARGET_ADU_DAY']
exposure_min = self.exposure_min_day_v.value


# Brightness when the sun is in view (very short exposures) can change drastically when clouds pass through the view
Expand Down Expand Up @@ -1420,7 +1424,7 @@ def calculate_exposure(self, adu, exposure):


if not self.target_adu_found:
self.recalculate_exposure(exposure, adu, target_adu, target_adu_min, target_adu_max, exp_scale_factor)
self.recalculate_exposure(exposure, adu, target_adu, target_adu_min, target_adu_max, exposure_min, exp_scale_factor)
return adu, 0.0


Expand Down Expand Up @@ -1451,7 +1455,7 @@ def calculate_exposure(self, adu, exposure):
return adu, adu_average


def recalculate_exposure(self, exposure, adu, target_adu, target_adu_min, target_adu_max, exp_scale_factor):
def recalculate_exposure(self, exposure, adu, target_adu, target_adu_min, target_adu_max, exposure_min, exp_scale_factor):

# Until we reach a good starting point, do not calculate a moving average
if adu <= target_adu_max and adu >= target_adu_min:
Expand All @@ -1472,8 +1476,8 @@ def recalculate_exposure(self, exposure, adu, target_adu, target_adu_min, target


# Do not exceed the limits
if new_exposure < self.exposure_min_v.value:
new_exposure = float(self.exposure_min_v.value)
if new_exposure < exposure_min:
new_exposure = float(exposure_min)
elif new_exposure > self.exposure_max_v.value:
new_exposure = float(self.exposure_max_v.value)

Expand Down
46 changes: 44 additions & 2 deletions misc/support_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ PATH=/usr/local/bin:/usr/bin:/bin
export PATH


function catch_error() {
echo
echo
echo "###############"
echo "### ERROR ###"
echo "###############"
echo
echo "The script exited abnormally, please try to run again..."
echo
echo
exit 1
}
trap catch_error ERR

function catch_sigint() {
echo
echo
echo "###############"
echo "### ERROR ###"
echo "###############"
echo
echo "The script was interrupted, please run the script again to finish..."
echo
echo
exit 1
}
trap catch_sigint SIGINT


DISTRO_NAME=$(lsb_release -s -i)
DISTRO_RELEASE=$(lsb_release -s -r)
CPU_ARCH=$(uname -m)
Expand All @@ -16,6 +45,13 @@ CPU_TOTAL=$(grep -c "^proc" /proc/cpuinfo)
MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk "{print \$2}")


if [ -f "/proc/device-tree/model" ]; then
SYSTEM_MODEL=$(cat /proc/device-tree/model)
else
SYSTEM_MODEL="Generic PC"
fi


if which indiserver >/dev/null 2>&1; then
INDISERVER=$(which indiserver)
else
Expand All @@ -41,6 +77,8 @@ echo
echo "CPUs: $CPU_TOTAL"
echo "Memory: $MEM_TOTAL kB"
echo
echo "System: $SYSTEM_MODEL"
echo
echo "Uptime"
uptime
echo
Expand All @@ -66,7 +104,7 @@ echo

echo "Process info"
# shellcheck disable=SC2009
ps auxwww | grep indi | grep -v grep
ps auxwww | grep indi | grep -v grep || true
echo

echo "USB info"
Expand Down Expand Up @@ -112,7 +150,11 @@ dpkg -l | grep libcamera || true
echo

echo "libcamera cameras"
if which libcamera-hello >/dev/null 2>&1; then
if which rpicam-hello >/dev/null 2>&1; then
echo "rpicam-hello: $(which rpicam-hello)"
rpicam-hello --list-cameras || true
echo
elif which libcamera-hello >/dev/null 2>&1; then
echo "libcamera-hello: $(which libcamera-hello)"
libcamera-hello --list-cameras || true
echo
Expand Down
10 changes: 9 additions & 1 deletion misc/upgrade_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export PATH
function catch_error() {
echo
echo
echo "The script exited abnormally, please try to run again..."
echo "###############"
echo "### ERROR ###"
echo "###############"
echo
echo "The setup script exited abnormally, please try to run again..."
echo
echo
exit 1
Expand All @@ -20,6 +24,10 @@ trap catch_error ERR
function catch_sigint() {
echo
echo
echo "###############"
echo "### ERROR ###"
echo "###############"
echo
echo "The setup script was interrupted, please run the script again to finish..."
echo
echo
Expand Down
11 changes: 9 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ ASTROBERRY="false"
function catch_error() {
echo
echo
echo "The script exited abnormally, please try to run again..."
echo "###############"
echo "### ERROR ###"
echo "###############"
echo
echo "The setup script exited abnormally, please try to run again..."
echo
echo
exit 1
Expand All @@ -101,8 +105,11 @@ trap catch_error ERR
function catch_sigint() {
echo
echo
echo "The setup script was interrupted, please run the script again to finish..."
echo "###############"
echo "### ERROR ###"
echo "###############"
echo
echo "The setup script was interrupted, please run the script again to finish..."
echo
exit 1
}
Expand Down