microlive 1.0.18__py3-none-any.whl → 1.0.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
microlive/imports.py CHANGED
@@ -23,7 +23,11 @@ from numba import njit, types
23
23
  from numba.typed import List as TypedList
24
24
  import cv2
25
25
  import io
26
- import fpdf
26
+ # Optional PDF generation support
27
+ try:
28
+ from fpdf import FPDF
29
+ except ImportError:
30
+ FPDF = None # PDF generation will be skipped if fpdf not installed
27
31
  import json
28
32
 
29
33
  # Import third-party libraries
@@ -1140,7 +1140,25 @@ def plot_frap_quantification_all_images(df_tracking_all, save_plot=False, plot_n
1140
1140
  return np.array(frames), np.array(mean_values), np.array(std_values)
1141
1141
 
1142
1142
 
1143
- def create_pdf(list_combined_image_paths,pdf_name, remove_original_images=False):
1143
+ def create_pdf(list_combined_image_paths, pdf_name, remove_original_images=False):
1144
+ """Create a PDF document from a list of images.
1145
+
1146
+ Args:
1147
+ list_combined_image_paths: List of Path objects to images.
1148
+ pdf_name: Output PDF file path.
1149
+ remove_original_images: If True, delete original images after adding to PDF.
1150
+
1151
+ Returns:
1152
+ None
1153
+
1154
+ Note:
1155
+ Requires fpdf/fpdf2 package. If not installed, prints a warning and skips PDF creation.
1156
+ """
1157
+ if FPDF is None:
1158
+ print(f"Warning: fpdf not installed. Skipping PDF creation: {pdf_name}")
1159
+ print("Install with: pip install fpdf2")
1160
+ return None
1161
+
1144
1162
  pdf = FPDF()
1145
1163
  pdf.set_auto_page_break(auto=True, margin=15)
1146
1164
  pdf.set_font("Arial", size=12)
@@ -239,31 +239,35 @@ def pipeline_folding_efficiency(original_lif_name, list_images,list_images_names
239
239
  plt.grid(axis='y', linestyle='--', alpha=0.7)
240
240
  plt.savefig(path_summary_wisker_plot, dpi=300, bbox_inches='tight')
241
241
  plt.show()
242
- # Create PDF with images and quality text
243
- pdf = FPDF()
244
- pdf.set_auto_page_break(auto=True, margin=15)
245
- pdf.set_font("Arial", size=12)
246
- for i, image_path in enumerate(list_image_paths_for_pdf):
247
- pdf.add_page()
248
- pdf.set_xy(10, 10)
249
- pdf.cell(0, 10, list_quality_text[i], 0, 1, 'L')
250
- if low_quality_pdf:
251
- img = Image.open(image_path)
252
- base_width = 150 # Desired width in mm in the PDF
253
- w_percent = (base_width / float(img.size[0]))
254
- h_size = int((float(img.size[1]) * float(w_percent))) # Height in mm to maintain aspect ratio
255
- # Temporarily save resized image for quality adjustment
256
- temp_path = Path(image_path).with_name(Path(image_path).stem + '_temp').with_suffix('.jpg')
257
- img.save(temp_path, 'JPEG', quality=85) # You can adjust quality to manage file size
258
- pdf.image(str(temp_path), x=25, y=25, w=base_width, h=h_size) # Now specifying both width and height
259
- temp_path.unlink() # Delete the temporary file
260
- else:
261
- # Directly embed the image at specified dimensions without resizing beforehand
262
- img = Image.open(image_path)
263
- w_percent = (150 / float(img.size[0]))
264
- h_size = int((float(img.size[1]) * float(w_percent))) # Calculate height to maintain aspect ratio
265
- pdf.image(str(image_path), x=25, y=25, w=150, h=h_size)
266
- pdf.output(path_summary_pdf)
242
+ # Create PDF with images and quality text (optional - requires fpdf)
243
+ if FPDF is not None:
244
+ pdf = FPDF()
245
+ pdf.set_auto_page_break(auto=True, margin=15)
246
+ pdf.set_font("Arial", size=12)
247
+ for i, image_path in enumerate(list_image_paths_for_pdf):
248
+ pdf.add_page()
249
+ pdf.set_xy(10, 10)
250
+ pdf.cell(0, 10, list_quality_text[i], 0, 1, 'L')
251
+ if low_quality_pdf:
252
+ img = Image.open(image_path)
253
+ base_width = 150 # Desired width in mm in the PDF
254
+ w_percent = (base_width / float(img.size[0]))
255
+ h_size = int((float(img.size[1]) * float(w_percent))) # Height in mm to maintain aspect ratio
256
+ # Temporarily save resized image for quality adjustment
257
+ temp_path = Path(image_path).with_name(Path(image_path).stem + '_temp').with_suffix('.jpg')
258
+ img.save(temp_path, 'JPEG', quality=85) # You can adjust quality to manage file size
259
+ pdf.image(str(temp_path), x=25, y=25, w=base_width, h=h_size) # Now specifying both width and height
260
+ temp_path.unlink() # Delete the temporary file
261
+ else:
262
+ # Directly embed the image at specified dimensions without resizing beforehand
263
+ img = Image.open(image_path)
264
+ w_percent = (150 / float(img.size[0]))
265
+ h_size = int((float(img.size[1]) * float(w_percent))) # Calculate height to maintain aspect ratio
266
+ pdf.image(str(image_path), x=25, y=25, w=150, h=h_size)
267
+ pdf.output(path_summary_pdf)
268
+ else:
269
+ print(f"Warning: fpdf not installed. Skipping PDF creation: {path_summary_pdf}")
270
+ print("Install with: pip install fpdf2")
267
271
 
268
272
  # save metadata
269
273
  metadata_folding_efficiency(