hima8_pv/nc文件加载出太阳辐照数据.ipynb

14 KiB
Raw Blame History

In [1]:
import numpy as np
import netCDF4 as nc
In [10]:
from osgeo import gdal, osr, ogr
In [3]:
data = r"D:\Datasets\Himawari\pub\L2_PAR\20221107\18\H08_20221107_1800_RFL020_FLDK.02401_02401.nc"
nc_data = nc.Dataset(data)
nc_data
Out[3]:
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
    title: Himawari-08 AHI equal latitude-longitude map data
    id: H08_20221107_1800_RFL020_FLDK.02401_02401.nc
    date_created: 2022-11-07T18:25:18Z
    pixel_number: 2401
    line_number: 2401
    upper_left_latitude: 60.0
    upper_left_longitude: 80.0
    grid_interval: 0.05
    band_number: 6
    algorithm_version: 0201
    Ancillary meteorological data: JMA forcast
    Ancillary ozone data: JMA objective analysis
    BRDF correction: on (Morel and Maritorena 2001)
    dimensions(sizes): latitude(2401), longitude(2401), band(6), time(1), geometry(17)
    variables(dimensions): float32 latitude(latitude), float32 longitude(longitude), int32 band_id(band), float64 start_time(time), float64 end_time(time), float64 geometry_parameters(geometry), int16 TAOT_02(latitude, longitude), int16 TAAE(latitude, longitude), int16 PAR(latitude, longitude), int16 SWR(latitude, longitude), int16 UVA(latitude, longitude), int16 UVB(latitude, longitude), uint8 QA_flag(latitude, longitude)
    groups: 
In [4]:
list(nc_data.variables.keys())
Out[4]:
['latitude',
 'longitude',
 'band_id',
 'start_time',
 'end_time',
 'geometry_parameters',
 'TAOT_02',
 'TAAE',
 'PAR',
 'SWR',
 'UVA',
 'UVB',
 'QA_flag']
In [5]:
nc_data['PAR']
Out[5]:
<class 'netCDF4._netCDF4.Variable'>
int16 PAR(latitude, longitude)
    long_name: Photosynthetically active radiation
    units: umol/m^2/s
    scale_factor: 0.1
    add_offset: 0.0
    valid_min: 0
    valid_max: 25000
    missing_value: -32768
unlimited dimensions: 
current shape = (2401, 2401)
filling on, default _FillValue of -32767 used
In [6]:
nc_data['latitude']
Out[6]:
<class 'netCDF4._netCDF4.Variable'>
float32 latitude(latitude)
    long_name: latitude
    units: degrees_north
unlimited dimensions: 
current shape = (2401,)
filling on, default _FillValue of 9.969209968386869e+36 used
In [7]:
par = np.asarray(nc_data['PAR'][:])
par
Out[7]:
array([[  0.     ,   0.     ,   0.     , ...,   0.     ,   0.     ,
          0.     ],
       [  0.     ,   0.     ,   0.     , ...,   0.     ,   0.     ,
          0.     ],
       [  0.     ,   0.     ,   0.     , ...,   0.     ,   0.     ,
          0.     ],
       ...,
       [  0.     ,   0.     ,   0.     , ..., 181.6    , 139.7    ,
        144.40001],
       [  0.     ,   0.     ,   0.     , ..., 201.6    , 318.6    ,
        169.7    ],
       [  0.     ,   0.     ,   0.     , ..., 240.8    , 338.9    ,
        340.1    ]], dtype=float32)
In [14]:
import pandas as pd
In [42]:
lat = list(map(lambda x: round(x, 2), np.asarray(nc_data['latitude'][:])))
lon = list(map(lambda x: round(x, 2), np.asarray(nc_data['longitude'][:])))
print(len(lat), len(lon))
latMin, latMax, lonMin, lonMax = min(lat), max(lat), min(lon), max(lon)
2401 2401
In [9]:
# 分辨率
lat_Res = (latMax - latMin) / (lat.shape[0]-1)
lon_Res = (lonMax - lonMin) / (lon.shape[0]-1)
In [53]:
cols = [str(x) for x in lat]
rows = [str(x) for x in lon]
In [54]:
par_df = pd.DataFrame.from_records(par)
par_df.columns = cols
par_df.index = rows
In [58]:
par_df.tail()
Out[58]:
60.0 59.95 59.9 59.85 59.8 59.75 59.7 59.65 59.6 59.55 ... -59.55 -59.6 -59.65 -59.7 -59.75 -59.8 -59.85 -59.9 -59.95 -60.0
199.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 160.699997 160.900009 155.400009 155.500000 142.100006 143.199997 143.699997 138.100006 138.300003 139.600006
199.85 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 153.800003 174.500000 147.300003 139.400009 139.600006 144.199997 144.199997 160.199997 142.199997 143.699997
199.9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 164.199997 166.800003 151.000000 153.800003 153.900009 169.000000 169.300003 181.600006 139.699997 144.400009
199.95 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 152.900009 159.800003 184.300003 164.000000 164.199997 167.100006 167.600006 201.600006 318.600006 169.699997
200.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 149.199997 148.400009 148.600006 152.300003 152.800003 159.699997 240.699997 240.800003 338.899994 340.100006

5 rows × 2401 columns

In [68]:
par_df[par_df.index=='120.85']
Out[68]:
60.0 59.95 59.9 59.85 59.8 59.75 59.7 59.65 59.6 59.55 ... -59.55 -59.6 -59.65 -59.7 -59.75 -59.8 -59.85 -59.9 -59.95 -60.0
120.85 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 12.5 27.4 53.100002 57.200001 11.1 11.900001 15.6 90.0 91.599998 94.900002

1 rows × 2401 columns

In [ ]: