package org.autoplot.jythonsupport;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.das2.datum.DatumRange;
import org.das2.datum.DatumRangeUtil;
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.das2.util.monitor.ProgressMonitor;
/**
* new implementation of the dataset command allows for keywords in the
* Jython environment.
*
{@code
* Tp=getDataSet( 'vap+cdaweb:ds=STA_L2_MAGPLASMA_1M&id=Tp',trim='2022-12-24' )
*}
* @see http://autoplot.org/help.datasetCommand
* @author jbf
*/
public class GetDataSetCommand extends PyObject {
private static final Logger logger= org.das2.util.LoggerManager.getLogger("jython.commands.getdataset");
public static final PyString __doc__ =
new PyString("getDataSet(ds,timerange,monitor,[named parameters])
"
+ " load the data specified by URI into Autoplot's internal data model. This will\n"
+ " block until the load is complete, and a ProgressMonitor object can be used to\n"
+ " monitor the load..\n"
+ "
optional parameters:\n"
+ "\n"
+ "timerange | String or DatumRange |
\n"
+ "monitor | Progress Monitor |
\n"
+ "
\n"
+ "
named parameters:\n"
+ "\n"
+ "trim=True | trim the data to the requested time range. |
\n"
+ "units=None | convert the data to the given units, or remove the unit if empty string or None\n"
+ " |
sortTime=True | sort the data by its timetags |
\n"
+ "
");
public static final PyString __completions__;
static {
String text = new BufferedReader(
new InputStreamReader( GetDataSetCommand.class.getResourceAsStream("GetDataSetCommand.json"), StandardCharsets.UTF_8) )
.lines().collect(Collectors.joining("\n"));
__completions__= new PyString( text );
}
/**
* 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( "getDataSet",
new String[] { "uri",
"timerange", "monitor",
"trim", "units",
"sortTime"
},
new PyObject[] {
Py.None, Py.None,
Py.None, Py.None,
Py.None
}
);
fs.args( args, keywords );
int nparm= args.length - keywords.length;
String uri=null;
Units units= null;
DatumRange trimRange= null;
ProgressMonitor monitor= null;
QDataSet result=null;
for ( int i=nparm; i