<commit_before>/*-
 * Copyright 2015 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.eclipse.dawnsci.analysis.dataset.slicer;

import java.util.Arrays;
import java.util.List;

import org.eclipse.dawnsci.analysis.api.dataset.IDataset;
import org.eclipse.dawnsci.analysis.api.dataset.ILazyDataset;
import org.eclipse.dawnsci.analysis.api.dataset.SliceND;
import org.eclipse.dawnsci.analysis.dataset.impl.SliceNDIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SliceBlockIterator implements ISliceViewIterator{

private static final Logger logger = LoggerFactory.getLogger(SliceBlockIterator.class);
	
	private ILazyDataset lazyDataset;
	private SliceNDIterator iterator;
	private SliceND	sampling;
	private SourceInformation source;
	private int[] axes;
	private int count;
	private int total;
	private int blocks = 10;
	private int fastest;
	private int subCount;
	private IDataset subSet;
	private boolean next;

	/**
	 * Construct a Slice View Iterator
	 * 
	 * @param lazyDataset - the full dataset
	 * @param sampling - the specific part to iterate over
	 * @param axes - the dimensions the correspond to data axes (i.e. length 1 for XY and 2 for an image)
	 */
	public SliceBlockIterator(ILazyDataset lazyDataset, SliceND sampling, int... axes) {
		this.lazyDataset = lazyDataset.getSliceView(sampling);
//		this.sampling = sampling != null ? sampling : new SliceND(lazyDataset.getShape());
		this.iterator = new SliceNDIterator(new SliceND(lazyDataset.getShape()), axes);
		this.axes = axes;
		this.sampling = sampling;
		count = 0;
		total = calculateTotal(sampling, axes);
		Arrays.sort(axes);
		for (int i = 0; i < lazyDataset.getRank(); i++){
			if (Arrays.binarySearch(axes, i) < 0) fastest = i;
		}
		subCount = 0;
		next = iterator.hasNext();
		
		List<SliceFromSeriesMetadata> sl;
		try {
			sl = lazyDataset.getMetadata(SliceFromSeriesMetadata.class);
			if (sl != null && !sl.isEmpty() && sl.get(0) != null) {
				SliceFromSeriesMetadata ss = sl.get(0);
				if (ss.getSourceInfo() != null) source = ss.getSourceInfo();
			}<commit_msg>null protect slice block iterator<commit_after>/*-
 * Copyright 2015 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.eclipse.dawnsci.analysis.dataset.slicer;

import java.util.Arrays;
import java.util.List;

import org.eclipse.dawnsci.analysis.api.dataset.IDataset;
import org.eclipse.dawnsci.analysis.api.dataset.ILazyDataset;
import org.eclipse.dawnsci.analysis.api.dataset.SliceND;
import org.eclipse.dawnsci.analysis.dataset.impl.SliceNDIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SliceBlockIterator implements ISliceViewIterator{

private static final Logger logger = LoggerFactory.getLogger(SliceBlockIterator.class);
	
	private ILazyDataset lazyDataset;
	private SliceNDIterator iterator;
	private SliceND	sampling;
	private SourceInformation source;
	private int[] axes;
	private int count;
	private int total;
	private int blocks = 10;
	private int fastest;
	private int subCount;
	private IDataset subSet;
	private boolean next;

	/**
	 * Construct a Slice View Iterator
	 * 
	 * @param lazyDataset - the full dataset
	 * @param sampling - the specific part to iterate over
	 * @param axes - the dimensions the correspond to data axes (i.e. length 1 for XY and 2 for an image)
	 */
	public SliceBlockIterator(ILazyDataset lazyDataset, SliceND sampling, int... axes) {
		if (sampling == null) sampling = new SliceND(lazyDataset.getShape());
		this.lazyDataset = lazyDataset.getSliceView(sampling);
//		this.sampling = sampling != null ? sampling : new SliceND(lazyDataset.getShape());
		this.iterator = new SliceNDIterator(new SliceND(lazyDataset.getShape()), axes);
		this.axes = axes;
		this.sampling = sampling;
		count = 0;
		total = calculateTotal(sampling, axes);
		Arrays.sort(axes);
		for (int i = 0; i < lazyDataset.getRank(); i++){
			if (Arrays.binarySearch(axes, i) < 0) fastest = i;
		}
		subCount = 0;
		next = iterator.hasNext();
		
		List<SliceFromSeriesMetadata> sl;
		try {
			sl = lazyDataset.getMetadata(SliceFromSeriesMetadata.class);
			if (sl != null && !sl.isEmpty() && sl.get(0) != null) {
				SliceFromSeriesMetadata ss = sl.get(0);
				if (ss.getSourceInfo() != null) source = ss.getSourceInfo();
			}
{'fraction_non_alphanumeric': 0.10602866779089376, 'fraction_numerical': 0.008431703204047217, 'mean_word_length': 4.416666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7666171', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1450, 'n_words': 422}