/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.autoplot.jythonsupport;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;
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(""
+ "title | title for the data, which could be used above a plot. |
\n"
+ "label | label for the data, which could be used as an axis label. |
\n"
+ "name | name for the data, which should be a legal Jython variable name. |
\n"
+ "units | units for the data, which string representing the units of the data. |
\n"
+ "resetUnits | assert units for the data, with no attempt to perform the units conversion. |
\n"
+ "validMin validMax | range of valid values for the data. |
\n"
+ "typicalMin typicalMax | typical range dataset, used for suggesting axis ranges. |
\n"
+ "scaleType | 'log' or 'linear' |
\n"
+ "averageType | 'linear', 'geometric', 'mod360', 'mod24', 'modpi', 'modtau' |
\n"
+ "format | format specifier, like %d or %.2f |
\n"
+ "cadence | nominal cadence, like 60s or 100Hz. Note this goes with the independent parameter (timetags). |
\n"
+ "
");
public static final PyString __completions__;
static {
String text = new BufferedReader(
new InputStreamReader( DatasetCommand.class.getResourceAsStream("DatasetCommand.json"), StandardCharsets.UTF_8) )
.lines().collect(Collectors.joining("\n"));
__completions__= new PyString( text );
}
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