Example usage for org.joda.time Seconds ONE

List of usage examples for org.joda.time Seconds ONE

Introduction

In this page you can find the example usage for org.joda.time Seconds ONE.

Prototype

Seconds ONE

To view the source code for org.joda.time Seconds ONE.

Click Source Link

Document

Constant representing one second.

Usage

From source file:org.eumetsat.usd.gcp.server.data.NetCDFCalibrationDataManager.java

License:Apache License

/**
 * Add several calibration records from a certain source.
 * /*  www  . j  av  a 2  s . c  om*/
 * @param userID
 *            id of the user making the request.
 * @param ncfile
 *            netCDF file handler to read conversion parameters.
 * @param sourceName
 *            name of the data source.
 * @param sourceURL
 *            URL of the data source.
 * @param dateArray
 *            array of dates.
 * @param offsetArray
 *            array of offsets.
 * @param offsetSeArray
 *            array of standard deviations for offset.
 * @param slopeArray
 *            array of slopes.
 * @param slopeSeArray
 *            array of standard deviations for slope.
 * @param covarianceArray
 *            array of covariances.
 * @param channelNum
 *            channel number.
 * @param sceneTb
 *            scene brightness temperature.
 * @param radToTbConvFormula
 *            rad to tb conversion formula.
 * @param tbToRadConvFormula
 *            tb to rad conversion formula.
 * @param convVarsNames
 *            conversion variables names.
 * @throws DatasetReadException
 *             when dataset could not be opened for reading.
 * @throws InvalidFormatException
 *             when dataset has an invalid format.
 * @throws InvalidFilenameException
 *             when dataset has an invalid filename.
 * @throws VariableReadException
 * @throws ChannelNotFoundException
 * @throws VariableNotFoundException
 */
private final void addCalibrationRecords(final String userID, final NetcdfFile ncfile, final String sourceName,
        final String sourceURL, final Array dateArray, final Array offsetArray, final Array offsetSeArray,
        final Array slopeArray, final Array slopeSeArray, final Array covarianceArray, final int channelNum,
        final double sceneTb, final String radToTbConvFormula, final String tbToRadConvFormula,
        final Set<String> convVarsNames) throws BadArgumentException, InvalidFilenameException,
        DatasetReadException, VariableNotFoundException, ChannelNotFoundException, VariableReadException {
    // Check dimensions consistency.
    if ((dateArray.getShape()[0] != offsetArray.getShape()[0])
            || (dateArray.getShape()[0] != slopeArray.getShape()[0])
            || (dateArray.getShape()[0] != offsetSeArray.getShape()[0])
            || (dateArray.getShape()[0] != slopeSeArray.getShape()[0])
            || (dateArray.getShape()[0] != covarianceArray.getShape()[0])) {
        throw new BadArgumentException("array dimensions mismatch.");
    }

    // Sweep arrays and add each record into the map.
    for (int i = 0; i < dateArray.getShape()[0]; i++) {
        Double dateDouble = dateArray.getDouble(i) * 1e3; // in [ms]
        Date date = new Date(dateDouble.longValue());

        // Read the conversion variables.
        Map<String, Double> convVars = new HashMap<String, Double>();
        for (String convVarName : convVarsNames) {
            // TODO: [Remove workaround when formulas are changed]
            // Restore 'c1' and 'c2', if they are in the formula...
            if (convVarName.equals(configManager.getGlobalAttributesNames().getC1())) {
                convVars.put(C1_VARNAME, NetcdfUtils.readDouble(ncfile, convVarName, i, channelNum));

            } else if (convVarName.equals(configManager.getGlobalAttributesNames().getC2())) {
                convVars.put(C2_VARNAME, NetcdfUtils.readDouble(ncfile, convVarName, i, channelNum));
            } else {
                convVars.put(convVarName, NetcdfUtils.readDouble(ncfile, convVarName, i, channelNum));
            }
        }

        // Create calibration record.
        CalibrationRecord calRecord = new CalibrationRecordImpl(radToTbConvFormula, tbToRadConvFormula,
                convVars, TB_VARNAME, RAD_VARNAME, offsetArray.getDouble(i), offsetSeArray.getDouble(i),
                slopeArray.getDouble(i), slopeSeArray.getDouble(i), covarianceArray.getDouble(i), sceneTb);

        // Add calibration record, if valid, to data for this user.
        if (calRecord.isValid()) {
            dataForUser(userID).addRecord(date, sourceName, sourceURL, calRecord);

            // TODO: to be checked.
            // if single-point, add a second one, with same value, and shifted one second, so that
            // it can be plotted by dygraphs.
            if (dateArray.getShape()[0] == 1) {
                DateTime dt = new DateTime(date);
                dt = dt.plus(Seconds.ONE);

                dataForUser(userID).addRecord(dt.toDate(), sourceName, sourceURL, calRecord);
            }
        }
    }
}