Thredds, выбирает шесть переменных из списка переменных, присутствующих в файлах netCDF, и сохраняет их локально в формате csv.
Код: Выделить всё
from datetime import datetime
from netCDF4 import Dataset
import netCDF4
import pandas as pd
import csv
def get_thredds_url(datetime_group, forecast_hour):
base_url="path"
thredds_url="path"
cycle_hour = "%02d" % datetime_group.hour
file_str=datetime_group.strftime("%Y%m%d%H")+"/gfs.t%sz.pgrb2.0p25.f%03d" % \
(cycle_hour, forecast_hour)
url = base_url + thredds_url + file_str
return (url)
Код: Выделить всё
def main():
datetime_group = datetime(2017, 9, 26, 0)
forecast_hour = 240
url = get_thredds_url(datetime_group, forecast_hour)
print (url)
nc_handle=Dataset(url)
#print (nc_handle.variables.keys())
lat=nc_handle.variables['lat'][:]
lon=nc_handle.variables['lon'][:]
issue_time=nc_handle.variables['time'][:]
valid_time=nc_handle.variables['time1'][:]
temp=nc_handle.variables['Temperature_height_above_ground'][:]
dewpoint_temp=lat=nc_handle.variables['Dewpoint_temperature_height_above_ground'][:]
dtime = netCDF4.num2date(issue_time[:],units=units)
tmp = pd.Series(temp, index=dtime)
tmp.to_csv('temp.csv',index=True, header=True)
csvwriter = csv.writer(tmp, delimiter=',')
print (csvwriter)
if __name__ == "__main__":
main()
Код: Выделить всё
tmp.csv
lat lon time time1 Temperature_height_above_ground
1 ... .. ... .... ......
2 ... .. ... .... ......
3 ... .. ... .... ......
Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/475 ... ing-python