- 积分
- 1586
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-3-23
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
begin
; 替换为你的MICAPS4文件路径
file_path = "25040608.000"
; 读取整个文件内容(跳过可能的UTF-8 BOM头)
lines = asciiread(file_path, -1, "string")
n_header = 2 ; 假设前两行为头信息
n_station = stringtofloat(str_get_field(lines(n_header-1),6," ")); 读取站点数
print(lines(0:2))
; 预分配数组
lon = new(dimsizes(lines)-2, "float")
lat = new(dimsizes(lines)-2, "float")
wind_dir = new(dimsizes(lines)-2, "float")
wind_str = new(dimsizes(lines)-2, "float")
do i = 0, n_station-1
lon(i) = stringtofloat(str_get_field(lines(i+2),2," "))
lat(i) = stringtofloat(str_get_field(lines(i+2),3," "))
wind_dir(i) = stringtofloat(str_get_field(lines(i+2),9," "))
wind_str(i) = stringtofloat(str_get_field(lines(i+2),10," "))
end do
;============================================================================================
;===========================================================================================
unique_coords = new(dimsizes(lines)-2, logical)
unique_coords = True
do i = 0, dimsizes(lines)-2-1
if (unique_coords(i)) then
matches = ind(lon.eq.lon(i) .and. lat.eq.lat(i))
if (dimsizes(matches).gt.1) then
print("发现重复坐标:索引 " + matches + "次数+"+i)
unique_coords(matches(1:)) = False
end if
delete(matches)
end if
end do
valid_indices = ind(unique_coords.and.wind_str.le.100);舍弃异常值
lon1 = lon(valid_indices)
lat1 = lat(valid_indices)
wind_str1 = wind_str(valid_indices)
printMinMax(wind_str1,1)
; 2. 设置目标网格参数(示例:中国区域)
latmin = 15.0
latmax = 55.0
lonmin = 70.0
lonmax = 140.0
dlat = 0.1 ; 网格分辨率
dlon = 0.1
nlat = toint((latmax-latmin)/dlat) + 1
nlon = toint((lonmax-lonmin)/dlon) + 1
lat_grid = fspan(latmin, latmax, nlat)
lon_grid = fspan(lonmin, lonmax, nlon)
; 3. 执行插值(使用自然邻域插值法natgrid)
temp_grid = natgrid(lon1, lat1, wind_str1, lon_grid, lat_grid)
printMinMax(temp_grid, 1)
; 4. 添加元数据描述
temp_grid!1 = "lat"
temp_grid!0 = "lon"
temp_grid&lat = lat_grid
temp_grid&lon = lon_grid
printVarSummary(temp_grid)
wks = gsn_open_wks("png", "temperature_grid")
res = True
res@gsnAddCyclic = False
res@cnFillOn = True
res@cnLinesOn = False
res@mpMinLatF = latmin
res@mpMaxLatF = latmax
res@mpMinLonF = lonmin
res@mpMaxLonF = lonmax
plot = gsn_csm_contour_map(wks, temp_grid, res)
end
|
|