3
* @class SubFieldImage - A simple class to keep track of a specific layer's associated parameters.
5
require('JP2Image.php');
7
class SubFieldImage extends JP2Image {
15
public function __construct($params, $timestamp, $zoomLevel, $xRange, $yRange, $tileSize, $correlate = NULL) {
16
parent::__construct($zoomLevel, $xRange, $yRange, $tileSize);
18
$this->observatory = substr($params, 0, 3);
19
$this->instrument = substr($params, 3, 3);
20
$this->detector = substr($params, 6,3);
21
$this->measurement = substr($params, 9,3);
23
$this->unixTimestamp = $timestamp;
24
$this->timestamp = $this->parseTimestamp($timestamp);
26
//$this->timestamps = $this->buildTimestampsArray($startTime, $endTime);
30
public function observatory() {
31
return $this->observatory;
34
public function instrument() {
35
return $this->instrument;
38
public function detector() {
39
return $this->detector;
42
public function measurement() {
43
return $this->measurement;
46
public function opacity() {
47
return $this->opacity;
50
private function buildImage () {
51
// Retrieve meta-information
52
$imageInfo = $this->getMetaInfo();
54
// Filepaths (For .tif and .png images)
55
$jp2 = $this->getFilePath("input");
56
$tif = $this->getFilePath("output");
58
// If tile already exists in cache, use it
59
//if (file_exists($png)) {
60
// $this->image = new Imagick($png);
66
$im = $this->extractRegion($jp2, $tif, $imageInfo["width"], $imageInfo["height"], $imageInfo['imgScaleX'], $this->detector, $this->measurement);
75
//$this->dimensions = $this->getImageDimensions();
77
// extractRegion($input, $output, $imageWidth, $imageHeight, $imageScale, $colorTable = Null)
79
// Ratio of the desired scale to the actual JP2 image scale
80
//$desiredToActual = $this->desiredScale / $scale;
82
// Number of tiles in scaled image
83
//$imgNumTilesX = ceil($width / ($desiredToActual * $ts));
84
//$imgNumTilesY = ceil($height / ($desiredToActual * $ts));
86
//print $imgNumTilesX . "<br>";
87
//print $imgNumTilesY . "<br>";
89
// Valid number of tiles for movie
90
//$numTilesX = min($imgNumTilesX, $this->xRange["end"] - $this->xRange["start"] + 1);
91
//$numTilesY = min($imgNumTilesY, $this->yRange["end"] - $this->yRange["start"] + 1);
93
//print "numTilesX: $numTilesX<br>";
94
//print "numTilesY: $numTilesY<br>";
96
// Movie (ROI) Dimensions
97
//$dimensions = array();
98
//$dimensions['width'] = $ts * $numTilesX;
99
//$dimensions['height'] = $ts * $numTilesY;
100
//$dimensions['x'] = (1/2) * ($width - $dimensions['width']);
101
//$dimensions['y'] = (1/2) * ($height - $dimensions['height']);
105
* buildTimestampsArray
107
* @param $start Object
110
private function buildTimestampsArray($startTime, $endTime) {
111
$timestamps = array();
113
// Case 1: A single image
114
if ($startTime == $endTime) {
115
array_push($timestamps, $startTime);
118
// Case 2: A image series / movie
128
* @description Determine the dimensions for the layer
131
private function getMetaInfo() {
133
$obs = $this->observatory;
134
$inst = $this->instrument;
135
$det = $this->detector;
136
$meas = $this->measurement;
138
// Get full image dimensions
139
$sql = sprintf("SELECT width, height, imgScaleX
141
LEFT JOIN measurement on measurementId = measurement.id
142
LEFT JOIN measurementType on measurementTypeId = measurementType.id
143
LEFT JOIN detector on detectorId = detector.id
144
LEFT JOIN opacityGroup on opacityGroupId = opacityGroup.id
145
LEFT JOIN instrument on instrumentId = instrument.id
146
LEFT JOIN observatory on observatoryId = observatory.id
147
WHERE observatory.abbreviation='%s' AND instrument.abbreviation='%s' AND detector.abbreviation='%s' AND measurement.abbreviation='%s' LIMIT 1",
148
mysql_real_escape_string($obs), mysql_real_escape_string($inst), mysql_real_escape_string($det), mysql_real_escape_string($meas));
150
$result = $this->db->query($sql);
151
$meta = mysql_fetch_array($result, MYSQL_ASSOC);
156
private function parseTimestamp ($ts) {
160
$mon = str_pad($d['mon'], 2 , "0", STR_PAD_LEFT);
161
$day = str_pad($d['mday'], 2 , "0", STR_PAD_LEFT);
162
$hour = str_pad($d['hours'], 2 , "0", STR_PAD_LEFT);
163
$min = str_pad($d['minutes'], 2 , "0", STR_PAD_LEFT);
164
$sec = str_pad($d['seconds'], 2 , "0", STR_PAD_LEFT);
166
return "$year-$mon-$day $hour:$min:$sec";
169
private function getFilePath($type) {
171
$year = substr($this->timestamp,0,4);
172
$month = substr($this->timestamp,5,2);
173
$day = substr($this->timestamp,8,2);
174
$hour = substr($this->timestamp,11,2);
175
$min = substr($this->timestamp,14,2);
176
$sec = substr($this->timestamp,17,2);
179
$obs = $this->observatory;
180
$inst = $this->instrument;
181
$det = $this->detector;
182
$meas = $this->measurement;
185
if ($type == "input") {
186
$filepath = $this->jp2Dir . implode("/", array($year, $month, $day, $obs, $inst, $det, $meas)) . "/";
187
$filepath .= implode("_", array($year, $month, $day, $hour . $min . $sec, $obs, $inst, $det, $meas)) . ".jp2";
193
$filepath = $this->cacheDir . "movies" . "/";
194
if (!file_exists($filepath))
197
// Create necessary directories
198
$filepath .= $year . "/";
199
if (!file_exists($filepath))
202
$filepath .= $month . "/";
203
if (!file_exists($filepath))
206
$filepath .= $day . "/";
207
if (!file_exists($filepath))
210
// Convert coordinates to strings
211
$xStartStr = "+" . str_pad($this->xRange["start"], 2, '0', STR_PAD_LEFT);
212
if (substr($this->xRange["start"],0,1) == "-")
213
$xStartStr = "-" . str_pad(substr($this->xRange["start"], 1), 2, '0', STR_PAD_LEFT);
215
$yStartStr = "+" . str_pad($this->yRange["start"], 2, '0', STR_PAD_LEFT);
216
if (substr($this->yRange["start"],0,1) == "-")
217
$yStartStr = "-" . str_pad(substr($this->yRange["start"], 1), 2, '0', STR_PAD_LEFT);
219
$xEndStr = "+" . str_pad($this->xRange["end"], 2, '0', STR_PAD_LEFT);
220
if (substr($this->xRange["end"],0,1) == "-")
221
$xEndStr = "-" . str_pad(substr($this->xRange["end"], 1), 2, '0', STR_PAD_LEFT);
223
$yEndStr = "+" . str_pad($this->yRange["end"], 2, '0', STR_PAD_LEFT);
224
if (substr($this->yRange["end"],0,1) == "-")
225
$yEndStr = "-" . str_pad(substr($this->yRange["end"], 1), 2, '0', STR_PAD_LEFT);
227
$filepath .= implode("_", array($this->unixTimestamp, $obs, $inst, $det, $meas, $this->zoomLevel, $xStartStr, $xEndStr, $yStartStr, $yEndStr, ".tif"));
b'\\ No newline at end of file'