This commit is contained in:
zhaojinghao 2022-11-11 15:54:33 +08:00
parent 29db69ea2c
commit 1a57f47249
2 changed files with 186 additions and 131 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"outputs": [],
"source": [
"import numpy as np\n",
@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"outputs": [],
"source": [
"from osgeo import gdal, osr, ogr"
@ -31,17 +31,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [
{
"data": {
"text/plain": "<class 'netCDF4._netCDF4.Dataset'>\nroot group (NETCDF4 data model, file format HDF5):\n title: Himawari-08 AHI equal latitude-longitude map data\n id: H08_20221107_1800_RFL020_FLDK.02401_02401.nc\n date_created: 2022-11-07T18:25:18Z\n pixel_number: 2401\n line_number: 2401\n upper_left_latitude: 60.0\n upper_left_longitude: 80.0\n grid_interval: 0.05\n band_number: 6\n algorithm_version: 0201\n Ancillary meteorological data: JMA forcast\n Ancillary ozone data: JMA objective analysis\n BRDF correction: on (Morel and Maritorena 2001)\n dimensions(sizes): latitude(2401), longitude(2401), band(6), time(1), geometry(17)\n 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)\n groups: "
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"outputs": [],
"source": [
"data = r\"D:\\Datasets\\Himawari\\pub\\L2_PAR\\20221107\\18\\H08_20221107_1800_RFL020_FLDK.02401_02401.nc\"\n",
"nc_data = nc.Dataset(data)\n",
@ -56,17 +47,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": "['latitude',\n 'longitude',\n 'band_id',\n 'start_time',\n 'end_time',\n 'geometry_parameters',\n 'TAOT_02',\n 'TAAE',\n 'PAR',\n 'SWR',\n 'UVA',\n 'UVB',\n 'QA_flag']"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"outputs": [],
"source": [
"list(nc_data.variables.keys())"
],
@ -79,17 +61,8 @@
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [
{
"data": {
"text/plain": "<class 'netCDF4._netCDF4.Variable'>\nint16 PAR(latitude, longitude)\n long_name: Photosynthetically active radiation\n units: umol/m^2/s\n scale_factor: 0.1\n add_offset: 0.0\n valid_min: 0\n valid_max: 25000\n missing_value: -32768\nunlimited dimensions: \ncurrent shape = (2401, 2401)\nfilling on, default _FillValue of -32767 used"
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"outputs": [],
"source": [
"nc_data['PAR']"
],
@ -102,17 +75,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"outputs": [
{
"data": {
"text/plain": "<class 'netCDF4._netCDF4.Variable'>\nfloat32 latitude(latitude)\n long_name: latitude\n units: degrees_north\nunlimited dimensions: \ncurrent shape = (2401,)\nfilling on, default _FillValue of 9.969209968386869e+36 used"
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"outputs": [],
"source": [
"nc_data['latitude']"
],
@ -125,17 +89,8 @@
},
{
"cell_type": "code",
"execution_count": 7,
"outputs": [
{
"data": {
"text/plain": "array([[ 0. , 0. , 0. , ..., 0. , 0. ,\n 0. ],\n [ 0. , 0. , 0. , ..., 0. , 0. ,\n 0. ],\n [ 0. , 0. , 0. , ..., 0. , 0. ,\n 0. ],\n ...,\n [ 0. , 0. , 0. , ..., 181.6 , 139.7 ,\n 144.40001],\n [ 0. , 0. , 0. , ..., 201.6 , 318.6 ,\n 169.7 ],\n [ 0. , 0. , 0. , ..., 240.8 , 338.9 ,\n 340.1 ]], dtype=float32)"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"outputs": [],
"source": [
"par = np.asarray(nc_data['PAR'][:])\n",
"par"
@ -149,7 +104,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"outputs": [],
"source": [
"import pandas as pd"
@ -163,16 +118,8 @@
},
{
"cell_type": "code",
"execution_count": 42,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2401 2401\n"
]
}
],
"execution_count": null,
"outputs": [],
"source": [
"lat = list(map(lambda x: round(x, 2), np.asarray(nc_data['latitude'][:])))\n",
"lon = list(map(lambda x: round(x, 2), np.asarray(nc_data['longitude'][:])))\n",
@ -188,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"outputs": [],
"source": [
"# 分辨率\n",
@ -204,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": null,
"outputs": [],
"source": [
"cols = [str(x) for x in lat]\n",
@ -219,7 +166,7 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": null,
"outputs": [],
"source": [
"par_df = pd.DataFrame.from_records(par)\n",
@ -232,66 +179,6 @@
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 58,
"outputs": [
{
"data": {
"text/plain": " 60.0 59.95 59.9 59.85 59.8 59.75 59.7 59.65 59.6 59.55 ... \\\n199.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... \n199.85 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... \n199.9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... \n199.95 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... \n200.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... \n\n -59.55 -59.6 -59.65 -59.7 -59.75 \\\n199.8 160.699997 160.900009 155.400009 155.500000 142.100006 \n199.85 153.800003 174.500000 147.300003 139.400009 139.600006 \n199.9 164.199997 166.800003 151.000000 153.800003 153.900009 \n199.95 152.900009 159.800003 184.300003 164.000000 164.199997 \n200.0 149.199997 148.400009 148.600006 152.300003 152.800003 \n\n -59.8 -59.85 -59.9 -59.95 -60.0 \n199.8 143.199997 143.699997 138.100006 138.300003 139.600006 \n199.85 144.199997 144.199997 160.199997 142.199997 143.699997 \n199.9 169.000000 169.300003 181.600006 139.699997 144.400009 \n199.95 167.100006 167.600006 201.600006 318.600006 169.699997 \n200.0 159.699997 240.699997 240.800003 338.899994 340.100006 \n\n[5 rows x 2401 columns]",
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>60.0</th>\n <th>59.95</th>\n <th>59.9</th>\n <th>59.85</th>\n <th>59.8</th>\n <th>59.75</th>\n <th>59.7</th>\n <th>59.65</th>\n <th>59.6</th>\n <th>59.55</th>\n <th>...</th>\n <th>-59.55</th>\n <th>-59.6</th>\n <th>-59.65</th>\n <th>-59.7</th>\n <th>-59.75</th>\n <th>-59.8</th>\n <th>-59.85</th>\n <th>-59.9</th>\n <th>-59.95</th>\n <th>-60.0</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>199.8</th>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>...</td>\n <td>160.699997</td>\n <td>160.900009</td>\n <td>155.400009</td>\n <td>155.500000</td>\n <td>142.100006</td>\n <td>143.199997</td>\n <td>143.699997</td>\n <td>138.100006</td>\n <td>138.300003</td>\n <td>139.600006</td>\n </tr>\n <tr>\n <th>199.85</th>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>...</td>\n <td>153.800003</td>\n <td>174.500000</td>\n <td>147.300003</td>\n <td>139.400009</td>\n <td>139.600006</td>\n <td>144.199997</td>\n <td>144.199997</td>\n <td>160.199997</td>\n <td>142.199997</td>\n <td>143.699997</td>\n </tr>\n <tr>\n <th>199.9</th>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>...</td>\n <td>164.199997</td>\n <td>166.800003</td>\n <td>151.000000</td>\n <td>153.800003</td>\n <td>153.900009</td>\n <td>169.000000</td>\n <td>169.300003</td>\n <td>181.600006</td>\n <td>139.699997</td>\n <td>144.400009</td>\n </tr>\n <tr>\n <th>199.95</th>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>...</td>\n <td>152.900009</td>\n <td>159.800003</td>\n <td>184.300003</td>\n <td>164.000000</td>\n <td>164.199997</td>\n <td>167.100006</td>\n <td>167.600006</td>\n <td>201.600006</td>\n <td>318.600006</td>\n <td>169.699997</td>\n </tr>\n <tr>\n <th>200.0</th>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>...</td>\n <td>149.199997</td>\n <td>148.400009</td>\n <td>148.600006</td>\n <td>152.300003</td>\n <td>152.800003</td>\n <td>159.699997</td>\n <td>240.699997</td>\n <td>240.800003</td>\n <td>338.899994</td>\n <td>340.100006</td>\n </tr>\n </tbody>\n</table>\n<p>5 rows × 2401 columns</p>\n</div>"
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"par_df.tail()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 68,
"outputs": [
{
"data": {
"text/plain": " 60.0 59.95 59.9 59.85 59.8 59.75 59.7 59.65 59.6 59.55 ... \\\n120.85 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... \n\n -59.55 -59.6 -59.65 -59.7 -59.75 -59.8 -59.85 -59.9 \\\n120.85 12.5 27.4 53.100002 57.200001 11.1 11.900001 15.6 90.0 \n\n -59.95 -60.0 \n120.85 91.599998 94.900002 \n\n[1 rows x 2401 columns]",
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>60.0</th>\n <th>59.95</th>\n <th>59.9</th>\n <th>59.85</th>\n <th>59.8</th>\n <th>59.75</th>\n <th>59.7</th>\n <th>59.65</th>\n <th>59.6</th>\n <th>59.55</th>\n <th>...</th>\n <th>-59.55</th>\n <th>-59.6</th>\n <th>-59.65</th>\n <th>-59.7</th>\n <th>-59.75</th>\n <th>-59.8</th>\n <th>-59.85</th>\n <th>-59.9</th>\n <th>-59.95</th>\n <th>-60.0</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>120.85</th>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>0.0</td>\n <td>...</td>\n <td>12.5</td>\n <td>27.4</td>\n <td>53.100002</td>\n <td>57.200001</td>\n <td>11.1</td>\n <td>11.900001</td>\n <td>15.6</td>\n <td>90.0</td>\n <td>91.599998</td>\n <td>94.900002</td>\n </tr>\n </tbody>\n</table>\n<p>1 rows × 2401 columns</p>\n</div>"
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"par_df[par_df.index=='120.85']"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {

168
读tif获得.ipynb Normal file
View File

@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"import netCDF4 as nc\n",
"import numpy as np\n",
"import datetime as dt\n",
"from osgeo import gdal"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"file_path = \"data/2022-07-22/PAR_Minutes_Download/\""
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [],
"source": [
"target_lon = '120.85'\n",
"target_lat = '29.6'"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 7,
"outputs": [],
"source": [
"par_list = list()\n",
"file_list = [x for x in os.listdir(file_path) if x.endswith('.nc')]\n",
"for file in file_list:\n",
" file_name = f\"{file_path}{file}\"\n",
" date = file.split('_')[1] + ':' + file.split('_')[2]\n",
" nc_data = nc.Dataset(file_name)\n",
" lat = nc_data['latitude'][:] # 纬度\n",
" lon = nc_data['longitude'][:] # 经度\n",
" lat_str = list(map(lambda x: str(round(x, 2)), np.asarray(nc_data['latitude'][:])))\n",
" lon_str = list(map(lambda x: str(round(x, 2)), np.asarray(nc_data['longitude'][:])))\n",
" latMin, latMax, lonMin, lonMax = min(lat), max(lat), min(lon), max(lon)\n",
" # 分辨率\n",
" lat_Res = (latMax - latMin) / (lat.shape[0]-1)\n",
" lon_Res = (lonMax - lonMin) / (lon.shape[0]-1)\n",
" lon_index = lon_str.index(target_lon)\n",
" lat_index = lat_str.index(target_lat)\n",
" par = np.asarray(nc_data['PAR'][:])\n",
" par_list.append([date, par[lat_index][lon_index]])"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"par_df = pd.DataFrame.from_records(par_list, columns=['time', 'par'])"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 20,
"outputs": [],
"source": [
"par_df.time = par_df.time.apply(lambda x: dt.datetime.strptime(x, '%Y%m%d:%H%M') + dt.timedelta(hours=8))"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 21,
"outputs": [
{
"data": {
"text/plain": " time par\ntime \n2022-07-22 08:00:00 20220722:0000 1146.900024\n2022-07-22 08:10:00 20220722:0010 1217.099976\n2022-07-22 08:20:00 20220722:0020 1288.800049\n2022-07-22 08:30:00 20220722:0030 1354.800049\n2022-07-22 08:40:00 20220722:0040 1419.900024\n... ... ...\n2022-07-23 07:10:00 20220722:2310 778.400024\n2022-07-23 07:20:00 20220722:2320 854.799988\n2022-07-23 07:30:00 20220722:2330 928.000000\n2022-07-23 07:40:00 20220722:2340 1011.000000\n2022-07-23 07:50:00 20220722:2350 1081.800049\n\n[141 rows x 2 columns]",
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>time</th>\n <th>par</th>\n </tr>\n <tr>\n <th>time</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2022-07-22 08:00:00</th>\n <td>20220722:0000</td>\n <td>1146.900024</td>\n </tr>\n <tr>\n <th>2022-07-22 08:10:00</th>\n <td>20220722:0010</td>\n <td>1217.099976</td>\n </tr>\n <tr>\n <th>2022-07-22 08:20:00</th>\n <td>20220722:0020</td>\n <td>1288.800049</td>\n </tr>\n <tr>\n <th>2022-07-22 08:30:00</th>\n <td>20220722:0030</td>\n <td>1354.800049</td>\n </tr>\n <tr>\n <th>2022-07-22 08:40:00</th>\n <td>20220722:0040</td>\n <td>1419.900024</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>2022-07-23 07:10:00</th>\n <td>20220722:2310</td>\n <td>778.400024</td>\n </tr>\n <tr>\n <th>2022-07-23 07:20:00</th>\n <td>20220722:2320</td>\n <td>854.799988</td>\n </tr>\n <tr>\n <th>2022-07-23 07:30:00</th>\n <td>20220722:2330</td>\n <td>928.000000</td>\n </tr>\n <tr>\n <th>2022-07-23 07:40:00</th>\n <td>20220722:2340</td>\n <td>1011.000000</td>\n </tr>\n <tr>\n <th>2022-07-23 07:50:00</th>\n <td>20220722:2350</td>\n <td>1081.800049</td>\n </tr>\n </tbody>\n</table>\n<p>141 rows × 2 columns</p>\n</div>"
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"par_df"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}