hima8_pv/读tif获得.ipynb

5.9 KiB
Raw Blame History

In [1]:
import os
import pandas as pd
import netCDF4 as nc
import numpy as np
import datetime as dt
from osgeo import gdal
In [2]:
file_path = "data/2022-07-22/PAR_Minutes_Download/"
In [3]:
target_lon = '120.85'
target_lat = '29.6'
In [7]:
par_list = list()
file_list = [x for x in os.listdir(file_path) if x.endswith('.nc')]
for file in file_list:
    file_name = f"{file_path}{file}"
    date = file.split('_')[1] + ':' + file.split('_')[2]
    nc_data = nc.Dataset(file_name)
    lat = nc_data['latitude'][:] # 纬度
    lon = nc_data['longitude'][:]  # 经度
    lat_str = list(map(lambda x: str(round(x, 2)), np.asarray(nc_data['latitude'][:])))
    lon_str = list(map(lambda x: str(round(x, 2)), np.asarray(nc_data['longitude'][:])))
    latMin, latMax, lonMin, lonMax = min(lat), max(lat), min(lon), max(lon)
    # 分辨率
    lat_Res = (latMax - latMin) / (lat.shape[0]-1)
    lon_Res = (lonMax - lonMin) / (lon.shape[0]-1)
    lon_index = lon_str.index(target_lon)
    lat_index = lat_str.index(target_lat)
    par = np.asarray(nc_data['PAR'][:])
    par_list.append([date, par[lat_index][lon_index]])
In [ ]:
par_df = pd.DataFrame.from_records(par_list, columns=['time', 'par'])
In [20]:
par_df.time = par_df.time.apply(lambda x: dt.datetime.strptime(x, '%Y%m%d:%H%M') + dt.timedelta(hours=8))
In [21]:
par_df
Out[21]:
time par
time
2022-07-22 08:00:00 20220722:0000 1146.900024
2022-07-22 08:10:00 20220722:0010 1217.099976
2022-07-22 08:20:00 20220722:0020 1288.800049
2022-07-22 08:30:00 20220722:0030 1354.800049
2022-07-22 08:40:00 20220722:0040 1419.900024
... ... ...
2022-07-23 07:10:00 20220722:2310 778.400024
2022-07-23 07:20:00 20220722:2320 854.799988
2022-07-23 07:30:00 20220722:2330 928.000000
2022-07-23 07:40:00 20220722:2340 1011.000000
2022-07-23 07:50:00 20220722:2350 1081.800049

141 rows × 2 columns

In [ ]: