一、ECMWF的数据
from netCDF4 import Dataset
from netCDF4 import num2date
nc_obj = Dataset ( "12.5.nc" )
time= nc_obj[ 'time' ] [ : ]
time1= num2date( time, units= nc_obj[ 'time' ] . units)
longitude= nc_obj[ 'longitude' ] [ : ]
print ( longitude)
[127. 127.125 127.25 127.375 127.5 127.625 127.75 127.875 128.
128.125 128.25 128.375 128.5 128.625 128.75 128.875 129. ]
latitude= nc_obj[ 'latitude' ] [ : ]
print ( latitude)
[46. 45.875 45.75 45.625 45.5 45.375 45.25 45.125 45. 44.875
44.75 44.625 44.5 44.375 44.25 44.125 44. ]
v10= nc_obj[ 'v10' ] [ : ]
a = [ 0 ] * 124
for i in range ( 124 ) :
a[ i] = nc_obj. variables[ 'v10' ] [ i] [ 4 ] [ 12 ]
u10= nc_obj[ 'u10' ] [ : ]
b = [ 0 ] * 124
for i in range ( 124 ) :
b[ i] = nc_obj. variables[ 'u10' ] [ i] [ 4 ] [ 12 ]
c = [ 0 ] * 124
for i in range ( 124 ) :
c[ i] = ( a[ i] ** 2 + b[ i] ** 2 ) ** 0.5
import matplotlib. pyplot as plt
import pandas as pd
plt. rc( 'font' , family= 'SimHei' , size= 15 )
plt. rcParams[ 'axes.unicode_minus' ] = False
plt. figure( figsize= ( 30 , 8 ) )
plt. title( 'ECMWF风速与时间的函数' )
plt. xlabel( '时间' )
plt. ylabel( '风速(m/s)' )
plt. grid( color= '#95a5a6' , linestyle= '--' , linewidth= 3 , axis= 'both' , alpha= 0.4 )
plt. plot( time1, c, 'ro' , time1, c, 'r' )
plt. xticks( pd. date_range( '2019-01-01' , '2019-01-31' ) )
plt. gcf( ) . autofmt_xdate( )
plt. savefig( 'ECMWF.png' )
plt. show( )
二、NOAA的数据(梁晨)
from datetime import datetime
import pandas as pd
noaa= pd. read_csv( "C:\\Users\\zzh\\Desktop\\ECMWF\\201901.CSV" )
201901.CSV该数据存在问题,在用pandas读进来后,USAF变成行号,其他依次往前挪了一列
time2= noaa[ 'WBAN' ]
new_time= [ ]
for i in time2:
new_time. append( ( str . split( str ( i) [ : 10 ] ) ) [ 0 ] )
new_time2 = [ ]
for i in new_time:
new_time2. append( datetime. strptime( i, '%Y%m%d%H' ) )
new_time3 = [ ]
for i in range ( 0 , 247 , 2 ) :
new_time3 . append( new_time2[ i] )
DIR= noaa[ 'DIR' ]
spd= [ ]
for i in DIR:
spd. append( i* 0.44704 )
spd2 = [ ]
for i in range ( 0 , 247 , 2 ) :
spd2 . append( spd[ i] )
plt. figure( figsize= ( 30 , 8 ) )
plt. title( 'NOAA风速与时间的函数' )
plt. xlabel( '时间' )
plt. ylabel( '风速(m/s)' )
plt. grid( color= '#95a5a6' , linestyle= '--' , linewidth= 3 , axis= 'both' , alpha= 0.4 )
plt. plot( new_time3, spd2, 'go' , new_time3, spd2, 'g' )
plt. xticks( pd. date_range( '2019-01-01' , '2019-01-31' ) )
plt. gcf( ) . autofmt_xdate( )
plt. savefig( 'NOAA.png' )
plt. show( )
三、ECMWF和NOAA对比图
plt. figure( figsize= ( 30 , 8 ) )
plt. title( '风速与时间的函数' )
plt. xlabel( '时间' )
plt. ylabel( 'g风速(m/s)' )
plt. grid( color= '#95a5a6' , linestyle= '--' , linewidth= 3 , axis= 'both' , alpha= 0.4 )
plt. plot( time1, c, 'ro' , time1, c, 'r' , label= 'ECMWF' )
plt. plot( new_time3, spd2, 'go' , new_time3, spd2, 'g' , label= 'NOAA' )
plt. xticks( pd. date_range( '2019-01-01' , '2019-01-31' ) )
plt. gcf( ) . autofmt_xdate( )
plt. legend( )
plt. savefig( 'ECMWF和NOAA.png' )
plt. show( )
大家好,我是[爱做梦的子浩](https://blog.csdn.net/weixin_43124279),我是东北大学大数据实验班大三的小菜鸡,非常向往优秀,羡慕优秀的人,已拿两个暑假offer,欢迎大家找我进行交流