将浮点数转换为netcdf文件中的字节 [英] converting float to byte in netcdf file
问题描述
我有一个很大的netcdf文件,其中的标准float字段仅包含0.0或1.0.我想从命令行将其转换为字节类型,以节省一些空间,并且还可以更轻松地在数组中将其读取为fortran中的字节类型.
I have a large netcdf file with a standard float field which consists of only 0.0 or 1.0. I would like to convert it to a byte type from the command line to save some space and also make it easier to read in the array to a byte type in fortran.
我尝试使用ncap
ncap -s 'fire=byte(fire)' CAMS_2003-2017_frp_mask2_africa_zip.nc test.nc
但是似乎所有字段都为零.我在源文件上使用了zip_6 netcdf4压缩,所以不确定是否会使问题复杂化?
but it just seems to zero all the fields. I was using zip_6 netcdf4 compression on the source file, I'm not sure if that complicates matters?
更新:我发现ncap2可用于字节
UPDATE: I found that ncap2 works with byte
ncap2 -s 'fire=byte(fire)' CAMS_2003-2017_frp_mask2_africa_zip.nc test.nc
但是我不明白为什么两者不同?这可能是内存问题,因为当尝试转换为"int"而不是"byte"时,ncap和ncap2都无法进行内存分配.
But I don't understand why the two differ? It may be a memory issue, as both ncap and ncap2 fail with memory allocation when trying to convert to "int" instead of "byte".
推荐答案
我发现了两种方法:
cdo -b I8 copy in.nc out.nc
或
ncap2 -s 'fire=byte(fire)' in.nc out.nc
这篇关于将浮点数转换为netcdf文件中的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!