|
1 | 1 | # File containing the Client for connecting to the DE-Server |
2 | 2 | # |
3 | | -# Last update: 2024-08-07 |
| 3 | +# Last update: 2025-11-13 |
4 | 4 | # cfrancis@directelectron.com |
5 | 5 |
|
6 | 6 |
|
|
51 | 51 | logLevel = logging.INFO |
52 | 52 | logging.basicConfig(format="%(asctime)s DE %(levelname)-8s %(message)s", level=logLevel) |
53 | 53 | log = logging.getLogger("DECameraClientLib") |
54 | | -log.info("Python : " + sys.version.split("(")[0]) |
55 | | -log.info("DEClient : " + version) |
56 | | -log.info("CommandVer: " + str(commandVersion)) |
57 | | -log.info("logLevel : " + str(logging.getLevelName(logLevel))) |
58 | 54 |
|
| 55 | +def print_info(): |
| 56 | + log.info(f"DEAPI Version: {version} (Command Version: {commandVersion})") |
| 57 | + log.info("Python : " + sys.version.split("(")[0]) |
| 58 | + log.info("DEClient : " + version) |
| 59 | + log.info("CommandVer: " + str(commandVersion)) |
| 60 | + log.info("logLevel : " + str(logging.getLevelName(logLevel))) |
59 | 61 |
|
60 | 62 | class Client: |
61 | 63 | """A class for connecting to the DE-Server |
@@ -217,7 +219,7 @@ def connect(self, host: str = "127.0.0.1", port: int = 13240, read_only=False): |
217 | 219 | self.commandVersion = 3 |
218 | 220 | else: |
219 | 221 | self.commandVersion = commandVersion |
220 | | - print("Command Version: ", self.commandVersion) |
| 222 | + log.info(f"Command Version: {self.commandVersion}") |
221 | 223 | self._initialize_attributes() |
222 | 224 | self.update_scan_size() |
223 | 225 | self.update_image_size() |
@@ -989,7 +991,7 @@ def set_binning(self, bin_x, bin_y, use_hw=True): |
989 | 991 | retval = True |
990 | 992 | if commandVersion < 10: |
991 | 993 | retval = self.SetProperty( |
992 | | - "Binning Mode", "Hardware and Software" if useHW else "Software Only" |
| 994 | + "Binning Mode", "Hardware and Software" if use_hw else "Software Only" |
993 | 995 | ) |
994 | 996 | retval &= self.SetProperty("Binning X", bin_x) |
995 | 997 | retval &= self.SetProperty("Binning Y", bin_y) |
@@ -1408,7 +1410,7 @@ def set_xy_array(self, positions, width=None, height=None): |
1408 | 1410 | packet = struct.pack("I", command.ByteSize()) + command.SerializeToString() |
1409 | 1411 | self.socket.send(packet) |
1410 | 1412 | ret = self.__ReceiveResponseForCommand(command) != False |
1411 | | - print("response", ret) |
| 1413 | + log.info(f"response {ret}") |
1412 | 1414 | except socket.error: |
1413 | 1415 | raise socket.error( |
1414 | 1416 | "Error sending x-y scan positions to socket. Is the server running?" |
@@ -1771,7 +1773,7 @@ def set_virtual_mask(self, id, w, h, mask): |
1771 | 1773 | log.warning("Virtual mask must be a numpy array of type uint8") |
1772 | 1774 | mask = mask.astype(np.uint8) |
1773 | 1775 | mask_bytes = mask.tobytes() |
1774 | | - print("Sending mask of size", len(mask_bytes)) |
| 1776 | + log.info(f"Sending mask of size {len(mask_bytes)}") |
1775 | 1777 | self.__sendToSocket(self.socket, mask_bytes, len(mask_bytes)) |
1776 | 1778 |
|
1777 | 1779 | ret = self.__ReceiveResponseForCommand(command) != False |
@@ -1900,9 +1902,9 @@ def get_movie_buffer( |
1900 | 1902 | f"expected: {totalBytes}, received: {movieBufferSize}" |
1901 | 1903 | ) |
1902 | 1904 | else: |
1903 | | - print("reading movie buffer", totalBytes) |
| 1905 | + log.info(f"reading movie buffer {totalBytes}", ) |
1904 | 1906 | movieBuffer = self._recvFromSocket(self.socket, totalBytes) |
1905 | | - print("Done reading movie buffer") |
| 1907 | + log.info("Done reading movie buffer") |
1906 | 1908 | else: |
1907 | 1909 | retval = False |
1908 | 1910 |
|
@@ -2216,7 +2218,7 @@ def wait_for_saving_files(self, quiet=True): |
2216 | 2218 |
|
2217 | 2219 | duration = self.GetTime() - t0 |
2218 | 2220 | if not quiet: |
2219 | | - print(" %.1fs" % duration) |
| 2221 | + log.info(f" {duration:.1f}s") |
2220 | 2222 | sys.stdout.flush() |
2221 | 2223 |
|
2222 | 2224 | def _get_auto_attributes(self, frame_type: FrameType): |
@@ -2386,11 +2388,7 @@ def take_trial_gain_reference( |
2386 | 2388 | self.SetProperty("Exposure Time (seconds)", prevExposureTime) |
2387 | 2389 |
|
2388 | 2390 | num_el = np.max([attr.eppixpf * frame_rate, attr.eppixps]) |
2389 | | - print( |
2390 | | - "The number of electrons per pixel per second (eppixps): {:.2f}".format( |
2391 | | - num_el |
2392 | | - ) |
2393 | | - ) |
| 2391 | + log.info(f"The number of electrons per pixel per second (eppixps): {num_el:.2f}") |
2394 | 2392 |
|
2395 | 2393 | if attr.saturation > 0.0001: # Nothing should be saturated in a gain image. |
2396 | 2394 | raise ValueError( |
@@ -2450,7 +2448,7 @@ def take_gain_reference( |
2450 | 2448 | frame_rate, target_electrons_per_pixel, counting |
2451 | 2449 | ) |
2452 | 2450 |
|
2453 | | - print( |
| 2451 | + log.info( |
2454 | 2452 | f"Gain reference: {exposure_time:.2f} seconds, " |
2455 | 2453 | f"total acquisitions: {num_acquisitions}, " |
2456 | 2454 | ) |
|
0 commit comments