<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.micromanager.acquisition;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import mmcorej.CMMCore;
import mmcorej.TaggedImage;
import org.micromanager.acquisition.engine.SequenceSettings;
import org.micromanager.api.AcquisitionEngine;
import org.micromanager.api.ScriptInterface;
import org.micromanager.api.TaggedImageStorage;
import org.micromanager.utils.ChannelSpec;
import org.micromanager.utils.JavaUtils;
import org.micromanager.utils.MDUtils;
import org.micromanager.utils.ReportingUtils;

/**
 *
 * @author arthur
 */
public class AcquisitionDisplayThread extends Thread {
   private static int untitledID_ = 0;

   private static String getUniqueUntitledName() {
      ++untitledID_;
      return "Untitled" + untitledID_;
   }

   protected final CMMCore core_;
   protected int imgCount_;
   private final ScriptInterface gui_;
   SequenceSettings acqSettings_;
   private boolean diskCached_ = false;
   private ArrayList<String> acqNames_ = new ArrayList<String>();
   private TaggedImageQueue imageProducingQueue_;
   private boolean singleWindow_;
   private MMImageCache imageCache_ = null;

   AcquisitionDisplayThread(ScriptInterface gui, CMMCore core,
           TaggedImageQueue imageProducingQueue, SequenceSettings acqSettings,
           ArrayList<ChannelSpec> channels, boolean diskCached, AcquisitionEngine eng,
           boolean singleWindow) {
      gui_ = gui;
      core_ = core;
      singleWindow_ = singleWindow;
      acqSettings_ = acqSettings;
      diskCached_ = diskCached;
      imageProducingQueue_ = imageProducingQueue;

      int nPositions = Math.max(1, (int) acqSettings.positions.size());
      int nTimes = Math.max(1, (int) acqSettings.numFrames);
      int nChannels = Math.max(1, (int) acqSettings.channels.size());
      int nSlices = Math.max(1, (int) acqSettings.slices.size());
      boolean usingChannels = acqSettings.channels.size() > 0;
      String acqPath;
      try {
         if (diskCached_) {
            acqPath = createAcqPath(acqSettings.root, acqSettings.prefix);
         } else {
            acqPath = getUniqueUntitledName();
         }
         String posName;
         
        // for (int posIndex = 0; posIndex < nPositions; ++posIndex) {
            posName = getPosName(0);
            String fullPath = createPositionPath(acqPath, "");
            String acqName = fullPath + "/" + "";
            acqNames_.add(acqName);
            gui_.openAcquisition(acqName, fullPath, nTimes, nChannels, nSlices, nPositions, true, diskCached_);
            gui_.setAcquisitionEngine(acqName, eng);

            //Map<String, String> summaryMetadata = makeMetadataFromAcqSettings(acqSettings);
            TaggedImageStorage imageFileManager;
            if (diskCached_) {
               imageFileManager = new TaggedImageStorageDiskDefault(acqName, true, null);
            } else {
               imageFileManager = new TaggedImageStorageRam(null);
            }
            imageCache_ = new MMImageCache(imageFileManager);
            imageCache_.setComment(acqSettings.comment);
            gui_.setAcquisitionCache(acqName, imageCache_);
            //gui_.setAcquisitionSummary(acqName, summaryMetadata);
            gui_.initializeAcquisition(acqName, (int) core_.getImageWidth(), (int) core_.getImageHeight(), (int) core_.getBytesPerPixel());
            if (usingChannels) {
               for (int i = 0; i < channels.size(); ++i) {
                  gui_.setChannelColor(acqName, i, channels.get(i).color_);
                  gui_.setChannelName(acqName, i, channels.get(i).config_);
               }
            }
         //}
      } catch (Exception ex) {
         ReportingUtils.logError(ex);
      }
   }

