Какое ключевое слово использовать для извлечения данных из файла netCDF ⇐ Python

Программы на Python
Anonymous
Какое ключевое слово использовать для извлечения данных из файла netCDF

Сообщение Anonymous »

Заголовок файла netCDF гласит:
netcdf gpw_v4_population_density_rev11_2pt5_min {
dimensions:
longitude = 8640 ;
latitude = 4320 ;
raster = UNLIMITED ; // (20 currently)
variables:
double longitude(longitude) ;
longitude:units = "degrees_east" ;
longitude:long_name = "longitude" ;
double latitude(latitude) ;
latitude:units = "degrees_north" ;
latitude:long_name = "latitude" ;
int raster(raster) ;
raster:units = "unknown" ;
raster:long_name = "raster" ;
float Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes(raster, latitude, longitude) ;
Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes:units = "Persons per square kilometer" ;
Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes:_FillValue = -3.4e+38f ;
Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes:missing_value = -3.4e+38f ;
Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes:long_name = "Population Density, v4.11 (2000, 2005, 2010, 2015, 2020): 2.5 arc-minutes" ;
Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes:min = 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 4., 0., 0., 0., -9999., -9999., 0., 0., 0., 0. ;
Population\ Density\,\ v4.11\ \(2000\,\ 2005\,\ 2010\,\ 2015\,\ 2020\)\:\ 2.5\ arc-minutes:max = 52542.421875, 53915.54296875, 59666.02734375, 78523.484375, 103340.84375, 207., 767642., 3., 21.5139427185059, 21.5139389038086, 32767., 6., 2015., 6., 6., 6., 2011., 2015., 4., 2016. ;

// global attributes:
:proj4 = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" ;
:Conventions = "CF-1.4" ;
:created_by = "R, packages ncdf4 and raster (version 2.8-4)" ;
:date = "2018-11-16 10:27:52" ;

Я стараюсь читать как обычно с помощью:
import netCDF4 as nc
import numpy as np
import numpy.ma as ma

sample_file = "/home/ubuntu/POP/gpw_v4_population_density_rev11_2pt5_min.nc"
sample_dataset = nc.Dataset(sample_file)
T_latitudes = sample_dataset.variables["latitude"][:]
T_longitudes = sample_dataset.variables["longitude"][:]
popu1 = sample_dataset.variables["Population"][:]

Это работает для широт и долгот (как и ожидалось), но я не уверен, какой синтаксис является правильным для извлечения различных групп населения. Я безуспешно пробовал несколько синтаксисов, но приведенный выше привел к ошибке:
KeyError: 'Population'


Подробнее здесь: https://stackoverflow.com/questions/790 ... etcdf-file

Вернуться в «Python»