@@ -761,7 +761,7 @@ def preview_img_from_file(fname, file_info, preview_output_directory, thumbnail_
761761
762762 else :
763763 # Stage 3 fits file - create thumbnails for all level 3 products
764- img = Level3PreviewImage (fname , create_thumbnail = True ,
764+ img = Level3PreviewImage (fname , create_thumbnail = file_info [ 'create_thumbnail' ] ,
765765 preview_output_directory = preview_output_directory ,
766766 thumbnail_output_directory = thumbnail_output_directory ,
767767 wfss_nbrightest_sources = 2
@@ -833,6 +833,13 @@ def process_program(program, overwrite, level3_only):
833833 'filename_parser() failed to recognize the file pattern.' ))
834834 filenames = filtered_filenames
835835
836+ # Sort in order to help keep track of thumbnail production for level 3 files
837+ filenames = sorted (filenames , reverse = True )
838+
839+ # Dictionary to track whether a thumbnail has been created for a level 3 rootname
840+ # Keys are rootnames, values are booleans describing whether a thumbail image has been made
841+ thumbs = {}
842+
836843 logging .info ('Found {} filenames' .format (len (filenames )))
837844 logging .info ('' )
838845
@@ -850,7 +857,7 @@ def process_program(program, overwrite, level3_only):
850857 identifier = f'jw{ parsed ["program_id" ]} '
851858 else :
852859 # In this case, the filename_parser failed to recognize the filename
853- identifier = os .path .basename (filename ).split ('.fits ' )[0 ]
860+ identifier = os .path .basename (filename ).split ('.' )[0 ]
854861 logging .warning ((f'While running generate_preview_images.process_program() on filtered filename { filename } , the '
855862 'filename_parser() failed to recognize the file pattern.' ))
856863 preview_output_directory = os .path .join (SETTINGS ['preview_image_filesystem' ], identifier )
@@ -880,9 +887,26 @@ def process_program(program, overwrite, level3_only):
880887 permissions .set_permissions (thumbnail_output_directory )
881888 logging .info ('\t Created directory {}' .format (thumbnail_output_directory ))
882889
890+ # For level 3 files, add a key to the filename_parser results, describing
891+ # whether or not to create a thumbnail image
892+ if 'stage_3' in parsed ['filename_type' ]:
893+ root = filename [0 :filename .rfind ('_' )]
894+ if root in thumbs :
895+ if thumbs [root ]:
896+ parsed ['create_thumbnail' ] = False
897+ else :
898+ parsed ['create_thumbnail' ] = True
899+ else :
900+ parsed ['create_thumbnail' ] = True
901+
883902 # Create the nominal preview image and thumbnail
884903 try :
885904 prev_ims , thumb_ims = preview_img_from_file (filename , parsed , preview_output_directory , thumbnail_output_directory )
905+ thumbs [root ] = True
906+
907+ # For development only
908+ print (f'Working on { filename } . Created thumbnail: { parsed ["create_thumbnail" ]} ' )
909+
886910 if prev_ims is not None :
887911 new_preview_counter += 1
888912 thumbnail_files .extend (thumb_ims )
0 commit comments