/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.autoplot.jythonsupport; import java.util.Map; import java.util.logging.Logger; import org.python.core.Py; import org.python.core.PyObject; import org.python.core.PyString; import org.das2.qds.QDataSet; import org.das2.datum.Units; import org.das2.qds.ops.Ops; import org.python.core.PyDictionary; import org.python.core.PyFloat; import org.python.core.PyInteger; import org.python.core.PyJavaInstance; /** * new implementation of the dataset command allows for keywords in the * Jython environment. *
{@code
 * dataset( [1,2,3,4,3], title='My Data' )
 *}
* @see http://autoplot.org/help.datasetCommand * @author jbf */ public class DatasetCommand extends PyObject { private static final Logger logger= org.das2.util.LoggerManager.getLogger("jython.commands.dataset"); public static final PyString __doc__ = new PyString("

dataset(ds,[named parameters])

" + "dataset creates datasets from arrays and adds metadata.\n" + "See http://autoplot.org/help.datasetCommand
\n" + "
named parameters:\n" + "" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
title title for the data, which could be used above a plot.
label label for the data, which could be used as an axis label.
name name for the data, which should be a legal Jython variable name.
units units for the data, which string representing the units of the data.
resetUnits assert units for the data, with no attempt to perform the units conversion.
validMin validMaxrange of valid values for the data.
typicalMin typicalMaxtypical range dataset, used for suggesting axis ranges.
scaleType'log' or 'linear'
averageType'linear', 'geometric', 'mod360', 'mod24', 'modpi', 'modtau'
formatformat specifier, like %d or %.2f
cadencenominal cadence, like 60s or 100Hz. Note this goes with the independent parameter (timetags).
"); private static QDataSet datasetValue( PyObject arg0 ) { Object o = arg0.__tojava__(QDataSet.class); if (o == null || o == Py.NoConversion) { return JythonOps.dataset(arg0); } else { QDataSet ds = (QDataSet) o; if (ds.rank() == 0) { // QDataSet library handles coerce logic. return ds; } else { return ds; } } } private static boolean booleanValue( PyObject arg0 ) { if ( arg0.isNumberType() ) { return arg0.__nonzero__(); } else { String s= String.valueOf(arg0); return s.equals("True") || s.equals("T") || s.equals("1"); } } private static Number numberValue( PyObject arg0 ) { if ( arg0 instanceof PyInteger ) { return ((PyInteger)arg0).getValue(); } else if ( arg0 instanceof PyFloat ) { return ((PyFloat)arg0).getValue(); } else if ( arg0 instanceof PyString ) { return Double.parseDouble( String.valueOf(arg0) ); } else { return arg0.__float__().getValue(); } } /** * implement the python call. * @param args the "rightmost" elements are the keyword values. * @param keywords the names for the keywords. * @return Py.None */ @Override public PyObject __call__(PyObject[] args, String[] keywords) { FunctionSupport fs= new FunctionSupport( "dataset", new String[] { "ds", "ds1", "ds2", "ds3", "ds4", "title", "label", "name", "units", "format", "cadence", "resetUnits", "fillValue", "validMin", "validMax", "typicalMin", "typicalMax", "scaleType", "averageType", "renderType", "bins1", "bins0", "cacheTag", "userProperties", "deltaPlus", "deltaMinus", "binPlus", "binMinus", "binMin", "binMax", }, new PyObject[] { Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, Py.None, } ); fs.args( args, keywords ); int nparm= args.length - keywords.length; QDataSet result; Units units=null; boolean resetUnits=false; for ( int i=nparm; i