Skip to content

Commit

Permalink
100 char limit (#159)
Browse files Browse the repository at this point in the history
* Remove some dependencies that aren't needed

* Fixing more dependencies

* Updating version number for release

* Version 0.5.1 release

* Change hard-coded version number (also added #154 to deal with in future)

* 100 char limit applied directly to develop
  • Loading branch information
wtgee authored and jamessynge committed Dec 2, 2017
1 parent ae6251d commit 5d13d60
Show file tree
Hide file tree
Showing 32 changed files with 284 additions and 94 deletions.
10 changes: 7 additions & 3 deletions pocs/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def __init__(self,
else:
# Should have been passed either a Focuser instance or a dict with Focuser
# configuration. Got something else...
self.logger.error("Expected either a Focuser instance or dict, got {}".format(focuser))
self.logger.error(
"Expected either a Focuser instance or dict, got {}".format(focuser))
self.focuser = None
else:
self.focuser = None
Expand Down Expand Up @@ -265,7 +266,9 @@ def command(self, cmd):
self._proc = subprocess.Popen(
run_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=False)
except OSError as e:
raise error.InvalidCommand("Can't send command to gphoto2. {} \t {}".format(e, run_cmd))
raise error.InvalidCommand(
"Can't send command to gphoto2. {} \t {}".format(
e, run_cmd))
except ValueError as e:
raise error.InvalidCommand("Bad parameters to gphoto2. {} \t {}".format(e, run_cmd))
except Exception as e:
Expand Down Expand Up @@ -379,7 +382,8 @@ def parse_config(self, lines):
line = ' {}'.format(line)
elif IsChoice:
if int(IsChoice.group(1)) == 0:
line = ' Choices:\n {}: {:d}'.format(IsChoice.group(2), int(IsChoice.group(1)))
line = ' Choices:\n {}: {:d}'.format(
IsChoice.group(2), int(IsChoice.group(1)))
else:
line = ' {}: {:d}'.format(IsChoice.group(2), int(IsChoice.group(1)))
elif IsPrintable:
Expand Down
4 changes: 3 additions & 1 deletion pocs/camera/canon_gphoto2.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def take_exposure(self, seconds=1.0 * u.second, filename=None):
"""
assert filename is not None, self.logger.warning("Must pass filename for take_exposure")

self.logger.debug('Taking {} second exposure on {}: {}'.format(seconds, self.name, filename))
self.logger.debug(
'Taking {} second exposure on {}: {}'.format(
seconds, self.name, filename))

if isinstance(seconds, u.Quantity):
seconds = seconds.value
Expand Down
4 changes: 3 additions & 1 deletion pocs/camera/sbig.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def take_exposure(self, seconds=1.0 * u.second, filename=None, dark=False, block

assert filename is not None, self.logger.warning("Must pass filename for take_exposure")

self.logger.debug('Taking {} second exposure on {}: {}'.format(seconds, self.name, filename))
self.logger.debug(
'Taking {} second exposure on {}: {}'.format(
seconds, self.name, filename))
exposure_event = Event()
self._SBIGDriver.take_exposure(self._handle, seconds, filename, exposure_event, dark)

Expand Down
70 changes: 53 additions & 17 deletions pocs/camera/sbigudrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def __init__(self, library_path=False, *args, **kwargs):
# Reopen driver ready for next command
self._send_command('CC_OPEN_DRIVER')

self.logger.info('\t\t\t SBIGDriver initialised: found {} cameras'.format(self._camera_info.camerasFound))
self.logger.info(
'\t\t\t SBIGDriver initialised: found {} cameras'.format(
self._camera_info.camerasFound))

def __del__(self):
self.logger.debug('Closing SBIGUDrv driver')
Expand Down Expand Up @@ -147,7 +149,8 @@ def assign_handle(self, serial=None):
try:
index = self._handle_assigned.index(False)
except ValueError:
# All handles already assigned, must be trying to intialising more cameras than are connected.
# All handles already assigned, must be trying to intialising more cameras
# than are connected.
self.logger.error('No connected SBIG cameras available!')
return (INVALID_HANDLE_VALUE, None)

Expand All @@ -162,7 +165,8 @@ def assign_handle(self, serial=None):

# Serial number, name and type should match with those from Query USB Info obtained earlier
camera_serial = str(self._camera_info.usbInfo[index].serialNumber, encoding='ascii')
assert camera_serial == ccd_info['serial_number'], self.logger.error('Serial number mismatch!')
assert camera_serial == ccd_info['serial_number'], self.logger.error(
'Serial number mismatch!')

# Keep camera info.
self._ccd_info[handle] = ccd_info
Expand All @@ -174,7 +178,8 @@ def assign_handle(self, serial=None):
return (handle, ccd_info)

def query_temp_status(self, handle):
query_temp_params = QueryTemperatureStatusParams(temp_status_request_codes['TEMP_STATUS_ADVANCED2'])
query_temp_params = QueryTemperatureStatusParams(
temp_status_request_codes['TEMP_STATUS_ADVANCED2'])
query_temp_results = QueryTemperatureStatusResults2()

with self._command_lock:
Expand Down Expand Up @@ -262,7 +267,10 @@ def take_exposure(self, handle, seconds, filename, exposure_event=None, dark=Fal

with self._command_lock:
self._set_handle(handle)
self._send_command('CC_QUERY_COMMAND_STATUS', params=query_status_params, results=query_status_results)
self._send_command(
'CC_QUERY_COMMAND_STATUS',
params=query_status_params,
results=query_status_results)

if query_status_results.status != status_codes['CS_IDLE']:
self.logger.warning('Attempt to start exposure on {} while camera busy!'.format(handle))
Expand Down Expand Up @@ -290,8 +298,10 @@ def take_exposure(self, handle, seconds, filename, exposure_event=None, dark=Fal
header.set('CCD-TEMP', temp_status.imagingCCDTemperature)
header.set('SET-TEMP', temp_status.ccdSetpoint)
header.set('EGAIN', self._ccd_info[handle]['readout_modes'][readout_mode]['gain'].value)
header.set('XPIXSZ', self._ccd_info[handle]['readout_modes'][readout_mode]['pixel_width'].value)
header.set('YPIXSZ', self._ccd_info[handle]['readout_modes'][readout_mode]['pixel_height'].value)
header.set('XPIXSZ', self._ccd_info[handle]
['readout_modes'][readout_mode]['pixel_width'].value)
header.set('YPIXSZ', self._ccd_info[handle]
['readout_modes'][readout_mode]['pixel_height'].value)
if dark:
header.set('IMAGETYP', 'Dark Frame')
else:
Expand Down Expand Up @@ -347,15 +357,21 @@ def _readout(self, handle, centiseconds, filename, readout_mode_code,
# Check for the end of the exposure.
with self._command_lock:
self._set_handle(handle)
self._send_command('CC_QUERY_COMMAND_STATUS', params=query_status_params, results=query_status_results)
self._send_command(
'CC_QUERY_COMMAND_STATUS',
params=query_status_params,
results=query_status_results)

# Poll if needed.
while query_status_results.status != status_codes['CS_INTEGRATION_COMPLETE']:
self.logger.debug('Waiting for exposure on {} to complete'.format(handle))
time.sleep(0.1)
with self._command_lock:
self._set_handle(handle)
self._send_command('CC_QUERY_COMMAND_STATUS', params=query_status_params, results=query_status_results)
self._send_command(
'CC_QUERY_COMMAND_STATUS',
params=query_status_params,
results=query_status_results)

self.logger.debug('Exposure on {} complete'.format(handle))

Expand All @@ -365,7 +381,11 @@ def _readout(self, handle, centiseconds, filename, readout_mode_code,
self._send_command('CC_END_EXPOSURE', params=end_exposure_params)
self._send_command('CC_START_READOUT', params=start_readout_params)
for i in range(height):
self._send_command('CC_READOUT_LINE', params=readout_line_params, results=as_ctypes(image_data[i]))
self._send_command(
'CC_READOUT_LINE',
params=readout_line_params,
results=as_ctypes(
image_data[i]))
self._send_command('CC_END_READOUT', params=end_readout_params)

self.logger.debug('Readout on {} complete'.format(handle))
Expand Down Expand Up @@ -407,10 +427,22 @@ def _get_ccd_info(self, handle):

with self._command_lock:
self._set_handle(handle)
self._send_command('CC_GET_CCD_INFO', params=ccd_info_params0, results=ccd_info_results0)
self._send_command('CC_GET_CCD_INFO', params=ccd_info_params2, results=ccd_info_results2)
self._send_command('CC_GET_CCD_INFO', params=ccd_info_params4, results=ccd_info_results4)
self._send_command('CC_GET_CCD_INFO', params=ccd_info_params6, results=ccd_info_results6)
self._send_command(
'CC_GET_CCD_INFO',
params=ccd_info_params0,
results=ccd_info_results0)
self._send_command(
'CC_GET_CCD_INFO',
params=ccd_info_params2,
results=ccd_info_results2)
self._send_command(
'CC_GET_CCD_INFO',
params=ccd_info_params4,
results=ccd_info_results4)
self._send_command(
'CC_GET_CCD_INFO',
params=ccd_info_params6,
results=ccd_info_results6)

# Now to convert all this ctypes stuff into Pythonic data structures.
ccd_info = {'firmware_version': self._bcd_to_string(ccd_info_results0.firmwareVersion),
Expand All @@ -431,7 +463,8 @@ def _get_ccd_info(self, handle):
'colour': bool(ccd_info_results6.ccd_b0),
'Truesense': bool(ccd_info_results6.ccd_b1)}

readout_mode_info = self._parse_readout_info(ccd_info_results0.readoutInfo[0:ccd_info_results0.readoutModes])
readout_mode_info = self._parse_readout_info(
ccd_info_results0.readoutInfo[0:ccd_info_results0.readoutModes])
ccd_info['readout_modes'] = readout_mode_info

return ccd_info
Expand Down Expand Up @@ -499,7 +532,8 @@ def _disable_vdd_optimized(self, handle):
of altering the bias structure between short and long exposures. This could cause systematic errors in bias
frames, dark current measurements, etc. It's probably not worth it.
"""
set_driver_control_params = SetDriverControlParams(driver_control_codes['DCP_VDD_OPTIMIZED'], 0)
set_driver_control_params = SetDriverControlParams(
driver_control_codes['DCP_VDD_OPTIMIZED'], 0)
self.logger.debug('Disabling DCP_VDD_OPTIMIZE on {}'.format(handle))
with self._command_lock:
self._set_handle(handle)
Expand Down Expand Up @@ -884,7 +918,9 @@ class QueryTemperatureStatusResults2(ctypes.Structure):
5: "REGULATION_ENABLE_AUTOFREEZE",
6: "REGULATION_DISABLE_AUTOFREEZE"}

temperature_regulation_codes = {regulation: code for code, regulation in temperature_regulations.items()}
temperature_regulation_codes = {
regulation: code for code,
regulation in temperature_regulations.items()}


class SetTemperatureRegulationParams(ctypes.Structure):
Expand Down
4 changes: 3 additions & 1 deletion pocs/camera/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def take_exposure(self, seconds=1.0 * u.second, filename=None, dark=False, block
seconds = seconds.to(u.second)
seconds = seconds.value

self.logger.debug('Taking {} second exposure on {}: {}'.format(seconds, self.name, filename))
self.logger.debug(
'Taking {} second exposure on {}: {}'.format(
seconds, self.name, filename))

# Set up a Timer that will wait for the duration of the exposure then copy a dummy FITS file
# to the specified path and adjust the headers according to the exposure time, type.
Expand Down
18 changes: 13 additions & 5 deletions pocs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def power_down(self):
"""
if self.connected:
self.say("I'm powering down")
self.logger.info("Shutting down {}, please be patient and allow for exit.".format(self.name))
self.logger.info(
"Shutting down {}, please be patient and allow for exit.".format(
self.name))

# Park if needed
if self.state not in ['parking', 'parked', 'sleeping', 'housekeeping']:
Expand Down Expand Up @@ -311,7 +313,8 @@ def is_weather_safe(self, stale=180):
bool: Conditions are safe (True) or unsafe (False)
"""
assert self.db.current, self.logger.warning("No connection to sensors, can't check weather safety")
assert self.db.current, self.logger.warning(
"No connection to sensors, can't check weather safety")

# Always assume False
is_safe = False
Expand All @@ -332,7 +335,8 @@ def is_weather_safe(self, stale=180):
timestamp = record['date']
age = (current_time().datetime - timestamp).total_seconds()

self.logger.debug("Weather Safety: {} [{:.0f} sec old - {}]".format(is_safe, age, timestamp))
self.logger.debug(
"Weather Safety: {} [{:.0f} sec old - {}]".format(is_safe, age, timestamp))

except TypeError as e:
self.logger.warning("No record found in Mongo DB")
Expand Down Expand Up @@ -451,10 +455,14 @@ def create_forwarder(port):
except Exception:
pass

cmd_forwarder_process = Process(target=create_forwarder, args=(cmd_port,), name='CmdForwarder')
cmd_forwarder_process = Process(
target=create_forwarder, args=(
cmd_port,), name='CmdForwarder')
cmd_forwarder_process.start()

msg_forwarder_process = Process(target=create_forwarder, args=(msg_port,), name='MsgForwarder')
msg_forwarder_process = Process(
target=create_forwarder, args=(
msg_port,), name='MsgForwarder')
msg_forwarder_process.start()

self._do_cmd_check = True
Expand Down
32 changes: 24 additions & 8 deletions pocs/focuser/birger.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def move_to(self, position):
"""
response = self._send_command('fa{:d}'.format(int(position)), response_length=1)
if response[0][:4] != 'DONE':
self.logger.error("{} got response '{}', expected 'DONENNNNN,N'!".format(self, response[0].rstrip()))
self.logger.error(
"{} got response '{}', expected 'DONENNNNN,N'!".format(
self, response[0].rstrip()))
else:
r = response[0][4:].rstrip()
self.logger.debug("Moved to {} encoder units".format(r[:-2]))
Expand All @@ -148,7 +150,9 @@ def move_by(self, increment):
"""
response = self._send_command('mf{:d}'.format(increment), response_length=1)
if response[0][:4] != 'DONE':
self.logger.error("{} got response '{}', expected 'DONENNNNN,N'!".format(self, response[0].rstrip()))
self.logger.error(
"{} got response '{}', expected 'DONENNNNN,N'!".format(
self, response[0].rstrip()))
else:
r = response[0][4:].rstrip()
self.logger.debug("Moved by {} encoder units".format(r[:-2]))
Expand Down Expand Up @@ -224,25 +228,33 @@ def _send_command(self, command, response_length=None, ignore_response=False):
error_message = error_messages[int(error_match.group())]
self.logger.error("{} returned error message '{}'!".format(self, error_message))
except Exception:
self.logger.error("Unknown error '{}' from {}!".format(error_match.group(), self))
self.logger.error(
"Unknown error '{}' from {}!".format(
error_match.group(), self))

return response

def _get_serial_number(self):
response = self._send_command('sn', response_length=1)
self._serial_number = response[0].rstrip()
self.logger.debug("Got serial number {} for {} on {}".format(self.uid, self.name, self.port))
self.logger.debug(
"Got serial number {} for {} on {}".format(
self.uid, self.name, self.port))

def _initialise_aperture(self):
self.logger.debug('Initialising aperture motor')
response = self._send_command('in', response_length=1)
if response[0].rstrip() != 'DONE':
self.logger.error("{} got response '{}', expected 'DONE'!".format(self, response[0].rstrip()))
self.logger.error(
"{} got response '{}', expected 'DONE'!".format(
self, response[0].rstrip()))

def _move_zero(self):
response = self._send_command('mz', response_length=1)
if response[0][:4] != 'DONE':
self.logger.error("{} got response '{}', expected 'DONENNNNN,1'!".format(self, response[0].rstrip()))
self.logger.error(
"{} got response '{}', expected 'DONENNNNN,1'!".format(
self, response[0].rstrip()))
else:
r = response[0][4:].rstrip()
self.logger.debug("Moved {} encoder units to close stop".format(r[:-2]))
Expand All @@ -256,12 +268,16 @@ def _learn_focus_range(self):
self.logger.debug('Learning absolute focus range')
response = self._send_command('la', response_length=1)
if response[0].rstrip() != 'DONE:LA':
self.logger.error("{} got response '{}', expected 'DONE:LA'!".format(self, response[0].rstrip()))
self.logger.error(
"{} got response '{}', expected 'DONE:LA'!".format(
self, response[0].rstrip()))

def _move_inf(self):
response = self._send_command('mi', response_length=1)
if response[0][:4] != 'DONE':
self.logger.error("{} got response '{}', expected 'DONENNNNN,1'!".format(self, response[0].rstrip()))
self.logger.error(
"{} got response '{}', expected 'DONENNNNN,1'!".format(
self, response[0].rstrip()))
else:
r = response[0][4:].rstrip()
self.logger.debug("Moved {} encoder units to far stop".format(r[:-2]))
Expand Down
Loading

0 comments on commit 5d13d60

Please sign in to comment.