001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:48:48 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33634 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.geon; 031 032import com.numericsolutions.geomodeltools.invdist_power_isosearch2d; 033 034//tokens 035import ptolemy.actor.TypedAtomicActor; 036import ptolemy.actor.TypedIOPort; 037import ptolemy.data.DoubleToken; 038import ptolemy.data.StringToken; 039import ptolemy.data.expr.FileParameter; 040import ptolemy.data.expr.Parameter; 041import ptolemy.data.expr.StringParameter; 042import ptolemy.data.type.BaseType; 043import ptolemy.kernel.CompositeEntity; 044import ptolemy.kernel.util.IllegalActionException; 045import ptolemy.kernel.util.NameDuplicationException; 046 047/** 048 * A grid interpolation actor. Currently only inverse distance is supported. 049 * 050 * @author Efrat Jaeger, John Harris 051 * @version $Id: Interpolate.java 33634 2015-08-24 22:48:48Z crawl $ 052 */ 053public class Interpolate extends TypedAtomicActor { 054 public Interpolate(CompositeEntity container, String name) 055 throws NameDuplicationException, IllegalActionException { 056 super(container, name); 057 input = new TypedIOPort(this, "input", true, false); 058 input.setTypeEquals(BaseType.STRING); // Push or Pull 059 output = new TypedIOPort(this, "output", false, true); 060 output.setTypeEquals(BaseType.STRING); 061 interpolationAlg = new StringParameter(this, "interpolationAlg"); 062 interpolationAlg.setExpression("inverse distance"); 063 interpolationAlg.addChoice("inverse distance"); 064 interpolationAlg.addChoice("minimum curvature"); 065 interpolationAlg.addChoice("nearest neighbor"); 066 interpolationAlg.addChoice("surface"); 067 outputFormat = new StringParameter(this, "outputFormat"); 068 outputFormat.setExpression("ESRI ascii grid"); 069 outputFormat.addChoice("ESRI ascii grid"); 070 outFile = new FileParameter(this, "outFile"); 071 outFile.setDisplayName("output File"); 072 latMin = new Parameter(this, "latMin"); 073 latMin.setTypeEquals(BaseType.DOUBLE); 074 latMax = new Parameter(this, "latMax"); 075 latMax.setTypeEquals(BaseType.DOUBLE); 076 longMin = new Parameter(this, "longMin"); 077 longMin.setTypeEquals(BaseType.DOUBLE); 078 longMax = new Parameter(this, "longMax"); 079 longMax.setTypeEquals(BaseType.DOUBLE); 080 xSpace = new Parameter(this, "xSpace"); 081 xSpace.setDisplayName("x grid spacing"); 082 xSpace.setTypeEquals(BaseType.DOUBLE); 083 ySpace = new Parameter(this, "ySpace"); 084 ySpace.setDisplayName("y grid spacing"); 085 ySpace.setTypeEquals(BaseType.DOUBLE); 086 coefficient = new Parameter(this, "coefficient"); 087 coefficient.setTypeEquals(BaseType.DOUBLE); 088 nullVal = new Parameter(this, "nullVal"); 089 nullVal.setDisplayName("null Value representation"); 090 nullVal.setTypeEquals(BaseType.DOUBLE); 091 searchRadius = new Parameter(this, "searchRadius"); 092 searchRadius.setDisplayName("set radius"); 093 searchRadius.setTypeEquals(BaseType.DOUBLE); 094 095 } 096 097 /** A string representation of the dataset */ 098 public TypedIOPort input; 099 100 /** A string representation of the gridded output */ 101 public TypedIOPort output; 102 103 // FIXME: currently supports only IDW. 104 /** The selected algorithm */ 105 public StringParameter interpolationAlg; 106 107 // NOTE: so far only esri ascii grid is supported. 108 /** The format of the interpolated result */ 109 public StringParameter outputFormat; 110 111 public FileParameter outFile; 112 /** Minimum latitude */ 113 public Parameter latMin; 114 115 /** Maximum latitude */ 116 public Parameter latMax; 117 118 /** Minimum longitude */ 119 public Parameter longMin; 120 121 /** Maximum longitude */ 122 public Parameter longMax; 123 124 /** Spacing between the grid cells */ 125 public Parameter xSpace; 126 127 /** Spacing between the grid cells */ 128 public Parameter ySpace; 129 130 /** Weight coefficient */ 131 public Parameter coefficient; 132 133 /** Representation of null values */ 134 public Parameter nullVal; 135 136 /** The search space */ 137 public Parameter searchRadius; 138 139 public void initialize() throws IllegalActionException { 140 } 141 142 public boolean prefire() throws IllegalActionException { 143 return super.prefire(); 144 } 145 146 public void fire() throws IllegalActionException { 147 try { 148 // TODO: take care of other algorithm and output format selection. 149 float xmin = (float) ((DoubleToken) latMin.getToken()) 150 .doubleValue(); 151 float xmax = (float) ((DoubleToken) latMax.getToken()) 152 .doubleValue(); 153 float ymin = (float) ((DoubleToken) longMin.getToken()) 154 .doubleValue(); 155 float ymax = (float) ((DoubleToken) longMax.getToken()) 156 .doubleValue(); 157 158 float dx = (float) ((DoubleToken) xSpace.getToken()).doubleValue(); 159 float dy = (float) ((DoubleToken) ySpace.getToken()).doubleValue(); 160 float nullval = (float) ((DoubleToken) nullVal.getToken()) 161 .doubleValue(); 162 163 float weight = (float) ((DoubleToken) coefficient.getToken()) 164 .doubleValue(); 165 float searchradius = (float) ((DoubleToken) searchRadius.getToken()) 166 .doubleValue(); 167 168 String dataFile = ((StringToken) input.get(0)).stringValue(); 169 dataFile = dataFile.trim(); 170 String gridFile = ((StringToken) outFile.getToken()).stringValue(); 171 172 invdist_power_isosearch2d gridder = new invdist_power_isosearch2d(); 173 174 gridder.execute(dataFile, gridFile, xmin, xmax, ymin, ymax, dx, dy, 175 nullval, weight, searchradius); 176 177 output.broadcast(new StringToken(gridFile)); 178 179 } catch (Exception ex) { 180 ex.printStackTrace(); 181 } 182 183 } 184}