@Override public IPathParameter resolvePathParameter(IContainer item) { IPathParameter result = null; String[] groupParts = item.getName().split(Pattern.quote(mPathSeparator)); String[] pathParts = mPath.getValue().split(Pattern.quote(mPathSeparator)); String part, param, buff; // Parse the path for (int depth = 0; depth < groupParts.length; depth++) { if (depth < pathParts.length) { part = groupParts[depth]; param = pathParts[depth]; // If a parameter is defined if (param.matches(".*(" + mPath.PARAM_PATTERN + ")+.*")) { // Try to determine the parameter result buff = param.replaceFirst("^(.*)(" + mPath.PARAM_PATTERN + ".*)$", "$1"); part = part.substring(buff.length()); buff = param.replaceAll(".*" + mPath.PARAM_PATTERN, ""); part = part.replaceFirst(Pattern.quote(buff), ""); buff = param.replaceAll(".*" + mPath.PARAM_PATTERN + ".*", "$1"); result = new PathParameter( Factory.getFactory(getFactoryName()), ParameterType.SUBSTITUTION, buff, part); break; } } } return result; }
@Override public IPathParameter getFirstPathParameter(StringBuffer output) { IPathParameter result = null; String[] pathParts = m_pathValue.split(Pattern.quote(PATH_SEPARATOR)); String name; // Split the path into nodes for (String part : pathParts) { if (part != null && !part.isEmpty()) { output.append(PATH_SEPARATOR); Pattern pattern = Pattern.compile(PARAM_PATTERN); Matcher matcher = pattern.matcher(part); if (matcher.find()) { name = part.replaceAll(".*" + PARAM_PATTERN + ".*", "$1"); result = Factory.getFactory(m_factory) .createPathParameter(ParameterType.SUBSTITUTION, name, ""); output.append(part.replaceAll(PARAM_PATTERN, "")); break; } else { output.append(part); } } } return result; }
public ArrayMath(IArray array, IFactory factory) { m_array = array; this.factory = factory; if (this.factory == null) { this.factory = Factory.getFactory(); } }
/** * Main process * * @param args path to reach file we want to parse * @throws IOException * @throws FileAccessException args[0] = folder of application's dictionary view args[1] = * plugin's name args[2] = folder where to find file */ public static void main(String[] args) throws Exception { System.out.println("OK"); final long time = System.currentTimeMillis(); final String dico_path; int nbFiles = 0; plugin = "org.gumtree.data.soleil.NxsFactory"; // Dictionary path if (args.length > 0) { dico_path = args[0]; Factory.setDictionariesFolder(dico_path); } // Setting plug-in to use if (args.length > 1) { plugin = args[1]; } if (args.length > 2) { sample_path = args[2]; } int i = 0; File folder = new File(sample_path); if (folder.exists()) { for (File sample : folder.listFiles()) { Runnable test = new Process(sample); Thread thread = new Thread(test); thread.start(); poolThread.add(thread); if (!useThreads) { thread.join(); } System.out.println(thread.getId() + "-------> " + sample.getName()); if (true) return; // test.run(); } } if (useThreads) { for (Thread t : poolThread) { t.join(); } } i++; // IFactory factory = Factory.getFactory(plugin); // TestArrayManual.testManuallyCreatedArrays(factory); System.out.println( "Total execution time: " + ((System.currentTimeMillis() - time) / 1000.) + "s"); System.out.println("Nb files tested: " + nbFiles); }
@Override public IDictionary findDictionary() { IDictionary dictionary = null; if (mGroups.length > 0) { IFactory factory = NxsFactory.getInstance(); dictionary = new NxsDictionary(); try { dictionary.readEntries( Factory.getMappingDictionaryFolder(factory) + NxsDictionary.detectDictionaryFile((NxsDataset) getDataset())); } catch (FileAccessException e) { dictionary = null; e.printStackTrace(); } // dictionary = mGroups[0].findDictionary(); } return dictionary; }
public Boolean process() throws Exception { retriever = new LiveDataRetriever(); retriever.setUser("Gumtree"); retriever.setPassword("Gumtree"); /* 'serverName' is one of the option strings, usually predefined by the algorithm, * and including the "default" option. * 'server' is the string for the actual server host name */ String server = serverName; if (serverName.equals("default")) { ICommandLineOptions options = ServiceUtils.getService(ICommandLineOptions.class); if (options.hasOptionValue(OPTION_SICS_INSTRUMENT)) { String instrumentName = options.getOptionValue(OPTION_SICS_INSTRUMENT); server = instrumentName.substring(instrumentName.lastIndexOf(".") + 1); server = "das1-" + server + ".nbi.ansto.gov.au"; } } URI fileHandle = null; try { fileHandle = retriever.getHDFFileHandle(server, serverPort, HistogramType.TOTAL_HISTO_XY); } catch (Exception e) { try { fileHandle = retriever.getHDFFileHandle("localhost", serverPort, HistogramType.TOTAL_HISTO_XY); } catch (Exception e1) { throw e1; } debugging("Cannot establish server connection"); } // Test if file is physically available long sleepTime; if (isFirst) { sleepTime = 2000; isFirst = false; } else { sleepTime = (long) (pollInterval * 1000); } try { debugging("> wait for " + sleepTime + " milliseconds"); Thread.sleep(sleepTime); } catch (Exception e) { throw e; } doStop = doStop || (null == fileHandle); if (doStop) { debugging("> Manual Stop or filehandle not available"); } else { debugging("> filehandle: " + fileHandle); histogram = fetchHistogram(fileHandle); } if (null == histogram) { debugging("> histogram: null"); doStop = true; histogram = Factory.createGroup("empty"); } outLoop = !doStop; return doStop; }
public Boolean process() throws Exception { if (skip_norm) { normalised_data = normalise_groupdata; return false; } // Read in needed data and prepare output arrays IArray dataArray = ((Plot) normalise_groupdata).findSignalArray(); IArray variance_array = ((Plot) normalise_groupdata).getVariance().getData(); /* If we have a 3D array, this means a series of monitor counts is available to * allow normalisation at each scan step. If the array is 2D, then no such * normalisation is necessary. */ double monmax = 1.0; // Value to which we normalise; usually maximum monitor counts if (dataArray.getRank() > 2) { int[] data_dims = dataArray.getShape(); int dlength = dataArray.getRank(); IArray monitor_array = normalise_groupdata.getRootGroup().getDataItem("monitor_data").getData(); // We should have a monitor array rather than a single value monmax = monitor_array.getArrayMath().getMaximum(); System.out.printf("Normalising to %f monitor counts\n", monmax); IArray outarray = Factory.createArray(double.class, data_dims); IArray out_variance = Factory.createArray(double.class, data_dims); int[] origin_list = new int[dlength]; int[] range_list = new int[dlength]; int[] target_shape = new int[dlength]; // shape to make a 2D array from multi-dim array for (int i = 0; i < dlength; i++) origin_list[i] = 0; // take in all elements for (int i = 0; i < dlength - 2; i++) { range_list[i] = data_dims[i]; // last two are rank reduced target_shape[i] = 1; } range_list[dlength - 2] = 1; range_list[dlength - 1] = 1; target_shape[dlength - 2] = data_dims[dlength - 2]; target_shape[dlength - 1] = data_dims[dlength - 1]; // Create an iterator over the higher dimensions. We leave in the final two dimensions so // that we can // use the getCurrentCounter method to create an origin. // Iterate over two-dimensional slices // Array loop_array = dataArray.sectionNoReduce(origin_list, range_list, null); ISliceIterator higher_dim_iter = dataArray.getSliceIterator(2); IArrayIterator mon_iter = monitor_array.getIterator(); ISliceIterator high_dim_out_it = outarray.getSliceIterator(2); ISliceIterator var_out_it = out_variance.getSliceIterator(2); ISliceIterator invar_iter = variance_array.getSliceIterator(2); // Now loop over higher dimensional frames while (higher_dim_iter.hasNext()) { double monval = mon_iter.getDoubleNext(); if (monval == 0) { String errorstring = "Normalisation error: zero monitor counts found"; throw new Exception(errorstring); } double monerr = monmax * monmax / (monval * monval * monval); monval = monmax / monval; // Actual value to multiply by IArray[] out_with_var = {high_dim_out_it.getArrayNext(), var_out_it.getArrayNext()}; IArray[] in_with_var = {higher_dim_iter.getArrayNext(), invar_iter.getArrayNext()}; // First create a scalar for normalisation of each frame double[] norm_with_err = {monval, monerr}; ArrayOperations.multiplyByScalar(in_with_var, norm_with_err, out_with_var); } // Now build the output databag String resultName = "normalisation_result"; normalised_data = PlotFactory.createPlot(normalise_groupdata, resultName, dataDimensionType); ((NcGroup) normalised_data).addLog("Apply normalisation to get " + resultName); PlotFactory.addDataToPlot( normalised_data, resultName, outarray, "Normalised data", "Normalised counts", out_variance); // Copy axes across from previous data List<Axis> data_axes = ((Plot) normalise_groupdata).getAxisList(); for (Axis oneaxis : data_axes) { PlotFactory.addAxisToPlot(normalised_data, oneaxis, oneaxis.getDimensionName()); } // We need the value to which everything has been normalised to be available to // subsequent processing steps IAttribute norm_val = Factory.createAttribute("normalised_to_val", monmax); // normalised_data.buildResultGroup(signal, stthVector, channelVector, twoThetaVector); normalised_data.addOneAttribute(norm_val); } else { normalised_data = normalise_groupdata; } return false; }