重新填充并重新投影NETCDF以匹配Geotiff Python

2024-06-12 22:22:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在netcdf中有ERA5气候数据,在将ERA5数据从每小时转换为每天,并将它们计算在一起以得到一个每日产品后,我需要在该气候数据和一组GeoTIFF中相同地理区域的相应像素之间进行一些计算,具有更高的空间分辨率和不同的投影。netCDF在EPSG 4326中进行了投影,并配有lat/lon瓷砖。geotiff的分辨率更高(3.125km2),并在南极投影中投影。我已经在QGIS中一起打开了netcdf和GeoTIFF,并验证了一切正常,并且它们匹配

我一直不确定如何实现这一点,但我的感觉是,我需要重新投影原始netCDF以匹配Geotiff,同时重新填充/上采样netCDF数据,以便像素匹配

有没有办法简单地“匹配”这两个文件

(我曾尝试在gdal中重新投影,并在python中手动设置新投影,这不会导致任何错误,但也不会创建任何文件!-只是什么都没有发生:

import gdal


path = '//Users/gj/Documents/Sea Ice Project/AutoSeaIceProduc/adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc'#Path to file
out = '//Users/gj/Documents/Sea Ice Project/AutoSeaIceProduc/ReprojectedTest.nc'#Path to file

gdal.Warp(out,path, srcSRS='EPSG:4326',dstSRS='EPSG:3976')

NetCDF的Gdal信息:

Driver: netCDF/Network Common Data Format
Files: adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc
       adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc.aux.xml
Size is 512, 512
Metadata:
  NC_GLOBAL#Conventions=CF-1.6
  NC_GLOBAL#history=2021-04-15 19:39:59 GMT by grib_to_netcdf-2.16.0: /opt/ecmwf/eccodes/bin/grib_to_netcdf -S param -o /cache/data8/adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc /cache/tmp/93fbbedb-7e77-4565-ba2b-05ef0e8b1c71-adaptor.mars.internal-1618515503.360069-11959-2-tmp.grib
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":u10
  SUBDATASET_1_DESC=[720x13x85] u10 (16-bit integer)
  SUBDATASET_2_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":v10
  SUBDATASET_2_DESC=[720x13x85] v10 (16-bit integer)
  SUBDATASET_3_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":d2m
  SUBDATASET_3_DESC=[720x13x85] d2m (16-bit integer)
  SUBDATASET_4_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":t2m
  SUBDATASET_4_DESC=[720x13x85] t2m (16-bit integer)
  SUBDATASET_5_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":sp
  SUBDATASET_5_DESC=[720x13x85] surface_air_pressure (16-bit integer)
  SUBDATASET_6_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":ssrd
  SUBDATASET_6_DESC=[720x13x85] surface_downwelling_shortwave_flux_in_air (16-bit integer)
  SUBDATASET_7_NAME=NETCDF:"adaptor.mars.internal-1618515503.3594973-11959-19-93fbbedb-7e77-4565-ba2b-05ef0e8b1c71.nc":strd
  SUBDATASET_7_DESC=[720x13x85] strd (16-bit integer)
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)  

样本geotiff的相关gdal信息

Driver: GTiff/GeoTIFF
Files: clip_asi-AMSR2-s3125-20200301-v5.4.tif
Size is 117, 163
Coordinate System is:
PROJCRS["IDL GeoTIFF Suport
Projection = Polar Stereographic
True scale:      -70.0000deg
Gunnar Spreen, Apr 2004",
    BASEGEOGCRS["WGS 84",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
    CONVERSION["Polar Stereographic (variant B)",
        METHOD["Polar Stereographic (variant B)",
            ID["EPSG",9829]],
        PARAMETER["Latitude of standard parallel",-70,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8832]],
        PARAMETER["Longitude of origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8833]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["(E)",north,
            MERIDIAN[90,
                ANGLEUNIT["degree",0.0174532925199433,
                    ID["EPSG",9122]]],
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["(N)",north,
            MERIDIAN[0,
                ANGLEUNIT["degree",0.0174532925199433,
                    ID["EPSG",9122]]],
            ORDER[2],
            LENGTHUNIT["metre",1]]]
Data axis to CRS axis mapping: 1,2
Origin = (-1810937.500000000000000,-554687.500000000000000)
Pixel Size = (3125.000000000000000,-3125.000000000000000)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_DATETIME=2020:03:02 05:15:07
  TIFFTAG_DOCUMENTNAME=/ssmi/www/htdocs/data/amsr2/asi_daygrid_swath/s3125/2020/mar/Amundsen/asi-AMSR2-s3125-20200301-v5.4.tif
  TIFFTAG_IMAGEDESCRIPTION=IDL TIFF file
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_SOFTWARE=IDL 8.1, ITT Visual Information Solutions
  TIFFTAG_XRESOLUTION=100
  TIFFTAG_YRESOLUTION=100
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-1810937.500, -554687.500) (107d 1'47.10"W, 72d38'40.82"S)
Lower Left  (-1810937.500,-1064062.500) (120d26'14.82"W, 70d47' 7.34"S)
Upper Right (-1445312.500, -554687.500) (110d59'45.57"W, 75d46'46.47"S)
Lower Right (-1445312.500,-1064062.500) (126d21'39.97"W, 73d32'29.83"S)
Center      (-1628125.000, -809375.000) (116d25'58.56"W, 73d19'46.09"S)

Tags: nameidbitnetcdfintegerepsgdescinternal