你的位置:首页 > Java教程

[Java教程]Java代码实例


package Core.AtmRadi;import ij.ImagePlus;import ij.io.FileSaver;import ij.process.FloatProcessor;import ij.process.ImageProcessor;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import CommonUtil.CallModtran.CallModtran;import CommonUtil.FileIO.ReadSSRFile;import Core.AtmRadi.AtmCoreCalc.Band;import Core.AtmRadi.AtmCoreCalc.BandLsLh;import Core.AtmRadi.AtmCoreCalc.DiscreteLsLh;import Core.AtmRadi.AtmCoreCalc.GenDiscreteLsLh;import Core.AtmRadi.AtmCoreCalc.PathTerm;import Core.AtmRadi.AtmCoreCalc.SolveEq;import Core.AtmRadi.AtmCoreCalc.Tape7Columns;import Core.AtmRadi.AtmCoreCalc.Utility;import import import import public class AtmModule {  private String bandInfoPath;  private String atmParasPath;  private String refPath;  private String resultPath;  private String ;    private Map<String, String> parasMap;  private Map<String, String> parasMapLast;  private List<PathTerm> pathTermList;  private List<Band> bandInfoList;    public static void main( String[] args ) {        AtmModule atm = new AtmModule();    atm.init( "./MODIS", null, "./MOD09A1/ref.tif", "./");    try {      atm.run();    } catch (IOException e) {            e.printStackTrace();    }  }  private void setAtmParas(){        //解析对应的    List<AtmCondiEntity> atmCondiEntities = class );    List<GeoPathEntity> geoPathEntities = class );    List<SpectralEntity> spectralEntities = class );        parasMap = new HashMap<String, String>();        //Card1     parasMap.put( "MODEL", String.valueOf( atmCondiEntities.get(0).getAtmMode() ) );  //大气模式        //Card1A    parasMap.put( "H2OSTR", String.valueOf( atmCondiEntities.get(0).getH2O() ) );        //垂直水汽柱特性    parasMap.put( "O3STR", String.valueOf( atmCondiEntities.get(0).getO3() ) );        //垂直臭氧柱特性        //Card2    parasMap.put( "IHAZE", String.valueOf( atmCondiEntities.get(0).getAerosolMode() ) );        //气溶胶模式    parasMap.put( "VIS", String.valueOf( atmCondiEntities.get(0).getVis() ) );        //气象视距        //Card3    parasMap.put( "H2", String.valueOf( geoPathEntities.get(0).getTargetAltitude() ) );          //目标海拔高度    parasMap.put( "ANGLE", String.valueOf( geoPathEntities.get(0).getSatZenithAngle() ) );        //卫星天顶角        //Card3A1    parasMap.put( "IDAY", String.valueOf( geoPathEntities.get(0).getSequenceDay() ) );        //顺序天数        //Card3A2    parasMap.put( "PARM1", String.valueOf( geoPathEntities.get(0).getObservelati() ) );        //观测纬度    parasMap.put( "PARM2", String.valueOf( geoPathEntities.get(0).getObservelong() ) );        //观测经度    parasMap.put( "TIME", String.valueOf( geoPathEntities.get(0).getObserveTime() ) );        //观测时间        parasMap.put( "V1", String.valueOf( spectralEntities.get(0).getStartWvl() ) );          //起始波长    parasMap.put( "V2", String.valueOf( spectralEntities.get(0).getEndWvl() ) );          //终止波长  }    public AtmModule(){        parasMapLast = new HashMap<String, String>();    bandInfoList = new ArrayList<>();  }      public void init( String aBandInfoPath, String aAtmParasPath, String aRefPath, String aResultPath ){        bandInfoPath = aBandInfoPath;    atmParasPath = aAtmParasPath;    refPath = aRefPath;    resultPath = aResultPath;        setAtmParas();  }    public void run() throws IOException{        //===========================准备通道以及通道响应信息(SSR)==========================    File sensorFolder = new File( bandInfoPath );    String[]sensorBandFileName = sensorFolder.list( (dir,name)->name.endsWith("rsp") );        for( int i=0; i<sensorBandFileName.length; ++i ){  //有多少文件、就要准备多少多少个通道信息            String ssrFilePath = bandInfoPath+"/"+sensorBandFileName[i];      ReadSSRFile ssrFile = new ReadSSRFile( ssrFilePath );              Double waveLenDleta = 1.0;      ssrFile.FormSSR( waveLenDleta );          //让系统频谱响应的波长间隔是1nm      List<Double> wavelength = ssrFile.getLambda();    //得到SSR文件的波长列(插值后)      List<Double> ssr = ssrFile.getResponse();      //得到SSR文件各波长对应的系统频谱响应值列(插值后)      ssrFile.close();             Band tmpBand = new Band();      tmpBand.wavelength = wavelength;      tmpBand.ssr = ssr;            bandInfoList.add( tmpBand );      }        //==============================运行modtran过程=============================    final double rou1 = 0.3;  //设定两次运行时的反射率    final double rou2 = 0.8;        //两遍Modtran处理    CallModtran callModtran = new CallModtran( null, rou1, rou2, parasMap );    Tape7Columns tape7Cols = callModtran.getTape7Cols();        //=======================解方程;求解离散Ls、Lh;求解通道Ls、Lh====================================        //解方程    SolveEq solveEq = new SolveEq( tape7Cols, rou1, rou2 );    pathTermList = solveEq.getResults();        //计算离散的Ls、Lh(背景反射率暂且用0.5代替,待改成计算均值)    GenDiscreteLsLh genDiscreteLsLh = new GenDiscreteLsLh( pathTermList, 0.5 );    List<DiscreteLsLh> discreteLsLhsList = genDiscreteLsLh.getDiscreteLsLh();        //计算各通道Ls、Lh    List<BandLsLh> bandLsLh = Utility.integrate( discreteLsLhsList, bandInfoList, 1.0 );            //=======================由各个通道下的反射率计算该通道下的L=====================================    FileWriter fos = new FileWriter( "./LuminaceImageInfo" );    String formatTitle = "%s %s %s %s \n"; //标题格式    String format = "%s %f %f %f \n";     //文件内容格式    String title = String.format( formatTitle, "FILENAME", "START", "END", "CENTER" );    fos.write( title );        for( int bandIndex=0; bandIndex<bandLsLh.size(); ++bandIndex ){  //循环次数=通道数            ImagePlus refImage = new ImagePlus( refPath );      refImage.getProcessor().subtract( 32768.0 );      ImageProcessor ip = refImage.getProcessor().duplicate();      int h = ip.getHeight();      int w = ip.getWidth();      short[] sourcePixel = (short[]) ip.getPixels();      float[] resPixel = new float[h*w];            BandLsLh bandLsLhTmp = bandLsLh.get( bandIndex );            for( int i=0; i<h; ++i ) {              //全反射率图逐点遍历计算        for( int j=0; j<w; ++j ) {                    double ref = ( sourcePixel[i*h+j] )/10000.0;          resPixel[i*h+j] = (float)( ref*bandLsLhTmp.bandLs + bandLsLhTmp.bandLh );        }      }      ImageProcessor ipTmp = new FloatProcessor( w, h, resPixel );            String bandInfo = "band";      bandInfo+=bandLsLhTmp.centerWaveLen;      ImagePlus luminaceImg = new ImagePlus( bandInfo, ipTmp );                  FileSaver fs = new FileSaver( luminaceImg );      //fs.saveAsTiff( resultPath );      fs.save();            String info = String.format( format, null, bandLsLhTmp.startWaveLen, bandLsLhTmp.endWaveLen, bandLsLhTmp.centerWaveLen );      fos.write( info );    }        fos.close();  }  }