168
170
$imgIndex = new ImgIndex(new DbConnection());
170
172
// find the closest image
171
$queryForField = 'abbreviation';
172
173
foreach(array('observatory', 'instrument', 'detector', 'measurement') as $field) {
173
$src["$field.$queryForField"] = $this->params[$field];
174
$src["$field.abbreviation"] = $this->params[$field];
176
177
// file name and location
177
$filename = $imgIndex->getJP2Location($this->params['timestamp'], $src);
178
$filename = $imgIndex->getJP2Filename($this->params['timestamp'], $src);
178
179
$filepath = $this->getFilepath($filename);
180
181
// regex for URL construction
213
214
* @return int Returns "1" if the action was completed successfully.
216
* Converting timestamp to a PHP DateTime:
217
* $dt = new DateTime("@$startTime");
218
* echo $dt->format("U");
219
* date_add($dt, new DateInterval("T" . $cadence . "S"));
220
* (See http://us2.php.net/manual/en/function.date-create.php)
215
222
private function _getJP2ImageSeries () {
223
$startTime = $this->params['startTime'];
224
$endTime = $this->params['endTime'];
225
$cadence = $this->params['cadence'];
226
$format = $this->params['format'];
228
$observatory = $this->params['observatory'];
229
$instrument = $this->params['instrument'];
230
$detector = $this->params['detector'];
231
$measurement = $this->params['measurement'];
233
// Create a temporary directory to store image-series (TODO: Move this + other directory creation to installation script)
234
$tmpdir = Config::TMP_ROOT_DIR . "/movies/";
235
if (!file_exists($tmpdir)) {
237
chmod($tmpdir, 0777);
241
$filename = implode("_", array($observatory, $instrument, $detector, $measurement, "F$startTime", "T$endTime", "B$cadence")) . "." . strtolower($format);
244
$filepath = "$tmpdir" . $filename;
247
$url = Config::TMP_ROOT_URL . "/movies/" . $filename;
249
// If the file doesn't exist already, create it
250
if (!file_exists($filepath)) {
251
$this->buildJP2ImageSeries($filepath);
254
// Output the file/jpip URL
255
if ((isset($this->params['getJPIP'])) && ($this->params['getJPIP'] == "true")) {
256
$webRootRegex = "/" . preg_replace("/\//", "\/", Config::WEB_ROOT_DIR) . "/";
257
$mj2 = "jpip" . substr(preg_replace($webRootRegex, Config::WEB_ROOT_URL, $url), 4);
266
* @param string The filename to use
267
* Constructs a JPX/MJ2 image series
269
private function buildJP2ImageSeries ($output_file) {
270
//date_default_timezone_set('UTC');
216
271
require_once('ImgIndex.php');
217
//date_default_timezone_set('UTC');
219
$startTime = $this->params['startTime'];
220
$endTime = $this->params['endTime'];
221
$cadence = $this->params['cadence'];
222
$format = $this->params['format'];
273
$startTime = $this->params['startTime'];
274
$endTime = $this->params['endTime'];
275
$cadence = $this->params['cadence'];
276
$format = $this->params['format'];
224
278
// Layer information
225
279
foreach(array('observatory', 'instrument', 'detector', 'measurement') as $field) {
232
286
// Determine number of frames to grab
233
287
$timeInSecs = $endTime - $startTime;
234
288
$numFrames = min(Config::MAX_MOVIE_FRAMES, ceil($timeInSecs / $cadence));
236
// Convert timestamp to a PHP DateTime (See http://us2.php.net/manual/en/function.date-create.php)
237
//$dt = new DateTime("@$startTime");
238
//echo $dt->format("U");
239
//date_add($dt, new DateInterval("T" . $cadence . "S"));
241
291
$time = $startTime;
243
293
$images = array();
245
295
// Get nearest JP2 images to each time-step
246
296
for ($i = 0; $i < $numFrames; $i++) {
247
$jp2 = $this->getFilepath($imgIndex->getJP2Location($time, $src));
248
//$url = preg_replace($this->web_root_url_regex, $this->web_root_dir, $url);
297
$jp2 = $this->getFilepath($imgIndex->getJP2Filename($time, $src));
249
298
array_push($images, $jp2);
250
299
$time += $cadence;
259
308
// Drop trailing comma
260
309
$cmd = substr($cmd, 0, -1);
262
// Create a temporary directory to store image-series
264
$tmpdir = Config::TMP_ROOT_DIR . "/jp2-image-series/";
265
if (!file_exists($tmpdir)) {
267
chmod($tmpdir, 0777);
271
if (!file_exists($tmpdir)) {
273
chmod($tmpdir, 0777);
276
$filename = "jhv_image_series." . strtolower($format);
277
$tmpurl = Config::TMP_ROOT_URL . "/jp2-image-series/$now/" . $filename;
278
$output_file = "$tmpdir" . $filename;
280
311
$cmd .= " -o $output_file";
283
314
if ($format == "MJ2")
284
315
$cmd .= " -mj2_tracks P:0-@25";
286
317
// Execute kdu_merge command
287
318
exec('export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:' . Config::KDU_LIBS_DIR . "; " . escapeshellcmd($cmd), $output, $return);
291
if ((isset($this->params['getJPIP'])) && ($this->params['getJPIP'] == "true")) {
292
$webRootRegex = "/" . preg_replace("/\//", "\/", Config::WEB_ROOT_DIR) . "/";
293
$mj2 = "jpip" . substr(preg_replace($webRootRegex, Config::WEB_ROOT_URL, $tmpurl), 4);
403
428
throw new Exception("Invalid layer choices! You must specify 1-3 command-separate layernames.");
406
//Limit number of frames to 100
431
//Limit number of frames
407
432
if (($numFrames < 10) || ($numFrames > Config::MAX_MOVIE_FRAMES)) {
408
throw new Exception("Invalid number of frames. Number of frames should be at least 10 and no more than $maxFrames.");
433
throw new Exception("Invalid number of frames. Number of frames should be at least 10 and no more than " . Config::MAX_MOVIE_FRAMES . ".");
411
436
$imgSeries = new ImageSeries($layers, $startDate, $zoomLevel, $numFrames, $frameRate, $hqFormat, $xRange, $yRange, $options);