List of usage examples for org.joda.time DateTime plusHours
public DateTime plusHours(int hours)
From source file:swrbRasterCase.ShortwaveRadiationBalanceRasterCase.java
License:Open Source License
@Execute public void process() throws Exception { // This 2 operations allow to define if we are working with daily or hourly time step // if we are working with Daily time step, every time it adds to the start date a day // otherwise it adds an hour, "step increments at the end of the process // the actual date is needed to compute the actual energy index DateTime startDateTime = formatter.parseDateTime(tStartDate); DateTime date = (doHourly == false) ? startDateTime.plusDays(step) : startDateTime.plusHours(step).plusMinutes(30); // computing the reference system of the input DEM CoordinateReferenceSystem sourceCRS = inDem.getCoordinateReferenceSystem2D(); if (step == 0) { // transform the GrifCoverage2D maps into writable rasters temperatureMap = mapsTransform(inTempGrid); if (humidityMap != null) humidityMap = mapsTransform(inHumidityGrid); demWR = mapsTransform(inDem);//from w w w . j a v a 2 s. c o m skyviewfactorWR = mapsTransform(inSkyview); // get the dimension of the maps regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inDem); cols = regionMap.getCols(); rows = regionMap.getRows(); dx = regionMap.getXres(); // compute the vector normal to a grid cell surface. normalWR = normalVector(demWR, dx); } WritableRaster outDiffuseWritableRaster = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); WritableRaster outDirectWritableRaster = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); WritableRaster outTopATMWritableRaster = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); WritableRaster totalWritableRaster = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); WritableRandomIter diffuseIter = RandomIterFactory.createWritable(outDiffuseWritableRaster, null); WritableRandomIter directIter = RandomIterFactory.createWritable(outDirectWritableRaster, null); WritableRandomIter topIter = RandomIterFactory.createWritable(outTopATMWritableRaster, null); WritableRandomIter totalIter = RandomIterFactory.createWritable(totalWritableRaster, null); // get the geometry of the maps and the coordinates of the stations GridGeometry2D inDemGridGeo = inDem.getGridGeometry(); stationCoordinates = getCoordinate(inDemGridGeo); // iterate over the entire domain and compute for each pixel the SWE for (int r = 1; r < rows - 1; r++) { for (int c = 1; c < cols - 1; c++) { int k = 0; // get the exact value of the variable in the pixel i, j temperature = temperatureMap.getSampleDouble(c, r, 0); humidity = pRH; if (humidityMap != null) humidity = humidityMap.getSampleDouble(c, r, 0); if (isNovalue(humidity)) humidity = pRH; // get the coordinate of the given pixel Coordinate coordinate = (Coordinate) stationCoordinates.get(k); //compute the latitude, after a reprojection in WGS 84 Point[] idPoint = getPoint(coordinate, sourceCRS, targetCRS); latitudeStation.add(Math.toRadians(idPoint[0].getY())); // calculating the sun vector double sunVector[] = calcSunVector(latitudeStation.get(k), getHourAngle(date, latitudeStation.get(k))); // calculate the inverse of the sun vector double[] inverseSunVector = calcInverseSunVector(sunVector); // calculate the normal of the sun vector according to Corripio (2003) double[] normalSunVector = calcNormalSunVector(sunVector); //E0 is the correction factor related to Earths orbit eccentricity computed according to Spencer (1971): double E0 = computeE0(date); //evaluate the shadow map WritableRaster shadowWR = calculateFactor(rows, cols, sunVector, inverseSunVector, normalSunVector, demWR, dx); // calculate the direct radiation, during the daylight double direct = (hour > (sunrise) && hour < (sunset)) ? calcDirectRadiation(c, r, demWR, shadowWR, sunVector, normalWR, E0, temperature, humidity) : 0; //calculate the diffuse radiation, during the daylight double diffuse = (hour > (sunrise) && hour < (sunset)) ? calcDiffuseRadiation(sunVector, E0, c, r) : 0; // calculate the radiation at the top of the atmosphere, during the daylight double topATM = (hour > (sunrise) && hour < (sunset)) ? calcTopAtmosphere(E0, sunVector[2]) : 0; double total = (hour > (sunrise) && hour < (sunset)) ? direct + diffuse : 0; diffuseIter.setSample(c, r, 0, direct); directIter.setSample(c, r, 0, diffuse); topIter.setSample(c, r, 0, topATM); totalIter.setSample(c, r, 0, total); // the index k is for the loop over the list k++; } } CoverageUtilities.setNovalueBorder(outDirectWritableRaster); CoverageUtilities.setNovalueBorder(outDiffuseWritableRaster); CoverageUtilities.setNovalueBorder(outTopATMWritableRaster); CoverageUtilities.setNovalueBorder(totalWritableRaster); outDirectGrid = CoverageUtilities.buildCoverage("Direct", outDirectWritableRaster, regionMap, inDem.getCoordinateReferenceSystem()); outDiffuseGrid = CoverageUtilities.buildCoverage("Diffuse", outDiffuseWritableRaster, regionMap, inDem.getCoordinateReferenceSystem()); outTopATMGrid = CoverageUtilities.buildCoverage("topATM", outTopATMWritableRaster, regionMap, inDem.getCoordinateReferenceSystem()); totalGrid = CoverageUtilities.buildCoverage("total", totalWritableRaster, regionMap, inDem.getCoordinateReferenceSystem()); // upgrade the step for the new date step++; }
From source file:test.integ.be.fedict.performance.CAConfiguration.java
License:Open Source License
private void generateCrl() throws Exception { DateTime now = new DateTime(); if (this.crlRefresh > 0) { crllGenerateNext = now.plusMinutes(this.crlRefresh); } else {//from w w w . j a v a2 s . c o m crllGenerateNext = now.plusHours(3); } crlNextUpdate = now.plusDays(7); List<BigInteger> revokedSerialNumbers = new LinkedList<BigInteger>(); for (long i = 0; i < this.crlRecords; i++) { revokedSerialNumbers.add(new BigInteger(Long.toString(i))); } X509CRL crl = TestUtils.generateCrl(crlNumber, this.keyPair.getPrivate(), certificate, now, crlNextUpdate, revokedSerialNumbers); this.crlFile = File.createTempFile("crl_" + name + "_", ".crl"); this.crlFile.deleteOnExit(); FileOutputStream fos = new FileOutputStream(this.crlFile); fos.write(crl.getEncoded()); fos.close(); }
From source file:uiuc.dm.miningTools.ui.ParametersSelectionFrame.java
private List<Trajectory> getSubTrajectory(List<Trajectory> trajs, Date start, Date end) { DateTime startDateTime = new DateTime(start); startDateTime = startDateTime.minusHours(12); DateTime endDateTime = new DateTime(end); endDateTime = endDateTime.plusHours(12); List<Trajectory> subs = new ArrayList<>(); for (Trajectory traj : trajs) { Trajectory sub = new Trajectory(); sub.setId(traj.getId());// w ww . j ava2 s .c om for (Point p : traj.getPoints()) { // if pTime >= start and pTime <= end; if ((p.getTime().equals(startDateTime) || p.getTime().isAfter(startDateTime)) && (p.getTime().equals(endDateTime) || p.getTime().isBefore(endDateTime))) { sub.addPoint(p); } } subs.add(sub); } return subs; }
From source file:ums.GenerateTimetable.java
public static void main(String[] a) { DateTime startTime = new DateTime(); startTime = startTime.dayOfWeek().setCopy(DateTimeConstants.MONDAY); startTime = startTime.hourOfDay().setCopy("9"); startTime = startTime.minuteOfHour().setCopy("15"); startTime = startTime.secondOfMinute().setCopy("0"); DateTimeFormatter fmt = DateTimeFormat.forPattern("EEEE h:mm a"); System.out.println(startTime.toString(fmt)); startTime = startTime.dayOfWeek().addToCopy(1); System.out.println(startTime.toString(fmt)); DateTime endTime = new DateTime(); endTime = endTime.dayOfWeek().setCopy(DateTimeConstants.MONDAY); endTime = endTime.hourOfDay().setCopy("21"); endTime = endTime.minuteOfHour().setCopy("15"); endTime = endTime.secondOfMinute().setCopy("0"); startTime.plusHours(3); if (startTime.equals(endTime)) { }//from w w w. ja v a 2 s.co m System.out.println(startTime); }
From source file:zack.yovel.clear.controller.background.UserPresentReceiver.java
License:Apache License
@Override public void onReceive(Context context, Intent intent) { this.context = context; initLocationServices();//from www . j a va 2s .c om preferences = PreferenceManager.getDefaultSharedPreferences(context); long lastPersistedWeatherReport = -1;//invalid, will require an update try { IWeatherPersist weatherReportPersistenceAgent = AWeatherPersistAgent.getInstance(); lastPersistedWeatherReport = weatherReportPersistenceAgent.getLastReportTime(context); } catch (FileNotFoundException e) { // do nothing here, the workflow will lead to triggering an update anyway. } DateTime lastUpdate = new DateTime(lastPersistedWeatherReport); if (lastUpdate.plusHours(1).isBeforeNow()) { boolean needCurrentLocation = preferences.getBoolean(Constants.Keys.PREF_MY_LOCATION, true); if (!needCurrentLocation) { String latlng = preferences.getString(Constants.Keys.PREF_LATLNG, null); if (null != latlng) { update(context, latlng); } else { findCurrentLocation(); } } else { findCurrentLocation(); } } }