- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试获取 Sentinel 3 图像的月平均值时遇到了一些麻烦......一切,真的。 Python,Matlab,我们两个人都陷入了这个问题。
主要原因是这些图像的信息不在一个单独的 netcdf 文件中,与坐标和产品整齐地放在一起。相反,它们都位于一天文件夹中的单独文件中 different .nc files with different information each, about one single satellite image .据我所知,SNAP 使用 xmlxs 文件来处理所有这些单独的 .nc 文件。
现在,我认为尝试合并和创建/编辑 .nc 文件以创建一个新的日常 .nc 文件是个好主意,其中包括叶绿素、坐标,还不如加上时间。稍后,我将合并这些新的,以便能够使用 xarray 进行每月平均。至少那是我的想法,但我不能做第一部分。这可能是一个显而易见的解决方案,但这是我尝试过的,使用 xarray 模块
import os
import numpy as np
import xarray as xr
import netCDF4
from netCDF4 import Dataset
nc_folder = df_try.iloc[0] #folder where the image files are
#open dataset in xarray
nc_chl = xr.open_dataset(str(nc_folder['path']) + '/' + 'chl_nn.nc') #path to chlorophyll file
nc_chl
n_coord =xr.open_dataset(str(nc_folder['path'])+ '/'+ 'geo_coordinates.nc') #path to coordinates file
n_time = xr.open_dataset(str(nc_folder['path'])+ '/' + 'time_coordinates.nc') #path to time file
ds_grid = [[nc_chl], [n_coord], [n_time]]
combined = xr.combine_nested(ds_grid, concat_dim=[None, None])
combined #dataset with all but not recognizing coordinates
ds = combined.rename({'latitude': 'lat', 'longitude': 'lon', 'time_stamp' : 'time'}).set_coords(['lon', 'lat', 'time']) #dataset recognizing coordinates as coordinates
ds
它给出了一个数据集
维度:列 4865 行:4091
3 个坐标(纬度、经度和时间)和 chl 变量。
现在,它不会保存到 netcdf4(我试过但出现错误)但我也在想是否有人知道另一种计算平均值的方法?我有三年的图像(从 2017 年开始到 2019 年结束),我需要以不同的方式(每月、季节性......)进行平均。我目前的主要问题是叶绿素值与地理坐标是分开的,因此直接仅使用叶绿素文件是行不通的,只会弄得一团糟。
有什么建议吗?
最佳答案
这里有两个选项:
在 xarray 中,您可以将它们添加为坐标。这有点棘手,因为 geo_coordinates.nc
文件中的坐标也是多维的。
可能的解决方案如下:
import netCDF4
import xarray as xr
import matplotlib.pyplot as plt
# paths
root = r'C:<your_path>\S3B_OL_2_WFR____20201015.SEN3\chl_nn.nc' #set path to chl file
coor = r'C:<your_path>\S3B_OL_2_WFR____20201015.SEN3\geo_coordinates.nc' #set path to the coordinates file
# loading xarray datasets
ds = xr.open_dataset(root)
olci_geo_coords = xr.open_dataset(coor)
# extracting coordinates
lat = olci_geo_coords.latitude.data
lon = olci_geo_coords.longitude.data
# assign coordinates to the chl dataset (needs to refer to both the dimensions of our dataset)
ds = ds.assign_coords({"lon":(["rows","columns"], lon), "lat":(["rows","columns"], lat)})
# clip the image (add your own coordinates)
area_of_interest = ds.where((10 < ds.lon) & (ds.lon < 12) & (58 < ds.lat) & (ds.lat < 59), drop=True)
# simple plot with coordinates as axis
plt.figure(figsize=(15,15))
area_of_interest["CHL_NN"].plot(x="lon",y="lat")
更简单的方法是将它们作为变量添加到新数据集中:
# path to the folder
root = r'C:<your_path>\S3B_OL_2_WFR____20201015.SEN3\*.nc' #set path to chl file
# create a dataset by combining nc files (coordinates will become variables)
ds = xr.open_mfdataset(root,combine = 'by_coords')
但在这种情况下,当您绘制或裁剪图像时,您不能直接使用坐标。
在 python 中,snappy 包可用并基于 SNAP 工具箱(在 JAVA 上实现)。检查:https://senbox.atlassian.net/wiki/spaces/SNAP/pages/19300362/How+to+use+the+SNAP+API+from+Python
安装后(不幸的是,snappy 仅支持 python 2.7、3.3 或 3.4),您可以直接在 python 上使用可用的 SNAP 函数来聚合卫星图像并创建周/月平均值。然后您不需要合并 lon、lat netcdf 文件,因为您将处理 xfdumanifest.xml
,SNAP 会处理这件事。
这是一个例子。它还执行聚合(根据两个 chl nc 文件计算平均值):
from snappy import ProductIO, WKTReader
from snappy import jpy
from snappy import GPF
from snappy import HashMap
# setting the aggregator method
aggregator_average_config = snappy.jpy.get_type('org.esa.snap.binning.aggregators.AggregatorAverage$Config')
agg_avg_chl = aggregator_average_config('CHL_NN')
# creating the hashmap to store the parameters
HashMap = snappy.jpy.get_type('java.util.HashMap')
parameters = HashMap()
#creating the aggregator array
aggregators = snappy.jpy.array('org.esa.snap.binning.aggregators.AggregatorAverage$Config', 1)
#adding my aggregators in the list
aggregators[0] = agg_avg_chl
# set parameters
# output directory
dir_out = 'level-3_py_dynamic.dim'
parameters.put('outputFile', dir_out)
# number of rows (directly linked with resolution)
parameters.put('numRows', 66792) # to have about 300 meters spatial resolution
# aggregators list
parameters.put('aggregators', aggregators)
# Region to clip the aggregation on
wkt="POLYGON ((8.923302175377243 59.55648108694149, 13.488748662344074 59.11388968719029,12.480488185001589 56.690625338725155, 8.212366327767503 57.12425256476263,8.923302175377243 59.55648108694149))"
geom = WKTReader().read(wkt)
parameters.put('region', geom)
# Source product path
path_15 = r"C:<your_path>\S3B_OL_2_WFR____20201015.SEN3\xfdumanifest.xml"
path_16 = r"C:\<your_path>\S3B_OL_2_WFR____20201016.SEN3\xfdumanifest.xml"
path = path_15 + "," + path_16
parameters.put('sourceProductPaths', path)
#result = snappy.GPF.createProduct('Binning', parameters, (source_p1, source_p2))
# create results
result = snappy.GPF.createProduct('Binning', parameters) #to be used with product paths specified in the parameters hashmap
print("results stored in: {0}".format(dir_out) )
我是新手,对这个话题很感兴趣,很高兴听到您/其他的解决方案!
关于python - Sentinel3 OLCI (chl) Python 上 netcdf 文件的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64228381/
我有一个大小为 320x320 像素的阈值图像。我通过设置 ROI 以 20x20 像素的 block 循环遍历整个图像。我需要找到每个 block 的平均值。所以我将这些图像 block 传递给函数
我正在尝试学习 Javascript。我已经构建了以下代码来从一组数字中找到平均值。它有效除了最后返回的值总是 NaN。我不知道为什么。如果我将这 block 移到 block 外,它似乎完全忘记了变
假设我的数据已经分组,我该如何计算中位数和其他统计数据? Index Value Count 0 6 2 1 2 3 2 9 8 在上面
我试图计算的有趣情况。基本上在一行中,我有产品名称,其右侧的行是自首次收到产品以来经过的天数。 为 ex 计算的天数是 =TODAY()-BB2 我现在要做的是识别让我们说产品词“卡车”,然后计算卡车
我想知道如何计算某些数字的累积平均值。我将举一个简单的例子来描述我在寻找什么。 我有以下号码 vec 1) 为您的向量(或列表、一维数组或您如何称呼它)的每个元素评估此表达式,您将获得累积平均值。
我正在尝试对数据库表中的每一行进行平均。但它不能正常工作我想忽略该值,如果为空,它不会计算为零。使用我的代码,它将空值计算为零我想这样做 MS Excel 如果行/单元格为空,它将忽略。 Contro
我有以下信息(按 View 返回): DateTime ItemID UserTyp Seconds 2012-01-01 10 S 12 2012-01-01
我正在使用excel的average函数来获取欧洲各个城市一系列酒店价格的平均值。 =average(21,42,63,84,105) 我希望能够计算每个平均函数中的变量数量(例如,在上面的示例中有
我有一长串列,我想一次性计算非零中位数、平均值和标准差。我不能只删除基于 1 列的 0 行,因为同一列中另一列的值可能不是 0。 下面是我目前的代码,用于计算中位数、平均值等,包括零。 agg
这是我的问题: 我有一张这样的 table : Table Log int id; int time; timestamp DATE; int sid (FK to table Site);
JSON: [{"id":"1","user":"001","answer":"1,1,3,2,2,1,3,2"}, {"id":"2","user":"002","answer":"2,3,3,2,
有个问题: 使用适当的列名称,显示 obs 类型“CONT”的允许 ID 和平均 obs 值,其中 CONT 的平均 obs 值 >= 40。 假设承认是表1,观察是表2,但具有相同的主键Admit_
我有一个记录传感器数据的应用程序,我希望能够从多个传感器生成平均值,可以是一个、两个、三个或很多... 编辑:这些是温度传感器,因此 0 是传感器可能作为值存储在数据库中的值。 我最初的出发点是这个
我有这样一个数据框 id power flag 0 20 0 1 25 0 2 26 1 3 30 1 4 18 0 5
我想计算所有事件 blob 的平均位置。为此,首先我需要所有 X 和 Y 位置的总和。在这种情况下我该怎么做? contourFinder.findContours(grayImg, minB
我是一个十足的 Java 新手。上周一开始,之前从未用任何语言进行过任何编程。因此,如果我发现简单的事情变得复杂,请耐心等待。 我收到了一个文本文件。如下图: 第一个数据是时间(午夜过后的秒数),第二
我正在尝试为 Audacity 编写一个简单的测量插件,它就像用石头砸我的头骨一样有趣。我想要做的就是获取一段音频并找到所有样本的平均值(该 block 的 DC offset ),这样我就可以将它作
我正在尝试计算给定多边形内的值: 实际上我正在使用这个管道: 'aggregation': { 'pipeline': [ { "$match" : {
我有一个 pandas DataFrame,其中包含包含列表的列。我正在尝试获取此专栏中列表的方法。 这是我的 DataFrame 的示例: Loc Background 0
我尝试加速计算放置在数组中的4d向量的平均值。这是我的代码: #include #include #include #include #include #include typedef f
我是一名优秀的程序员,十分优秀!