{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "from datetime import datetime, timedelta\n", "import pytz\n", "import xarray as xr\n", "import metpy as mpy\n", "from pandas.tseries.offsets import *\n", "import metpy.calc as mpcalc\n", "from metpy.units import units" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "folder = 'C:/Users/Matthew/Documents/summerintership/met_tower/'\n", "file11 = 'WFMFS_SUMMIT_Table1_2017_08_11_2302.dat'\n", "file12 = 'WFMFS_SUMMIT_Table1_2017_08_12_2302.dat'\n", "file13 = 'WFMFS_SUMMIT_Table1_2017_08_13_2302.dat'\n", "file14 = 'WFMFS_SUMMIT_Table1_2017_08_14_2302.dat'\n", "file15 = 'WFMFS_SUMMIT_Table1_2017_08_15_2302.dat'\n", "file16 = 'WFMFS_SUMMIT_Table1_2017_08_16_2302.dat'\n", "file17 = 'WFMFS_SUMMIT_Table1_2017_08_17_2302.dat'\n", "file18 = 'WFMFS_SUMMIT_Table1_2017_08_18_2302.dat'\n", "file19 = 'WFMFS_SUMMIT_Table1_2017_08_19_2302.dat'\n", "file20 = 'WFMFS_SUMMIT_Table1_2017_08_20_2302.dat'\n", "file21 = 'WFMFS_SUMMIT_Table1_2017_08_21_2302.dat'\n", "file22 = 'WFMFS_SUMMIT_Table1_2017_08_22_2302.dat'\n", "file23 = 'WFMFS_SUMMIT_Table1_2017_08_23_2302.dat'\n", "file24 = 'WFMFS_SUMMIT_Table1_2017_08_24_2302.dat'\n", "file25 = 'WFMFS_SUMMIT_Table1_2017_08_25_2302.dat'\n", "names = [\"TIMESTAMP\",\"RECORD\",\"NO_Avg\",\"NO2_Avg\",\"NOy_Avg\",\"Ozone_Avg\",\"CO_Avg\",\"SO2_Avg\",\"Lamp_Avg\",\"Spare2_Avg\",\"T_Avg\",\"RH_Avg\",\"WS3CupA_Avg\",\"WS3CupB_Avg\",\"WS3CupA_Max\",\"WS3CupB_S_WVT\",\"WindDir_D1_WVT\",\"WindDir_SD1_WVT\",\"BP_Avg\",\"SlrW_Avg\",\"WS3CupB_Max\",\"Rain_mm_Tot\",\"PTemp_C_Avg\",\"Batt_Volt_Avg\",\"Spare3_Avg\",\"F_CO_Avg\",\"F_NOY_Avg\",\"F_SO2_Avg\",\"F_NOX_Avg\",\"F_TRH_Avg\",\"F_WIND_Avg\",\"Phase1_Avg\",\"Phase2_Avg\",\"Phase3_Avg\",\"Spare13_Avg\",\"Spare14_Avg\",\"Spare15_Avg\",\"Spare16_Avg\"]\n", "df11 = pd.read_table((folder + file11), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df12 = pd.read_table((folder + file12), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df13 = pd.read_table((folder + file13), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df14 = pd.read_table((folder + file14), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df15 = pd.read_table((folder + file15), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df16 = pd.read_table((folder + file16), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df17 = pd.read_table((folder + file17), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df18 = pd.read_table((folder + file18), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df19 = pd.read_table((folder + file19), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df20 = pd.read_table((folder + file20), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df21 = pd.read_table((folder + file21), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df22 = pd.read_table((folder + file22), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df23 = pd.read_table((folder + file23), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df24 = pd.read_table((folder + file24), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "df25 = pd.read_table((folder + file25), sep=\",\", skiprows = (4), index_col = 'TIMESTAMP', names = names)\n", "\n", "df = pd.concat((df11, df12, df13, df14, df15, df16, df17, df18, df19, df20, df21, df22, df23, df24, df25))\n", "\n", "dt = pd.to_datetime( df.index, format = '%Y-%m-%d %H:%M:%S')\n", "df.index = dt\n", "df.T_Avg = df.T_Avg.astype('float64')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Adding 4 hours to each timestamp to correct from EST to UTC\n", "1.44e13ns = 4 hours" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "DatetimeIndex(['2017-08-11 23:02:00', '2017-08-11 23:03:00',\n", " '2017-08-11 23:04:00', '2017-08-11 23:05:00',\n", " '2017-08-11 23:06:00', '2017-08-11 23:07:00',\n", " '2017-08-11 23:08:00', '2017-08-11 23:09:00',\n", " '2017-08-11 23:10:00', '2017-08-11 23:11:00',\n", " ...\n", " '2017-08-26 22:52:00', '2017-08-26 22:53:00',\n", " '2017-08-26 22:54:00', '2017-08-26 22:55:00',\n", " '2017-08-26 22:56:00', '2017-08-26 22:57:00',\n", " '2017-08-26 22:58:00', '2017-08-26 22:59:00',\n", " '2017-08-26 23:00:00', '2017-08-26 23:01:00'],\n", " dtype='datetime64[ns]', name='TIMESTAMP', length=21600, freq=None)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.index" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#df_asrc_sum.index = df_asrc_sum.index.tz_localize('US/Eastern') \n", "#df_asrc_sum.index = df_asrc_sum.index.tz_convert('UTC')\n", "time = np.array(df.index)\n", "time = time + 18000000000000" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "time = xr.DataArray(time, name= ['time'], coords=[time], dims=['time'])\n", "record = xr.DataArray(df.RECORD, name= ['Record'], coords=[time], dims=['time'])\n", "NO_Avg= xr.DataArray(df.NO_Avg, name= ['NO_Avg'], coords=[time], dims=['time'])\n", "NO2_Avg= xr.DataArray(df.NO2_Avg, name= ['NO2_Avg'], coords=[time], dims=['time'])\n", "NOy_Avg= xr.DataArray(df.NOy_Avg, name= ['NOy_Avg'], coords=[time], dims=['time'])\n", "Ozone_Avg= xr.DataArray(df.Ozone_Avg, name= ['Ozone_Avg'], coords=[time], dims=['time'])\n", "CO_Avg = xr.DataArray(df.CO_Avg, name= ['CO_Avg'], coords=[time], dims=['time'])\n", "SO2_Avg= xr.DataArray(df.SO2_Avg, name= ['SO2_Avg'], coords=[time], dims=['time'])\n", "Lamp_Avg= xr.DataArray(df.Lamp_Avg, name= ['Lamp_Avg'], coords=[time], dims=['time'])\n", "Spare2_Avg= xr.DataArray(df.Spare2_Avg, name= ['Spare2_Avg'], coords=[time], dims=['time'])\n", "T_Avg= xr.DataArray(df.T_Avg, name= ['Temp'], coords=[time], dims=['time'])\n", "RH_Avg= xr.DataArray(df.RH_Avg, name= ['Relative Humidity'], coords=[time], dims=['time'])\n", "WS3CupA_Avg= xr.DataArray(df.WS3CupA_Avg, name= ['WS3CupA_Avg'], coords=[time], dims=['time'])\n", "WS3CupB_Avg= xr.DataArray(df.WS3CupB_Avg, name= ['WS3CupB_Avg'], coords=[time], dims=['time'])\n", "WS3CupA_Max= xr.DataArray(df.WS3CupA_Max, name= ['WS3CupA_Max'], coords=[time], dims=['time'])\n", "WS3CupB_Max= xr.DataArray(df.WS3CupB_Max, name= ['WS3CupB_Max'], coords=[time], dims=['time'])\n", "WS3CupB_S_WVT= xr.DataArray(df.WS3CupB_S_WVT, name= ['WS3CupB_S_WVT'], coords=[time], dims=['time'])\n", "WindDir_D1_WVT= xr.DataArray(df.WindDir_D1_WVT, name= ['WindDir_D1_WVT'], coords=[time], dims=['time'])\n", "WindDir_SD1_WVT= xr.DataArray(df.WindDir_SD1_WVT, name= ['WindDir_SD1_WVT'], coords=[time], dims=['time'])\n", "BP_Avg= xr.DataArray(df.BP_Avg, name= ['Pressure'], coords=[time], dims=['time'])\n", "SlrW_Avg= xr.DataArray(df.SlrW_Avg, name= ['SlrW_Avg'], coords=[time], dims=['time'])\n", "Rain_Tot= xr.DataArray(df.Rain_mm_Tot, name= ['Rain_Tot'], coords=[time], dims=['time'])\n", "PTemp_C_Avg= xr.DataArray(df.PTemp_C_Avg, name= ['PTemp_C_Avg'], coords=[time], dims=['time'])\n", "Batt_Volt_Avg= xr.DataArray(df.Batt_Volt_Avg, name= ['Batt_Volt_Avg'], coords=[time], dims=['time'])\n", "Spare3_Avg= xr.DataArray(df.Spare3_Avg, name= ['Spare3_Avg'], coords=[time], dims=['time'])\n", "F_CO_Avg= xr.DataArray(df.F_CO_Avg, name= ['F_CO_Avg'], coords=[time], dims=['time'])\n", "F_NOY_Avg= xr.DataArray(df.F_NOY_Avg, name= ['F_NOY_Avg'], coords=[time], dims=['time'])\n", "F_SO2_Avg= xr.DataArray(df.F_SO2_Avg, name= ['F_SO2_Avg'], coords=[time], dims=['time'])\n", "F_NOX_Avg= xr.DataArray(df.F_NOX_Avg, name= ['F_NOX_AvgF_TRH_Avg'], coords=[time], dims=['time'])\n", "F_TRH_Avg= xr.DataArray(df.F_TRH_Avg, name= ['F_TRH_Avg'], coords=[time], dims=['time'])\n", "F_WIND_Avg= xr.DataArray(df.F_WIND_Avg, name= ['F_WIND_Avg'], coords=[time], dims=['time'])\n", "Phase1_Avg= xr.DataArray(df.Phase1_Avg, name= ['Phase1_Avg'], coords=[time], dims=['time'])\n", "Phase2_Avg= xr.DataArray(df.Phase2_Avg, name= ['Phase2_Avg'], coords=[time], dims=['time'])\n", "Phase3_Avg= xr.DataArray(df.Phase3_Avg, name= ['Phase3_Avg'], coords=[time], dims=['time'])\n", "Spare13_Avg= xr.DataArray(df.Spare13_Avg, name= ['Spare13_Avg'], coords=[time], dims=['time'])\n", "Spare14_Avg= xr.DataArray(df.Spare14_Avg, name= ['Spare14_Avg'], coords=[time], dims=['time'])\n", "Spare15_Avg= xr.DataArray(df.Spare15_Avg, name= ['Spare15_Avg'], coords=[time], dims=['time'])\n", "Spare16_Avg= xr.DataArray(df.Spare16_Avg, name= ['Spare16_Avg'], coords=[time], dims=['time'])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [], "source": [ "T_Avg.attrs['units'] = 'degC'\n", "WS3CupA_Avg.attrs['units'] = 'm/s'\n", "WS3CupB_Avg.attrs['units'] = 'm/s'\n", "Rain_Tot.attrs['units'] = 'mm'\n", "BP_Avg.attrs['units'] = 'hPa'\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ds = T_Avg.to_dataset(name='Temp')\n", "ds['RH']=RH_Avg\n", "ds['Pressure']=BP_Avg\n", "ds['Rain_Tot']=Rain_Tot\n", "ds['WS3CupA_Avg']=WS3CupA_Avg\n", "ds['WS3CupA_Max']=WS3CupA_Max\n", "ds['WS3CupB_Avg']=WS3CupB_Avg\n", "ds['WS3CupB_Max']=WS3CupB_Max\n", "ds['WS3CupB_S_WVT']=WS3CupB_S_WVT\n", "ds['WindDir_D1_WVT']=WindDir_D1_WVT\n", "ds['WindDir_SD1_WVT']=WindDir_SD1_WVT\n", "ds['NO_Avg']=NO_Avg\n", "ds['NO2_Avg']=NO2_Avg\n", "ds['NOy_Avg']=NOy_Avg\n", "ds['Ozone_Avg']=Ozone_Avg\n", "ds['CO_Avg']=CO_Avg\n", "ds['SO2_Avg']=SO2_Avg\n", "ds['Lamp_Avg']=Lamp_Avg\n", "ds['SlrW_Avg']=SlrW_Avg\n", "ds['PTemp_C_Avg']=PTemp_C_Avg\n", "ds['Batt_Volt_Avg']=Batt_Volt_Avg\n", "ds['F_CO_Avg']=F_CO_Avg\n", "ds['F_NOX_Avg']=F_NOX_Avg\n", "ds['F_NOY_Avg']=F_NOY_Avg\n", "ds['F_SO2_Avg']=F_SO2_Avg\n", "ds['F_TRH_Avg']=F_TRH_Avg\n", "ds['F_WIND_Avg']=F_WIND_Avg\n", "ds['Phase1_Avg']=Phase1_Avg\n", "ds['Phase2_Avg']=Phase2_Avg\n", "ds['Phase3_Avg']=Phase3_Avg\n", "ds['Spare2_Avg']=Spare2_Avg\n", "ds['Spare3_Avg']=Spare3_Avg\n", "ds['Spare13_Avg']=Spare13_Avg\n", "ds['Spare14_Avg']=Spare14_Avg\n", "ds['Spare15_Avg']=Spare15_Avg\n", "ds['Spare16_Avg']=Spare16_Avg\n", "ds['Record']=record" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\n", "Dimensions: (time: 21600)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2017-08-12T04:02:00 ...\n", "Data variables:\n", " Temp (time) float64 12.82 12.82 12.82 12.82 12.82 12.82 ...\n", " RH (time) float64 100.0 100.0 100.0 100.0 100.0 100.0 ...\n", " Pressure (time) int64 853 853 853 853 853 853 853 853 853 852 ...\n", " Rain_Tot (time) int64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...\n", " WS3CupA_Avg (time) float64 6.779 7.025 7.746 8.23 7.992 8.61 8.28 ...\n", " WS3CupA_Max (time) float64 9.64 8.69 10.38 10.06 9.22 10.49 11.54 ...\n", " WS3CupB_Avg (time) float64 3.967 3.867 4.108 3.958 4.325 4.425 ...\n", " WS3CupB_Max (time) float64 4.8 4.4 5.3 4.8 5.1 5.2 4.9 5.1 5.4 6.0 ...\n", " WS3CupB_S_WVT (time) float64 3.967 3.867 4.108 3.958 4.325 4.425 ...\n", " WindDir_D1_WVT (time) float64 173.9 223.3 234.6 230.5 220.4 209.5 ...\n", " WindDir_SD1_WVT (time) float64 63.5 40.28 33.92 27.2 25.31 41.22 48.54 ...\n", " NO_Avg (time) float64 0.045 0.038 0.064 0.058 0.055 0.025 ...\n", " NO2_Avg (time) float64 0.313 0.296 0.246 0.239 0.26 0.246 0.222 ...\n", " NOy_Avg (time) float64 1.323 1.256 1.233 1.28 1.273 1.25 1.273 ...\n", " Ozone_Avg (time) float64 44.98 43.85 43.25 44.15 44.64 44.3 44.23 ...\n", " CO_Avg (time) float64 336.8 337.0 332.9 331.3 330.6 328.7 ...\n", " SO2_Avg (time) float64 0.0 -0.022 -0.023 0.075 -0.006 -0.015 ...\n", " Lamp_Avg (time) object 1.467e+03 1.461e+03 1.451e+03 1.438e+03 ...\n", " SlrW_Avg (time) int64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...\n", " PTemp_C_Avg (time) float64 22.88 22.88 22.87 22.87 22.87 22.87 ...\n", " Batt_Volt_Avg (time) float64 12.97 12.98 12.98 12.98 12.98 12.98 ...\n", " F_CO_Avg (time) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ...\n", " F_NOX_Avg (time) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ...\n", " F_NOY_Avg (time) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ...\n", " F_SO2_Avg (time) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ...\n", " F_TRH_Avg (time) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...\n", " F_WIND_Avg (time) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...\n", " Phase1_Avg (time) float64 122.2 122.0 122.0 122.1 122.1 122.1 ...\n", " Phase2_Avg (time) float64 121.7 121.6 121.4 121.3 121.4 121.6 ...\n", " Phase3_Avg (time) float64 116.7 116.2 116.3 116.1 116.1 116.5 ...\n", " Spare2_Avg (time) float64 153.3 154.2 152.4 148.0 148.1 148.3 ...\n", " Spare3_Avg (time) int64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...\n", " Spare13_Avg (time) float64 4.742 4.082 3.642 2.529 1.966 2.543 ...\n", " Spare14_Avg (time) float64 -224.1 -224.2 -224.4 -224.4 -224.2 ...\n", " Spare15_Avg (time) int64 -1002 -1002 -1003 -1003 -1004 -1004 -1004 ...\n", " Spare16_Avg (time) float64 0.014 0.014 0.0 0.014 0.014 0.0 0.014 ...\n", " Record (time) int64 780972 780973 780974 780975 780976 780977 ..." ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ds.to_netcdf('C:/Users/Matthew/Documents/summerintership/met_tower/WFM_asrc.nc')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }