noaa潮汐表的瘦api
tidetable的Python项目详细描述
tidetable是下载年度潮汐预报的python模块。 来自NOAA Tides & Currents站点的表。
使用pip install tidetable安装。
基本知识
首先,从NOAA Tides & Currents site获取潮汐站的站id。
然后,使用get方法下载表。这将返回 TideTable对象,它只是一个list和一些附加的 元数据参数。
在本例中,我们使用缅因州的潮汐站:
>>>importtidetable>>>table=tidetable.get(8416092)>>>tabletidetable.TideTable(stationid=8416092)>>>table[0]{'pred_cm':149.0,'datetime':datetime.datetime(2014,12,31,3,44),'pred_ft':4.9,'high_low':'H'}
TideTable对象的元数据包含一些位置数据, 有关母潮汐站和误差间隔的信息:
>>>table.stationname,table.state('Monhegan Island','ME')>>>table.datum'MLLW'>>>table.referencetostationid'8418150'>>>table.timeoffsetlow,table.timeoffsethigh('-9','-13')
时间框架
默认情况下,NOAA返回当前的潮汐预测表 一年。要获取最近或将来的年份,请使用year 关键字参数。在过去的五年里 未来的岁月是可以利用的。没有办法缩短时间 一整年的预测范围。
>>>importtidetable>>>table=tidetable.get(8416092,year=2016)>>>tabletidetable.TideTable(stationid=8416092)>>>table[4]['datetime']datetime.datetime(2016,1,1,3,39)
(请注意,返回的前几行可能是前一年的。)
写作
TideTable对象有一个write-csv方法。它接受 文件名或任何类似文件的对象。
importtidetabletable=tidetable.get(8416092)table.write_csv('tide_table.csv')
时区
如您所见,TideTable是一个dicts的列表,每个列表 有一个datetime,一个以英尺和厘米为单位的预测,以及一个高或低标志。 这些预测是相对于datum的,在本例中是 或平均低水位。注意mllw是不同的 从海平面。
默认情况下,datetime在本地时间,可以是 标准或夏令时。使用time_zone关键字 参数获取GMT或本地标准时区中的时间。 tidetable总是返回天真的datetime对象。
使用这些常量指定时区:tidetable.GMT, tidetable.LOCAL_STANDARD_TIME,tidetable.LOCAL_TIME。
>>>importtidetable>>>table=tidetable.get(8416092,time_zone=tidetable.GMT)>>>table[0]['datetime']datetime.datetime(2014,12,31,0,15)
(请注意与第一个示例中日期时间的差异,即 东部标准时间)