- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在从事一个项目,该项目将原始二进制雷达数据从国家气象局 ftp 站点导入服务器。使用 Weather and Climate Toolkit 数据导出工具,我将数据转换为 netCDF 文件。以下是对 .nc 文件执行“ncdump -h”命令的结果:
netcdf last {
dimensions:
lat = 800 ;
lon = 1200 ;
time = 1 ;
variables:
double cref(time, lat, lon) ;
cref:long_name = "Level-III Composite Reflectivity (16 levels / 248 nm)" ;
cref:missing_value = -999. ;
cref:units = "dBZ" ;
double lat(lat) ;
lat:units = "degrees_north" ;
lat:spacing = "0.010995604400775773" ;
lat:datum = "NAD83 - NOAA Standard" ;
double lon(lon) ;
lon:units = "degrees_east" ;
lon:spacing = "0.010983926942902655" ;
lon:datum = "NAD83 - NOAA Standard" ;
int time(time) ;
time:units = "seconds since 1970-1-1" ;
// global attributes:
:title = "Level-III Composite Reflectivity (16 levels / 248 nm) 22:23:47 UTC 10/20/2016" ;
:Conventions = "CF-1.0" ;
:History = "Exported to NetCDF-3 CF-1.0 conventions by the NOAA Weather and Climate Toolkit (version 3.7.9) \n",
"Export Date: Thu Oct 20 16:11:07 EDT 2016" ;
:geographic_datum_ESRI_PRJ = "GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]" ;
:geographic_datum_OGC_WKT = "GEOGCS[\"NAD83\", DATUM[\"NAD83\", SPHEROID[\"GRS_1980\", 6378137.0, 298.25722210100002],TOWGS84[0,0,0,0,0,0,0]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\",0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]]" ;
}
我想找到 cref 变量的最大条目,我可以使用 python 中的 netCDF4 和 numpy 库很容易地做到这一点:
import netCDF4
import numpy
netcdf = netCDF4.Dataset("last.nc")
var = netcdf.variables['cref']
print(numpy.nanmax(var))
print(numpy.nanmin(var))
但是,我希望过滤 netCDF 文件,以便仅在给定纬度/经度的特定距离内找到最大值和最小值。换句话说,我希望围绕指定的纬度/经度“裁剪”一个指定半径的圆。我找到了 how to crop a square通过另一个 SO 线程,但无法弄清楚圆圈是如何工作的。
最佳答案
我会计算中心与每个纬度/经度对(二维网格)之间的距离,并使用它来构建一个可以应用于数据的 mask 。屏蔽后,您可以再次简单地使用 numpy
函数来计算统计数据,例如 max()
。
例如,使用 https://stackoverflow.com/a/4913653/3581217 中的 haversine()
函数,修改为矢量化版本,您可以直接将其应用于 numpy
数组:
import numpy as np
import matplotlib.pylab as pl
def haversine(lon1, lat1, lon2, lat2):
# convert decimal degrees to radians
lon1 = np.deg2rad(lon1)
lon2 = np.deg2rad(lon2)
lat1 = np.deg2rad(lat1)
lat2 = np.deg2rad(lat2)
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2
c = 2 * np.arcsin(np.sqrt(a))
r = 6371
return c * r
# Latitude / longitude grid
lat = np.linspace(50,54,16)
lon = np.linspace(6,9,12)
# Center coordinates
clat = 52
clon = 7
max_dist = 100 # max distance in km
# Calculate distance between center and all other lat/lon pairs
distance = haversine(lon[:,np.newaxis], lat, clon, clat)
# Mask distance array where distance > max_dist
distance_m = np.ma.masked_greater(distance, max_dist)
# Dummy data
data = np.random.random(size=[lon.size, lat.size])
# Test: set a value outside the max_dist circle to a large value:
data[0,0] = 10
# Mask the data array based on the distance mask
data_m = np.ma.masked_where(distance > max_dist, data)
pl.figure()
pl.subplot(221)
pl.title('distance (km)')
pl.pcolormesh(lon, lat, np.transpose(distance))
pl.colorbar()
pl.subplot(222)
pl.title('distance < max_dist (km)')
pl.pcolormesh(lon, lat, np.transpose(distance_m))
pl.colorbar()
pl.subplot(223)
pl.title('all data; max = {0:.1f}'.format(data.max()))
pl.pcolormesh(lon, lat, np.transpose(data))
pl.colorbar()
pl.subplot(224)
pl.title('masked data; max = {0:.1f}'.format(data_m.max()))
pl.pcolormesh(lon, lat, np.transpose(data_m))
pl.colorbar()
结果是:
关于python - 使用 Python 对 NetCDF 文件进行循环纬度/经度裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40177960/
我正在开发一个应用程序,用户可以在其中搜索其位置附近的项目。 当用户注册我的服务时,会获取他们的经/纬度坐标(这实际上是从邮政编码中获取的,然后通过 Google 查找经度/纬度坐标)。当用户添加一个
所以:我有以下函数,改编自在线找到的公式,它采用两个纬度/经度坐标并计算它们之间的距离(以英里为单位)(沿着球形地球): public static double distance (double l
我有一个给定点(经度、纬度),我想获取给定点 5 英里半径范围内的所有点范围? 最佳答案 我只是在这里猜测,但我认为您需要找到一种不同的方法。如果您尝试使用 Foursquare、Google map
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我找到了一些代码,用于将纬度/经度转换为给定图像上的像素,反之亦然。我将其移植到 JavaScript,但在纬度上得到了不正确的返回值。我测试了原始的、未修改的代码,它给出了同样的不准确之处。下面是带
我用了AstroPy EarthLocation 获取传播卫星轨道的纬度、经度和高度 loc = coord.EarthLocation(*itrs.cartesian.xyz)。现在,我尝试使用 n
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: how to do location based search Getting similar longit
我有一个超过 15000 个经纬度坐标的列表。给定任何 X、Y 坐标,在列表中找到最近坐标的最快方法是什么? 最佳答案 您将需要使用名为 Voronoi diagram 的几何结构。 .这将平面划分为
For people interested in this topic: the accepted answer involves some concepts that I think are wel
我的应用程序上有一张 map ,它显示 2 种注释:位置和位置集群。当我放大集群时,集群会展开以显示集群中包含的位置。当这些位置添加到 map 时,其父簇的坐标将存储在注释对象中。我想要做的是制作一个
关于纬度/经度计算的简单问题。 我想获取一个值集,例如Lat: 55.123456 Long -6.123456 并计算出任意距离的四个点。 作为给定的正方形,我想计算出左侧和右侧的纬度值。因此红线距
Postgis中Linestring中的点(由osm2pgsql从osm导入)按顺序描述(经度,纬度) 例如慕尼黑 map 中的线串 'LINESTRING(11.4068032 47.8580927
给定左上长/纬度和右下长/纬度,我如何确定给定的长/纬度是否落在矩形内? 理想情况下我会看类似的东西 bool IsWithinArea(float topLeftLat,float topLeftL
几天来,我一直在尝试让纬度/经度检查器、速度计、高度计工作,但似乎没有任何工作。我尝试过使用 Android 的内置 locationmanager 和 google play 服务。现在我回来尝试
我有经纬度形式的位置坐标,例如:23⁰ 39' 24.8"N & 58⁰ 11' 36.5"E,请参见下图。但是在我的工作场所我使用 ArcGIS 并且它似乎不支持度数(纬度,经度)形式的坐标。我现在
网上看了一些教程,发现LocationManager就是这样做的。这是我在网上找到的代码。但是,我不明白。为什么我不能得到长/纬度?为什么要经历所有“改变”位置的事情...... lm=(Locati
我一直在关注此网站的教程:' http://wptrafficanalyzer.in/blog/storing-google-maps-android-api-v2-marker-locations-
我需要使用用户当前的纬度/经度和数据库中存储的一些值进行一些计算。问题是 Location.getLatitude() 返回一个类似 4119778.0 的值,而我在数据库中的值保存为 41.1675
所以在 PostgreSQL 中,我有一堆 long/lat 的几何值,其格式如下: 0101000020E610000095B9F94674CF37C09CBF0985083B5040 所以在 Po
在 GoogleMap 中,有标记的纬度和经度概念。 MySQL 中的 Point 数据类型有两个坐标 x 和 y。我不知道 Point 的坐标代表什么;所以我想知道什么表示 Point 根据 Goo
我是一名优秀的程序员,十分优秀!