繁体   English   中英

在python中的netCDF文件中提取特定纬度/经度上的传感日期/时间

[英]Extracting the sensing date/time over a particular lat/lng in a netCDF file in python

我目前正在 python 中处理多个 netCDF 文件。 我在大伦敦使用 Sentinel-5P NO2 对流层柱。 我想将各个文件绘制为时间序列,标题为每个条带在伦敦上空的逾越节时间,但我不确定如何提取它。

有没有一种简单的方法可以为每个文件提取卫星在特定纬度/经度上的逾越时间?

编辑:有关文件的更多信息。 它们是 netCDF 文件,意味着它们包含维度、变量、属性和坐标。 它们包含空间分辨率为 3.5x7km 的伦敦上空 NO2 垂直柱密度的信息。 我已经在 PyCharm 中使用 xarray 打开了文件,并进一步附加了一个图像以提供有关变量的更多信息。

在此处输入图片说明

当纬度= 51.2 或 51.8 时,我基本上需要找到 delta_time 的值。 以下是我到目前为止开发的内容,但是我有大约 50 个文件,所有文件都超过 100,000 像素,所以这非常非常慢。 有谁知道我该如何改进?


    for i in file_list:

        # Open product - GROUP PRODUCT
        with xr.open_dataset(i, group='PRODUCT') as file:
            print(colored('\nPRODUCT Group:\n', 'blue'), file)

        no2 = file['nitrogendioxide_tropospheric_column'][0]

        for row in no2.coords['latitude']:
            for cell in row:
                if cell == 51.2 or cell == 51.8:
                    print(cell)
                    print(cell['scanline'])
                    scanpoint = (cell['scanline'])
                    scantime = no2['delta_time'].sel(scanline=scanpoint)
                    print(scantime)
                    return scantime
            else:
                continue

您应该能够使用矢量化的 NumPy 函数来做您想做的事。 现在,我不太确定比较浮动的相等性,但这应该与您的相似。 我没有专门使用 xarray 但使用过 netCDF4,所以它说<array>我的意思是为该变量/坐标获取一个 numpy(或等效)数组。 另外,请注意,我没有选择单个 time value ,它看起来像您拥有的,但我只是使用了整个 3D latitude数组。

import numpy as np

latitude = <3D latitudes array>
delta_time = <2D delta_time array>

# 3D boolean array with our required condition
condition = (latitude == 51.2) | (latitude == 51.8)

# Expand tuple of indices, one for each of the 3 dims, but ignore ground_pixel dim
# Each of these idx arrays is 1D
time_idx, scanline_idx, _ = condition.nonzero()

# Get 1D array of delta_times by using time and scanline indices
delta_times = delta_time[time_idx, scanline_idx]

这应该为您提供所有三个维度中所有相关单元格的坐标( condition.nonzero() ),以及这些单元格的delta_times

请注意,如果您不使用实际值并且只关心latitudedelta_time ,则不需要实际的no2数组,但您始终可以使用类似no2[condition]获取相关单元格的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM