Skip to content

Commit

Permalink
accufiz_interferometer changes per flake8 linter
Browse files Browse the repository at this point in the history
  • Loading branch information
lanemeier7 committed Oct 18, 2024
1 parent 6353335 commit 7057d5c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
16 changes: 10 additions & 6 deletions catkit2/services/accufiz_interferometer/accufiz_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AccufizInterferometer(Service):

def __init__(self):
super().__init__('accufiz_interferometer')

# mask, server path, local path are required
self.mask = self.config['mask']
self.server_path = self.config['server_path']
Expand All @@ -40,14 +40,15 @@ def __init__(self):
# Set the 4D timeout.
self.html_prefix = f"http://{self.ip}/WebService4D/WebService4D.asmx"
set_timeout_string = f"{self.html_prefix}/SetTimeout?timeOut={self.timeout}"

self.get(set_timeout_string)

# set mask
self.set_mask()

# Create data streams.
self.detector_masks = self.make_data_stream('detector_masks', 'uint8', [self.image_height, self.image_width], self.NUM_FRAMES_IN_BUFFER)
self.images = self.make_data_stream('images', 'float32', [self.image_height, self.image_width], self.NUM_FRAMES_IN_BUFFER)

self.is_acquiring = self.make_data_stream('is_acquiring', 'int8', [1], 20)
self.is_acquiring.submit_data(np.array([0], dtype='int8'))
self.should_be_acquiring = threading.Event()
Expand Down Expand Up @@ -82,7 +83,7 @@ def post(self, url, data=None, json=None, **kwargs):
raise RuntimeError(f"{self.config_id} POST error: {resp.status_code}: {resp.text}")
time.sleep(self.post_save_sleep)
return resp


def take_measurement(self, num_frames=2):
# Send request to take data.
Expand All @@ -106,7 +107,7 @@ def take_measurement(self, num_frames=2):

if not glob(f"{local_file_path}.h5"):
raise RuntimeError(f"{self.config_id}: Failed to save measurement data to '{local_file_path}'.")

local_file_path = local_file_path if local_file_path.endswith(".h5") else f"{local_file_path}.h5"

self.log.info(f"{self.config_id}: Succeeded to save measurement data to '{local_file_path}'")
Expand Down Expand Up @@ -140,7 +141,7 @@ def convert_h5_to_fits(filepath, rotate, fliplr, img, mask, wavelength=632.8, cr
center = ndimage.measurements.center_of_mass(mask)

image = np.clip(img, -10, +10)[np.int64(center[0]) - radiusmask:np.int64(center[0]) + radiusmask - 1,
np.int64(center[1]) - radiusmask: np.int64(center[1]) + radiusmask - 1]
np.int64(center[1]) - radiusmask: np.int64(center[1]) + radiusmask - 1]

# Apply the rotation and flips.
image = rotate_and_flip_image(image, rotate, fliplr)
Expand Down Expand Up @@ -179,12 +180,15 @@ def acquisition_loop(self):
finally:
self.is_acquiring.submit_data(np.array([0], dtype='int8'))


def start_acquisition(self):
self.should_be_acquiring.set()


def end_acquisition(self):
self.should_be_acquiring.clear()


if __name__ == '__main__':
service = AccufizInterferometer()
service.run()
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AccufizInterferometerSim(Service):

def __init__(self):
super().__init__('accufiz_interferometer_sim')

# mask, server path, local path are required
self.mask = self.config['mask']
self.server_path = self.config['server_path']
Expand All @@ -65,14 +65,15 @@ def __init__(self):
# Set the 4D timeout.
self.html_prefix = f"http://{self.ip}/WebService4D/WebService4D.asmx"
set_timeout_string = f"{self.html_prefix}/SetTimeout?timeOut={self.timeout}"

self.get(set_timeout_string)

# set mask
self.set_mask()

# Create data streams.
self.detector_masks = self.make_data_stream('detector_masks', 'uint8', [self.image_height, self.image_width], self.NUM_FRAMES_IN_BUFFER)
self.images = self.make_data_stream('images', 'float32', [self.image_height, self.image_width], self.NUM_FRAMES_IN_BUFFER)

self.is_acquiring = self.make_data_stream('is_acquiring', 'int8', [1], 20)
self.is_acquiring.submit_data(np.array([0], dtype='int8'))
self.should_be_acquiring = threading.Event()
Expand Down Expand Up @@ -105,7 +106,6 @@ def post(self, url, data=None, json=None, **kwargs):
time.sleep(self.post_save_sleep)
return sim_response()


def take_measurement(self, num_frames=1):
# Send request to take data.
resp = self.post(f"{self.html_prefix}/AverageMeasure", data={"count": int(num_frames)})
Expand All @@ -124,7 +124,7 @@ def take_measurement(self, num_frames=1):
tmph5f = h5py.File(fname, 'w')
tmph5f['measurement0/Detectormask'] = generate_circle_array(radius=1, h=self.image_height, w=self.image_width)
tmph5f['measurement0/genraw/data'] = np.random.rand(self.image_height, self.image_width)
tmph5f.close()
tmph5f.close()

else:
local_file_path = self.sim_data.replace('.h5', '')
Expand All @@ -140,7 +140,7 @@ def take_measurement(self, num_frames=1):

if not glob(f"{local_file_path}.h5"):
raise RuntimeError(f"{self.config_id}: Failed to save measurement data to '{local_file_path}'.")

local_file_path = local_file_path if local_file_path.endswith(".h5") else f"{local_file_path}.h5"

self.log.info(f"{self.config_id}: Succeeded to save measurement data to '{local_file_path}'")
Expand All @@ -156,13 +156,12 @@ def take_measurement(self, num_frames=1):

if os.path.exists(local_file_path):
os.remove(local_file_path)

if os.path.exists(fitsfile):
os.remove(fitsfile)
self.log.info('cleaning up temporary simulated files')
return image


@staticmethod
def convert_h5_to_fits(filepath, rotate, fliplr, img, mask, wavelength=632.8, create_fits=False):

Expand All @@ -179,7 +178,7 @@ def convert_h5_to_fits(filepath, rotate, fliplr, img, mask, wavelength=632.8, cr
center = ndimage.measurements.center_of_mass(mask)

image = np.clip(img, -10, +10)[np.int64(center[0]) - radiusmask:np.int64(center[0]) + radiusmask - 1,
np.int64(center[1]) - radiusmask: np.int64(center[1]) + radiusmask - 1]
np.int64(center[1]) - radiusmask: np.int64(center[1]) + radiusmask - 1]

# Apply the rotation and flips.
image = rotate_and_flip_image(image, rotate, fliplr)
Expand Down Expand Up @@ -218,12 +217,15 @@ def acquisition_loop(self):
finally:
self.is_acquiring.submit_data(np.array([0], dtype='int8'))


def start_acquisition(self):
self.should_be_acquiring.set()


def end_acquisition(self):
self.should_be_acquiring.clear()


if __name__ == '__main__':
service = AccufizInterferometerSim()
service.run()

0 comments on commit 7057d5c

Please sign in to comment.