注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿弥陀佛

街树飘影未见尘 潭月潜水了无声 般若观照心空静...

 
 
 

日志

 
 
关于我

一直从事气象预报、服务建模实践应用。 注重气象物理场、实况场、地理信息、本体知识库、分布式气象内容管理系统建立。 对Barnes客观分析, 小波,计算神经网络、信任传播、贝叶斯推理、专家系统、网络本体语言有一定体会。 一直使用Java、Delphi、Prolog、SQL编程。

网易考拉推荐

realVector Test  

2015-06-15 17:44:48|  分类: Scala |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
package rae2latlon
import java.io.ByteArrayInputStream
import ucar.nc2.{NetcdfFileWriter, NetcdfFile}
import ucar.nc2.ncml.NcMLReader

/**
* Created by hjn on 2015/6/8.
*/
object realVector {
val yyRadar=(29.29966,113.10308)
//val jzRadar=(30.352115,112.148)
val jzRadar=(30.332115,112.078)
val lowerLeftLat=math.min(yyRadar._1,jzRadar._1)
val lowerLeftLon=math.min(yyRadar._2,jzRadar._2)
val nLat=(math.abs(jzRadar._1-yyRadar._1)*100).toInt
val nLon=(math.abs(jzRadar._2-yyRadar._2)*100).toInt
val nAlt=8

println(lowerLeftLat,lowerLeftLon,nLat,nLon)

def main(args: Array[String]) {
val jingzhou = readV("D:\\工作\\东方之星\\公共区域风场\\Z_RADR_I_Z9716_20150601131900_O_DOR_SA_CAP.nc")
val yueyang =readV("D:\\工作\\东方之星\\公共区域风场\\Z_RADR_I_Z9730_20150601132000_O_DOR_SB_CAP.nc")
val ncPath="D:\\工作\\东方之星\\公共区域风场\\RealVector.nc"
makeNcFileFromNcml(ncPath)
println(jingzhou(5)(300)(300))
calculateRealVector(jingzhou,yueyang,ncPath)
}
def readV(ncFnm:String): AS3 ={
val nfsrc = NetcdfFile.open(ncFnm)
val nRowsrc = nfsrc.readSection("lat").getSize().toInt
val nColsrc = nfsrc.readSection("lon").getSize().toInt
val nAlt = nfsrc.readSection("level").getSize().toInt
println(nAlt,nRowsrc,nColsrc)
//println(nRowsrc, nColsrc, lat0src, lon0src)
val elesrc = getMat3D(nfsrc, "RadialVelocity",nAlt, nRowsrc, nColsrc)
println(elesrc(5)(300)(300))
nfsrc.close()
elesrc
}
type AS3 = Array[Array[Array[Short]]]
def getMat3D(nf: NetcdfFile, nm: String,nz:Int, ny: Int, nx: Int): AS3 = {
val a = nf.readSection(nm).copyTo1DJavaArray().asInstanceOf[Array[Short]]
val mat=a.grouped(nx*ny).toArray.map(f=>f.grouped(nx).toArray)
mat
}
def realVector(lat:Double ,lon:Double , yySpd:Double , jzSpd:Double): (Double, Double) = {

val yyVectorK = (lat - yyRadar._1) / (lon - yyRadar._2)
val phi1 = if((lat - yyRadar._1)>0)math.atan(yyVectorK) else math.atan(yyVectorK)+math.Pi/2
val yyCentralK = -1 / yyVectorK
val yyVectorB = math.sin(phi1) * yySpd

val jzVectorK = (lat - jzRadar._1) / (lon - jzRadar._2)
val phi2 = if((lat - jzRadar._1)>0)math.atan(jzVectorK) else math.atan(jzVectorK)+math.Pi/2
val jzCentralK = -1 / jzVectorK
val jzVectorB = math.sin(phi2) * jzSpd

val x = (yyVectorB - jzVectorB) / (jzCentralK - yyCentralK)
val y = x * yyCentralK + yyVectorB
//println("center:" + x, y)
val u = (x - lon) * 2
val v = (y - lat) * 2
(-u, -v)
}

def calculateRealVector(nc1:AS3,nc2:AS3,ncFnm:String): Unit ={

val nc: NetcdfFileWriter = NetcdfFileWriter.openExisting(ncFnm)
val u:AS3=Array.fill[Short](nAlt,nLat,nLon)(0.toShort)
val v:AS3=Array.fill[Short](nAlt,nLat,nLon)(0.toShort)
val w:AS3=Array.fill[Short](nAlt,nLat,nLon)(0.toShort)
var max:Short= -9999

for(k <- 0 until nAlt)
for(i <- 0 until nLat)
for(j <- 0 until nLon){
if(nc1(k)(240-nLat+i)(270 + j)!= -9999 && nc2(k)(240 + i)(270-nLon+j)!= -9999) {
//println(nc1(k)(240-nLat+i)(270 + j),nc2(k)(240 + i)(270-nLon+j))
val temp=realVector(yyRadar._1+i/100.0,jzRadar._2+j/100.0,nc1(k)(240-nLat+i)(270 + j),nc2(k)(240 + i)(270-nLon+j))
u(k)(i)(j) = (1 * temp._1).toShort
v(k)(i)(j) = (1 * temp._2).toShort
if(i > 0 && j>0 && i< nLat-1 && j<nLon-1) {
//val dU=
w(k)(i)(j) = (-(u(k)(i)(j) - u(k)(i - 1)(j - 1)) + (v(k)(i)(j) - v(k)(i - 1)(j - 1))).toShort
}
}
}
appendGrids(nc,u,"u")
appendGrids(nc,v,"v")
appendGrids(nc,w,"w")
nc.close()
}

def appendGrids(nc: NetcdfFileWriter, grids: AS3,variableNm:String) {
val variable = nc.findVariable(variableNm)
//val a = ucar.ma2.Array.factory(grids)
//nc.write(variable, a)

val c= ucar.ma2.Array.factory(grids)
nc.write(variable, c)
}
def makeNcFileFromNcml(ncFnm: String) {
val ncml = ncmlTemp()
val inputStream = new ByteArrayInputStream(ncml.getBytes("UTF-8"))
NcMLReader.writeNcMLToFile(inputStream, ncFnm)
}
def ncmlTemp() = {
val gridsize=0.01
val altLevels = Array[Int](10, 15, 20, 25, 30,35, 40, 45).map(_ * 100)

s"""<?xml version="1.0" encoding="UTF-8"?>\n""".stripMargin +
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<dimension name="level" length={ nAlt.toString} />
<dimension name="time" length="1" isUnlimited="true" />
<dimension name="lat" length={ nLat.toString} />
<dimension name="lon" length={ nLon.toString} />
<attribute name="StationName" value="Z9771"/>
<attribute name="description" value="雷达重合区域真实风场" />
<attribute name="history" value="Created Fri Apr 10 11:38:17 2015" />
<attribute name="source" value="PWSC of CMA" />
<!--attribute name="centerLat" type="double" value={centerLat.toString} /-->
<!--attribute name="centerLon" type="double" value={centerLon.toString} /-->
<attribute name="lowerLeftLat" type="double" value={lowerLeftLat.toString} />
<attribute name="lowerLeftLon" type="double" value={lowerLeftLon.toString}/>
<attribute name="gridsize" type="double" value={ gridsize.toString } />
<attribute name="dataType" value="i2" />
<variable name="time" shape="time" type="double">
<attribute name="units" type="String" value="seconds since 0001-01-01 00:00:00" />
<attribute name="calendar" value="gregorian" />
</variable>
<variable name="level" shape="level" type="int">
<attribute name="long_name" type="String" value="高度"/>
<attribute name="units" type="String" value="m"/>
<values>{altLevels.mkString(" ")} </values>
</variable>
<variable name="latitude" shape="lat" type="double">
<attribute name="long_name" type="String" value="纬度"/>
<attribute name="units" value="degree" />
<values start = {lowerLeftLat.toString} increment="0.01"/>
</variable>
<variable name="longitude" shape="lon" type="double">
<attribute name="long_name" type="String" value="经度"/>
<attribute name="units" value="degree" />
<values start = {lowerLeftLon.toString} increment="0.01"/>
</variable>
<variable name="u" shape="level lat lon" type="short">
<attribute name="units" value="ms" />
</variable>
<variable name="v" shape="level lat lon" type="short">
<attribute name="units" value="ms" />
</variable>
<variable name="w" shape="level lat lon" type="short">
<attribute name="units" value="ms" />
</variable>
</netcdf>.toString
}
}
  评论这张
 
阅读(334)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017