   private Map<String,String> makeMetadataFromAcqSettings(SequenceSettings acqSettings) {
      Map md = Collections.synchronizedMap(new HashMap<String, String>());<commit_msg>code cleanup<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.micromanager.acquisition;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import mmcorej.CMMCore;
import mmcorej.TaggedImage;
import org.micromanager.acquisition.engine.SequenceSettings;
import org.micromanager.api.AcquisitionEngine;
import org.micromanager.api.ScriptInterface;
import org.micromanager.api.TaggedImageStorage;
import org.micromanager.utils.ChannelSpec;
import org.micromanager.utils.JavaUtils;
import org.micromanager.utils.MDUtils;
import org.micromanager.utils.ReportingUtils;

/**
 *
 * @author arthur
 */
public class AcquisitionDisplayThread extends Thread {
   private static int untitledID_ = 0;

   private static String getUniqueUntitledName() {
      ++untitledID_;
      return "Untitled" + untitledID_;
   }

   protected final CMMCore core_;
   protected int imgCount_;
   private final ScriptInterface gui_;
   SequenceSettings acqSettings_;
   private boolean diskCached_ = false;
   private ArrayList<String> acqNames_ = new ArrayList<String>();
   private TaggedImageQueue imageProducingQueue_;
   private boolean singleWindow_;
   private MMImageCache imageCache_ = null;

   AcquisitionDisplayThread(ScriptInterface gui, CMMCore core,
           TaggedImageQueue imageProducingQueue, SequenceSettings acqSettings,
           ArrayList<ChannelSpec> channels, boolean diskCached, AcquisitionEngine eng,
           boolean singleWindow) {
      gui_ = gui;
      core_ = core;
      singleWindow_ = singleWindow;
      acqSettings_ = acqSettings;
      diskCached_ = diskCached;
      imageProducingQueue_ = imageProducingQueue;

      int nPositions = Math.max(1, (int) acqSettings.positions.size());
      int nTimes = Math.max(1, (int) acqSettings.numFrames);
      int nChannels = Math.max(1, (int) acqSettings.channels.size());
      int nSlices = Math.max(1, (int) acqSettings.slices.size());
      boolean usingChannels = acqSettings.channels.size() > 0;
      String acqPath;
      try {
         if (diskCached_) {
            acqPath = createAcqPath(acqSettings.root, acqSettings.prefix);
         } else {
            acqPath = getUniqueUntitledName();
         }

         String fullPath = createPositionPath(acqPath, "");
         String acqName = fullPath + "/" + "";
         acqNames_.add(acqName);
         gui_.openAcquisition(acqName, fullPath, nTimes, nChannels, nSlices, nPositions, true, diskCached_);
         gui_.setAcquisitionEngine(acqName, eng);

         //Map<String, String> summaryMetadata = makeMetadataFromAcqSettings(acqSettings);
         TaggedImageStorage imageFileManager;
         if (diskCached_) {
            imageFileManager = new TaggedImageStorageDiskDefault(acqName, true, null);
         } else {
            imageFileManager = new TaggedImageStorageRam(null);
         }
         imageCache_ = new MMImageCache(imageFileManager);
         imageCache_.setComment(acqSettings.comment);
         gui_.setAcquisitionCache(acqName, imageCache_);
         //gui_.setAcquisitionSummary(acqName, summaryMetadata);
         gui_.initializeAcquisition(acqName, (int) core_.getImageWidth(), (int) core_.getImageHeight(), (int) core_.getBytesPerPixel());
         if (usingChannels) {
            for (int i = 0; i < channels.size(); ++i) {
               gui_.setChannelColor(acqName, i, channels.get(i).color_);
               gui_.setChannelName(acqName, i, channels.get(i).config_);
            }
         }
         
      } catch (Exception ex) {
         ReportingUtils.logError(ex);
      }
   }

   private Map<String,String> makeMetadataFromAcqSettings(SequenceSettings acqSettings) {
      Map md = Collections.synchronizedMap(new HashMap<String, String>());
{'fraction_non_alphanumeric': 0.09579118271512427, 'fraction_numerical': 0.0019982515299113274, 'mean_word_length': 3.1860951385258756, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3836647', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2295, 'n_words': 493}