All Downloads are FREE. Search and download functionalities are using the official Maven repository.

decodes.comp.AreaComputation Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
/*
*  $Id$
*/
package decodes.comp;

import ilex.util.Logger;
import ilex.var.IFlags;
import ilex.var.NoConversionException;
import ilex.var.TimedVariable;

import java.util.Date;
import java.util.Enumeration;

/**
* Implements area table computations.
* Holds the lookup table & shift values.
* Delegates table reads to supplied reader.
*/
public class AreaComputation 
	extends Computation
	implements HasLookupTable
{
	private String module = "AreaComputation";

	/**
	* If true, apply shifts to independent variable before lookup.
	*/
	private boolean applyShifts;
	
	/**
	* Sensor number in PlatformConfig for independent variable
	*/
	private int indepSensorNum;
	
	/**
	 * Sensor number in PlatformConfig for Mean Velocity (XV)
	 */
	private int xvSensorNum;
	
	/**
	 * 
	 */
	private double xvScale;
	
	
	/**
	* Internal flag indicating whether tables
	* have been sorted.
	*/
	private boolean sorted;
	
	/**
	* The table of independent/dependent points for the rating.
	*/
	private LookupTable ratingTable;
	
	/**
	* A table of shift values.
	*/
	private LookupTable shiftTable;
	
	/**
	* The object used to read the table.
	*/
	private RatingTableReader tableReader;
	
	
	/**
	* Sensor number for the dependent (output) value.
	*/
	private int depSensorNum;
	
	
	/**
	* Beginning time for this rating. Only independent values after this time
	* will be processed.
	*/
	private Date beginTime;
	
	
	/**
	* Ending time for this rating. Only independent values before this time
	* will be processed.
	*/
	private Date endTime;
	
	/**
	  Adds a point to the table.
	  @param indep the independent value
	  @param dep the dependent value
	*/
	public void addPoint( double indep, double dep )
	{
		ratingTable.add(indep, dep);
	}
	
	/**
	  Adds a shift to the table.
	  @param indep the independent value
	  @param shift the shift value
	*/
	public void addShift( double indep, double shift )
	{
		shiftTable.add(indep, shift);
	}
	
	/**
	  Applies the rating to the data found in the passed
	  message. If successful, this will result in a new
	  TimeSeries containing the dependent variables.
	  @param msg the input data collection.
	*/
	public void apply( IDataCollection msg )
	{
		Logger.instance().debug3("Applying area rating calculation");
		// Retrieve independent time series.
		ITimeSeries indepTs = msg.getITimeSeries(indepSensorNum);
		if (indepTs == null)
		{
			Logger.instance().warning(module + 
				" Message does not contain independent sensor " +
				indepSensorNum);
			return;
		}

		String name = getProperty("DepName");
		if (name == null)
			name = "anon";

		ITimeSeries depTs = msg.newTimeSeries(depSensorNum, name);
		Logger.instance().debug3("Created dep sensor " + depSensorNum + ": " + name);
		depTs.setDataOrder(indepTs.getDataOrder());
		depTs.setPeriodicity(indepTs.getRecordingMode(), 
			indepTs.getTimeOfFirstSample(), indepTs.getTimeInterval());
		String s = getProperty("DepEpaCode");
		if (s != null)
			depTs.addDataType("EPA-Code", s);
		s = getProperty("DepShefCode");
		if (s != null)
			depTs.addDataType("SHEF-PE", s);

/////// THIS IS THE ONLY HOLE
//		ps.site = indepSensor.getSensorSite();
////////

		s = getProperty("DepUnits");
		if (s != null)
			depTs.setUnits(s);

		// For each indep sample, lookup dep value & add to new time series.
		int sz = indepTs.size();
		for(int i=0; i 0)
			{
				Logger.instance().warning(
					"Skipping area computation because sample time is"
					+ " outside the rating time range.");
				continue;
			}
			try
			{
				//Find area for the HG value - comes from the area files
				double area = ratingTable.lookup(indepTv.getDoubleValue());
				Logger.instance().info(module + " Area for " + 
						indepTv.getDoubleValue() + " is " + area);
				//multiply the area by the XV value sensor. Note the XV value
				//has a scale value, this value is multiplied by the XV value
				//before doing this equation
				double xvValue = 0;//Mean velocity
				//Find the XV value for this timestamp
				ITimeSeries xvTs = msg.getITimeSeries(xvSensorNum);
				if (xvTs == null)
				{
					Logger.instance().warning(module + 
						" Message does not contain xv (mean velocity) sensor " +
						xvSensorNum);
					return;
				}
				int xvz = xvTs.size();
				for(int x=0; x




© 2015 - 2024 Weber Informatics LLC | Privacy Policy