Exemplo n.º 1
0
<?php

/**
 * Extract data from GRIB files filtering absolute temperature parameter
 * level type 100 (isobaric) and level values 1000,750,500,250
 * then prints data in CSV format
 */
require_once '../decoder/GribFileDecoder.php';
$messages = GribFileDecoder::loadFile('example.grb', array('parameters' => array(11), 'levelTypes' => array(100), 'levelValues' => array(1000, 750, 500, 250)));
echo "lat;lon;";
foreach ($messages as $message) {
    echo $message->levelValue . ";";
}
echo "\n";
for ($x = $messages[0]->gridDescription->longitudePoints - 1; $x >= 0; $x--) {
    for ($y = 0; $y < $messages[0]->gridDescription->latitudePoints; $y++) {
        $i = $x * $messages[0]->gridDescription->latitudePoints + $y;
        list($lat, $lon) = $messages[0]->getPointAt($i);
        echo "{$lat};{$lon};";
        foreach ($messages as $message) {
            echo number_format($message->getDataAt($i), 2, '.', '') . ";";
        }
        echo "\n";
    }
}
Exemplo n.º 2
0
<?php

/**
 * Read the land/sea mask parameter message from GRIB file and
 * generate a map representation from the message values
 */
require_once '../decoder/GribFileDecoder.php';
$messages = GribFileDecoder::loadFile('example.grb', array('parameters' => array(81)));
if (!sizeof($messages)) {
    die('Land/Sea parameter not found in file!');
}
$message = $messages[0];
$img = imagecreatetruecolor($message->gridDescription->longitudePoints, $message->gridDescription->latitudePoints);
$black = imagecolorallocate($img, 0, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255);
for ($i = 0; $i < $message->gridDescription->latitudePoints * $message->gridDescription->longitudePoints; $i++) {
    list($lat, $lon) = $message->getPointAt($i);
    $lat = $message->gridDescription->latitudePoints - ($lat - $message->gridDescription->latitudeFirstPoint) / $message->gridDescription->latitudinalIncrement;
    $lon = ($lon - $message->gridDescription->longitudeFirstPoint) / $message->gridDescription->longitudinalIncrement;
    $data = floor($message->getDataAt($i));
    if ($data) {
        imagesetpixel($img, $lon, $lat, $white);
    }
}
imagepng($img, 'landSeaMap.png');
imagedestroy($img);
Exemplo n.º 3
0
<?php

/*
 * Describe all GRIB messages contained in the example file.
 */
require_once '../decoder/GribFileDecoder.php';
require_once '../tables/GribParametersCPTEC.php';
//Load all messages in GRIB file (no filter)
$messages = GribFileDecoder::loadFile('example.grb');
foreach ($messages as $index => $message) {
    $levelType = $message->levelTypeId;
    $levelValue = $message->levelValue;
    $parameterId = $message->parameterId;
    $parameterDescription = "(" . $parameterId . " " . GribParametersCPTEC::getParameterAbbreviation($parameterId) . ") " . GribParametersCPTEC::getParameterDescription($parameterId);
    echo "Message {$index} contains parameter: {$parameterDescription} at level {$levelValue} of type {$levelType}.\n";
}