filecontroller
Class ReadImageFile

java.lang.Object
  extended by filecontroller.ReadImageFile

public class ReadImageFile
extends java.lang.Object

The ReadImageFile -class reads Portable GreyMap (PGM) images from Finnish Meteorological Institute's (FMI) radar, and converts them to form this program uses. The actual data is in polar coordinates, which is converted into PGM-images. In other words, one line represent here measurements from a specific direction. Measurements are calculated at intervals of 500 meters, and the furthest measure is as far as 250km. This means 500 measurement on one line. The single measurement is represented as a value between 0-254. Value 255 is a special case, it means that there is no measurement at this certain point. We convert the value x from PGM image to dBZ scale by formula: Z[dBZ] = 0.5 * x - 32 PGM files contains also a header part in the beginning of file, which is read and pulled apart before the actual data. Header could look like this: ---- P5 # SITE=VAN # DATA=Z # TASK=1 # SUBTASKS=6 # SWEEPS=3 # AZIMUTS=360 # TASKNAME=PPI1_F # VOLUMETIME=200802181130 # TASKTIME=20080218113035 # SWEEPTIMES=20080218113335 20080218113352 20080218113414 # RUNNINGTIMES=2 9 10 # ELEVATIONS=15.0 25.0 45.1 # BINS=108 66 40 # BINARYELEVATIONS=2731 4551 8192 # STARTAZIMUTS=360.2 360.2 360.2 # CALIPREFLS=-41.06 240 1080 ---- Most important values are ELEVATIONS and BINS, and the last line where is defined the width and height values of raw image. Note that we may have to render up to six PGM-images from different elevations into one weather -image.

Version:
1
Author:
Potkuri -group

Field Summary
private  java.awt.Color colorOfCornerArea
          Background color of corner area in weather -image.
private  java.awt.Color colorOfRadarArea
          Background color of radar area in weather -image.
private  int[] colorPalette
          Array of integer RGB colors.
private  int currentRadarPic
          Latest composed image.
private  java.lang.String dataDir
          Directory for PGM-images.
private  double[] elevations
          Elevations counter.
private  java.lang.String errorMessage
          Latest error message.
private  int filterWhiteNoise
          This value is used when removing noise from radar-image.
private  java.awt.image.BufferedImage mapImage
          Current Weather image.
private  int[][] mapMatrix
          Weather information in numeric array.
private  java.awt.image.BufferedImage offScreenImage
          Working area for Java 2D.
private  int originX
          X -coordinate of origin.
private  int originY
          Y -coordinate of origin.
private  Parameters parameters
          Current instance of Parameter class.
private  int pictureHeight
          Weather image height.
private  int pictureWidth
          Weather image width.
private  int[] radarBins
          Measurements in current image.
private  int[] radarImageSize
          Size of current PGM -image.
private  int radarPics
          Latest composed image.
private  double[] radarStartAzimuts
          Start direction between 0-360.
private  int renderMapHeight
          Render height.
private  int renderMapWidth
          Render width.
private  java.lang.Boolean status
          Status reveal if constructor or rendering fails.
private  int stormSensitivity
          Boundary of storm on dBZ-scale.
private  java.util.ArrayList<java.lang.String> weatherFiles
          List of images.
private  int weatherFilesPointer
          Pointer to current row.
 
Constructor Summary
ReadImageFile(Parameters parameters)
          Constructor of this class.
 
Method Summary
 java.lang.String getErrorMessage()
          Returns latest error message.
 java.awt.image.BufferedImage getMap()
          Returns rendered weather data in bufferedImage -format.
 int[][] getMapMatrix()
          Returns rendered weather data in integer matrix.
private  java.lang.String getPictureName()
          This method returns path and name of the next PGM-image in order.
private  int[] getPrintColorPalette()
          This method initialize a color palette, which is used when rendering storms from weather data into BufferedImage-object.
 boolean getStatus()
          Returns a current status of this instance.
private  boolean loadList(java.lang.String filename)
          Load user's weather data-list from file.
private  boolean loadPicture()
          Method renders a set of PGM-images to one weather scenario.
private  int[][] noiseFilter(int[][] temporaryMap)
          This method filters extra noise off from weather map.
private  boolean recognizeHeaderLine(java.lang.String headerLine, int headerNumber)
          Method tries to recognize PGM picture's current header line, and set the value of the header into program's data structure.
private  boolean renderWeathermapToBufferedImage()
          This method converts the weather data from integer matrix into bufferedImage.
 boolean update()
          Method renders next PGM -images from user's list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colorOfCornerArea

private java.awt.Color colorOfCornerArea
Background color of corner area in weather -image.


colorOfRadarArea

private java.awt.Color colorOfRadarArea
Background color of radar area in weather -image.


colorPalette

private int[] colorPalette
Array of integer RGB colors.


currentRadarPic

private int currentRadarPic
Latest composed image.


dataDir

private java.lang.String dataDir
Directory for PGM-images.


elevations

private double[] elevations
Elevations counter.


errorMessage

private java.lang.String errorMessage
Latest error message.


filterWhiteNoise

private int filterWhiteNoise
This value is used when removing noise from radar-image.


mapImage

private java.awt.image.BufferedImage mapImage
Current Weather image.


mapMatrix

private int[][] mapMatrix
Weather information in numeric array.


offScreenImage

private java.awt.image.BufferedImage offScreenImage
Working area for Java 2D.


originX

private int originX
X -coordinate of origin.


originY

private int originY
Y -coordinate of origin.


parameters

private Parameters parameters
Current instance of Parameter class.


pictureHeight

private int pictureHeight
Weather image height.


pictureWidth

private int pictureWidth
Weather image width.


radarBins

private int[] radarBins
Measurements in current image. This value is read from the header.


radarImageSize

private int[] radarImageSize
Size of current PGM -image. This value is read from the header.


radarPics

private int radarPics
Latest composed image.


radarStartAzimuts

private double[] radarStartAzimuts
Start direction between 0-360.


renderMapHeight

private int renderMapHeight
Render height.


renderMapWidth

private int renderMapWidth
Render width.


status

private java.lang.Boolean status
Status reveal if constructor or rendering fails.


stormSensitivity

private int stormSensitivity
Boundary of storm on dBZ-scale.


weatherFiles

private java.util.ArrayList<java.lang.String> weatherFiles
List of images.


weatherFilesPointer

private int weatherFilesPointer
Pointer to current row.

Constructor Detail

ReadImageFile

public ReadImageFile(Parameters parameters)
Constructor of this class. If constructor fails, the status of this instance is set as false.

Parameters:
parameters - Current parameter -class.
Method Detail

getErrorMessage

public java.lang.String getErrorMessage()
Returns latest error message.

Returns:
message

getMap

public java.awt.image.BufferedImage getMap()
Returns rendered weather data in bufferedImage -format.

Returns:
BufferedImage map

getMapMatrix

public int[][] getMapMatrix()
Returns rendered weather data in integer matrix. Values are represented on dBZ -scale.

Returns:
matrix

getPictureName

private java.lang.String getPictureName()
This method returns path and name of the next PGM-image in order. There may be up to six images in one set. On first round method returns the name of "A" -image, on second round the name of "B" -image and so on. When there is no more files in this set, method returns null.

Returns:
String Path of next PGM-image.

getPrintColorPalette

private int[] getPrintColorPalette()
This method initialize a color palette, which is used when rendering storms from weather data into BufferedImage-object. In practice, color values are stored into a integer matrix with 250 cells. The colors are represented in Java's RGM-mode.

Returns:
colors

getStatus

public boolean getStatus()
Returns a current status of this instance. If status is false, there probably is a new error message available.

Returns:
status

loadList

private boolean loadList(java.lang.String filename)
Load user's weather data-list from file. The list defines the PGM-images we use when rendering weather data.

Parameters:
filename - Name of user list, this comes from Parameter -class.
Returns:
load succeed

loadPicture

private boolean loadPicture()
Method renders a set of PGM-images to one weather scenario. Weather information is represented in numeric array, where values reflect weather fierceness on dBZ scale.

Returns:
render succeed

noiseFilter

private int[][] noiseFilter(int[][] temporaryMap)
This method filters extra noise off from weather map. Isolated pixels are removed by checking cell's neighbors, only cells which have enough stormy neighbors are counted in.

Parameters:
temporaryMap - matrix
Returns:
filterMap matrix

recognizeHeaderLine

private boolean recognizeHeaderLine(java.lang.String headerLine,
                                    int headerNumber)
Method tries to recognize PGM picture's current header line, and set the value of the header into program's data structure. Rather the headers are identified by it's header number, this is possible because the headers are always on same format.

Parameters:
headerLine - Current line.
headerNumber - Number of line.
Returns:
boolean

renderWeathermapToBufferedImage

private boolean renderWeathermapToBufferedImage()
This method converts the weather data from integer matrix into bufferedImage. BufferedImage is used later by Graphics- class.

Returns:
rendering succeed

update

public boolean update()
Method renders next PGM -images from user's list. Returns false if there is no more weather data, or if file not found.

Returns:
update succeed