time
作为Dimension
分配给xarray.DataSet
对象lat
/ lon
分配为Dimension
我已经从NOAA FTP服务here下载了植被健康数据。
帮助文档为here。
每周有2030
个文件,因此非常感谢您并行执行此操作。
In [0]: ls | wc -l
2030
主要问题是数据每周发送一次,没有time
维度(.nc
global attributes
中的天数和文件名中的year
除外) )。
对于名为'VHP.G04.C07.NH.P1992014.VH.nc'
的文件:
In [1]: xr.open_dataset('VHP.G04.C07.NH.P1992014.VH.nc')
Out[1]:
<xarray.Dataset>
Dimensions: (HEIGHT: 3616, WIDTH: 10000)
Dimensions without coordinates: HEIGHT, WIDTH
Data variables:
VCI (HEIGHT, WIDTH) float32 ...
TCI (HEIGHT, WIDTH) float32 ...
VHI (HEIGHT, WIDTH) float32 ...
QA (HEIGHT, WIDTH) float32 ...
Attributes:
VERSION: VH (vh.exe,version 1.3, March 21 2012)
SATELLITE: NH
INSTRUMENT: AVHRR
CITATION_TO_DOCUMENTS: User Guide of Vegetation Health(VH) system (vers...
CONTACT: NOAA/NESDIS/STAR/EMB
PRODUCT_NAME: Vegetation Health
PROJECTION: Plate_Carree
DATE_BEGIN: 92
DATE_END: 98
TIME_BEGIN: 00:00 UTC (use day time data only)
TIME_END: 23:59 UTC (use day time data only)
ANCILLARY_FILES: FILE_CONFIGURE:vh.config_NN\nFILE_PRELAUNCH_CALI...
CONFIGURE_FILE_CONTENT: [Options for vh.exe]\nDIR_Ancillary= ...
YEAR: 1992
PERIOD_OF_YEAR: 14
DAYS_PER_PERIOD: 7
END_LATITUDE_RANGE: -55.152
START_LONGITUDE_RANGE: -180.0
START_LATITUDE_RANGE: 75.024
END_LONGITUDE_RANGE: 180.0
INPUT_FILES: 2
INPUT_FILENAMES: data/AVHRR_VHP/4km/VH/VHP.G04.C07.NH.P1992014.SM...
因此,我希望使用xarray
:
time
存储为标量dimension
HEIGHT
和WIDTH
转换为latitude
和longitude
dimensions
将生成的xarray.Dataset
写入.nc
文件
所以我想要这样的东西(但具有cf-compliance):
<xarray.Dataset>
Dimensions: (latitude: 3616, longitude: 10000, time)
Dimensions without coordinates: latitude, longitude, time
Data variables:
VCI (latitude, longitude, time) float32 ...
TCI (latitude, longitude, time) float32 ...
VHI (latitude, longitude, time) float32 ...
QA (latitude, longitude, time) float32 ...
latitude (HEIGHT) float32 ...
longitude (WIDTH) float32 ...
time
存储为标量维度我想要这样做,以便以后可以使用cdo mergetime *.nc
将所有文件合并为一个.nc
文件
我已经研究出如何从.nc
文件中获取时间。
year = int(filename[-13:-9]) # 1992
day_begin = int(ds.attrs['DATE_BEGIN'])
day_end = int(ds.attrs['DATE_END'])
dt = datetime.datetime(year, 1, 1) + datetime.timedelta(day_begin - 1)
现在如何将其分配给坐标?该坐标将为标量。它还需要符合cf标准(例如Days since 1970-01-01
)
HEIGHT
和WIDTH
转换为latitude
和longitude
维度我还想转换HEIGHT
和WIDTH
尺寸。由于2018年的文件(例如'VHP.G04.C07.npp.P2018030.VH.nc'
)具有纬度/经度字段,因此变得更容易。
VHP.G04.C07.npp.P2018030.VH.nc
:In [2]: xr.open_dataset('VHP.G04.C07.npp.P2018030.VH.nc')
Out[2]:
<xarray.Dataset>
Dimensions: (HEIGHT: 3616, WIDTH: 10000)
Dimensions without coordinates: HEIGHT, WIDTH
Data variables:
VCI (HEIGHT, WIDTH) float32 ...
TCI (HEIGHT, WIDTH) float32 ...
VHI (HEIGHT, WIDTH) float32 ...
QA (HEIGHT, WIDTH) float32 ...
latitude (HEIGHT) float32 ...
longitude (WIDTH) float32 ...
PLATE_CARREE int32 ...
Attributes:
Conventions: CF-1.5
Metadata_Conventions: CF-1.5, Unidata Dataset Discovery v1.0
standard_name_vocabulary: CF Standard Name Table (version 17, 24 March 2...
project: S-NPP Data Exploitation
institution: DOC/NOAA/NESDIS/NDE > S-NPP Data Exploitation,...
naming_authority: gov.noaa.nesdis.nde
instrument_name: VIIRS
summary: Vegetation Health Product
history: Version 1
processing_level: NOAA Level 3
source: VIIRS-I1-SDR, VIIRS-I2-SDR, VIIRS-I5-SDR, ICCMO
references: User Guide of Vegetation Health (VH version 1....
cdm_data_type: grid
geospatial_lat_units: degrees_north
geospatial_lon_units: degrees_east
creator_name: DOC/NOAA/NESDIS/STAR > VHP Team, Center for Sa...
creator_email: Felix.kogan@noaa.gov
creator_url: http://www.star.nesdis.noaa.gov/smcd/emb/vci/VH/
publisher_name: DOC/NOAA/NESDIS/NDE > S-NPP Data Exploitation,...
publisher_email: espcoperations@noaa.gov
publisher_url: http://projects.osd.noaa.gov/NDE
PRODUCT_NAME: VH_2018_Week_30
PROJECTION: Plate Carree
time_coverage_start: 201807230000000
time_coverage_end: 201807292359599
ANCILLARY_FILES: File_Configure=control/VHconfig.viirs_weekly_4...
INPUT_FILENAMES: data/VIIRS/4km/VH/VGVI_21Bands.G04.C07.npp.P20...
version: v2r01,Sep 8 2017
satellite_name: npp
title: VH_2018_Week_30
YEAR: 2018
PERIOD_OF_YEAR: 30
DAYS_PER_PERIOD: 7
INPUT_FILES: 2
geospatial_lat_min: -55.151993
geospatial_lon_min: -180.0
geospatial_lat_max: 75.024
geospatial_lon_max: 180.0
CONFIGURE_FILE_CONTENT: #Options for VIIRS-VH weekly job processing (p...
如何提取这些经纬度Data variables
,将其存储为Coordinates
,然后将该文件中的坐标用作latitude
和longitude
的坐标我以前的文件(例如上面的'VHP.G04.C07.NH.P1992014.VH.nc'
。)
然后我要使用以下命令将其写入.nc
文件:
ds.to_netcdf('path/to/output')
对于第1部分和第2部分,我非常费劲,在处理此数据以及使用其他variables
的经纬度xarray.Dataset
方面提供的任何帮助将不胜感激。
如果您觉得我选择了错误的工具,我也将很感兴趣!