从netCDF读取数组,为什么我得到(1,1,n)的大小

问题描述 投票:2回答:1

我正在尝试阅读,然后从netcdf文件中绘制数据。我试图存储为变量的.nc文件中包含的一些数组被创建为(1,1,n)大小的变量。打印时我看到[[[数字,数字,....]]]。为什么这三个[[[创建?如何将这些变量作为简单的(n,1)数组读取?这是我的代码

import pandas as pd
import netCDF4 as nc
import matplotlib.pyplot as plt
from tkinter import filedialog
import numpy as np

file_path=filedialog.askopenfilename(title = "Select files", filetypes = (("all files","*.*"),("txt files","*.txt")))

file=nc.Dataset(file_path)
print(file.variables.keys()) # get all variable names

read_alt=file.variables['altitude'][:]
alt=np.array(read_alt)
read_b355=file.variables['backscatter'][:]
read_error_b355=file.variables['error_backscatter'][:]
b355=np.array(read_b355)
error_b355=np.array(read_error_b355)

变量alt很好,对于另外两个我有上述问题。

size netcdf4
1个回答
0
投票

您的变量 - 高度,反向散射和误差散射 - 是否可能具有多个维度?每当您加载这种数据时,netCDF库都会保留维度。

然而,我通常做的是,通过挤压它从阵列中删除我不需要的尺寸:

read_alt = np.squeeze(file.variables['altitude'][:])
read_b355 = np.squeeze(file.variables['backscatter'][:]);
read_error_b355 = np.squeeze(file.variables['error_backscatter'][:]);
© www.soinside.com 2019 - 2024. All rights reserved.