예제 #1
0
 def LoadNewFile(self, infilename):
     try:
         self.MetData = MetData(infilename)
     except Exception as err:
         dlg = wx.MessageDialog(self, str(err), "File Not Loaded",
                                wx.OK | wx.ICON_WARNING)
         dlg.ShowModal()
         dlg.Destroy()
     self.MonthSelector.SetStringSelection("All Year")
     self.OnSelectMonth()
예제 #2
0
class Test_RawPorts(ReaderTester):
    filename = "RawPortsSample.txt"
    MD = MetData(os.path.join(TestDataDir, filename))
    start_time = dt(2006, 4, 24, 1)
    end_time = dt(2006, 4, 25, 15)
    time_zone = 'UTC'
    name = ''
    lat_long = (None, None)
    fields = ['AirTemp',
              'PredictedWaterLevel',
              'AirPressure',
              'WindGusts',
              'ObservedWaterLevel',
              'WindSpeed',
              'WaterTemp',
              'Salinity',
              'WindDirection',
              'SpecificGravity']

    units = {'AirTemp': 'degreesF',
             'PredictedWaterLevel': 'feet',
             'AirPressure': 'millibars',
             'WindGusts': 'knots',
             'ObservedWaterLevel': 'feet',
             'WindSpeed': 'knots',
             'WaterTemp': 'degreesF',
             'Salinity': 'PSU',
             'WindDirection': 'degrees',
             'SpecificGravity': 'SG'}
예제 #3
0
class Test_NDBC_ContinuousWind(ReaderTester):
    filename = "46047_5day.cwind"
    MD = MetData(os.path.join(TestDataDir, filename))
    start_time = dt(2007, 8, 23, 14, 0)
    end_time = dt(2007, 8, 23, 16, 50)
    time_zone = 'UTC'
    name = '46047_5day'
    lat_long = (None, None)
    fields = ['Hour',
              'WindGusts',
              'WindGustDirection',
              'Month',
              'WindSpeed',
              'Year',
              'WindGustTime',
              'WindDirection',
              'Day',
              'Minute',
              ]


    units = {'WindGusts': 'm/s',
             'WindSpeed': 'm/s',
             'WindDirection': 'degrees',
             'WindGustDirection':'degrees',
             'WindGustTime': None
             }
예제 #4
0
def make_random_data(num_samples):
    dirs = np.r_[np.random.normal(loc=45, scale=20, size=(num_samples, )),
                 np.random.normal(loc=270, scale=40, size=(
                     num_samples, ))] % 360
    spds = np.random.normal(loc=10, scale=6, size=(2 * num_samples, ))
    spds = np.where((spds < 0), 0, spds)
    data = np.c_[spds, dirs]
    # make an hourly time series
    Times = [
        datetime.datetime(2009, 1, 1) + datetime.timedelta(hours=i)
        for i in range(len(data))
    ]
    data = MetData(
        FileReader=None,
        DataArray=data,
        Fields={
            "WindSpeed": 0,
            "WindDirection": 1,
        },
        Units={
            "WindSpeed": "knots",  # most often?
            "WindDirection": "degrees",
        },
        Times=[
            datetime.datetime(2009, 1, 1) + datetime.timedelta(hours=i)
            for i in range(len(data))
        ],
        Name='Fake Sample Data',
    )
    return data
예제 #5
0
class Test_NDBC_RealTime_Missing_Dir(ReaderTester):
    filename = "NDBC_with_MM_dir.txt"
    MD = MetData(os.path.join(TestDataDir, filename))
    start_time = dt(2014, 7, 31, 15, 35)
    end_time = dt(2014, 7, 31, 21, 35)
    # time_zone = 'UTC'
    # name = '46086_5day'
    # lat_long = (None, None)
    # fields = ['AirTemp',
    #            'DominantWavePeriod',
    #            'Hour',
    #            'WindGusts',
    #            'WaveHeight',
    #            'WindDirection',
    #            'AverageWavePeriod',
    #            'WindSpeed',
    #            'Visibility',
    #            'Month',
    #            'AirPressure',
    #            'MeanWaveDirection',
    #            'Year',
    #            'WaterTemp',
    #            'PressureTendency',
    #            'DewPoint',
    #            'Day',
    #            'Minute',
    #            'TideHeight',
    #           ]

    # units = {'AirTemp': 'degreesC',
    #          'AirPressure': 'hPa',
    #          'DewPoint': 'degreesC',
    #          'WindGusts': 'm/s',
    #          'WindSpeed': 'm/s',
    #          'WaterTemp': 'degreesC',
    #          'WindDirection': 'degrees',
    #          'DominantWavePeriod': 'seconds',
    #          'WaveHeight': 'meters',
    #          'AverageWavePeriod': 'seconds',
    #          'MeanWaveDirection': 'degrees',
    #          'Visibility': 'nauticalmiles',
    #          'TideHeight': 'feet',
    #          }
    def test_missing_wind_dir(self):
        print(self.MD.GetFieldsAsArray(['WindDirection', 'WindSpeed']))
        wind = self.MD.GetFieldsAsArray(['WindDirection', 'WindSpeed'])
        # make sure NaNs are in the right place:
        assert np.isnan(wind[3, 0])
        assert np.isnan(wind[12, 0])
        assert np.isnan(wind[13, 0])
        assert np.isnan(wind[14, 0])
        assert np.isnan(wind[15, 0])
        assert np.isnan(wind[16, 0])
        assert np.isnan(wind[18, 0])
예제 #6
0
class Test_NCDC_LCD(ReaderTester):
    filename = "NCDC-LCD.txt"
    MD = MetData(os.path.join(TestDataDir, filename))
    start_time = dt(2008, 10, 1, 0, 15)
    end_time = dt(2008, 10, 27, 3, 56)
    time_zone = 'LST'  # is that correct??
    name = 'GROTON-NEW LONDON AIRPORT (14707)'
    lat_long = (41.328, -72.049)
    fields = ['AirTemp',  # that's all it reads now!
              'WindSpeed',
              'WindDirection',
              ]
    units = {'AirTemp': 'celsius',
             'WindSpeed': 'mph',
             'WindDirection': 'degrees',
             }
예제 #7
0
class Test_NDBC_RealTime(ReaderTester):
    filename = "46086_5day.txt"
    MD = MetData(os.path.join(TestDataDir, filename))

    start_time = dt(2007, 8, 18, 17, 50)
    end_time = dt(2007, 8, 23, 16, 50)
    time_zone = 'UTC'
    name = '46086_5day'
    lat_long = (None, None)
    fields = ['AirTemp',
               'DominantWavePeriod',
               'Hour',
               'WindGusts',
               'WaveHeight',
               'WindDirection',
               'AverageWavePeriod',
               'WindSpeed',
               'Visibility',
               'Month',
               'AirPressure',
               'MeanWaveDirection',
               'Year',
               'WaterTemp',
               'PressureTendency',
               'DewPoint',
               'Day',
               'Minute',
               'TideHeight',
              ]

    units = {'AirTemp': 'degreesC',
             'AirPressure': 'hPa',
             'DewPoint': 'degreesC',
             'WindGusts': 'm/s',
             'WindSpeed': 'm/s',
             'WaterTemp': 'degreesC',
             'WindDirection': 'degrees',
             'DominantWavePeriod': 'seconds',
             'WaveHeight': 'meters',
             'AverageWavePeriod': 'seconds',
             'MeanWaveDirection': 'degrees',
             'Visibility': 'nauticalmiles',
             'TideHeight': 'feet',
             }
예제 #8
0
class Test_NGDCXX(ReaderTester):
    filename = "NGDC_test.txt"
    MD = MetData(os.path.join(TestDataDir, filename))
    start_time = dt(1974, 9, 24, 0, 0)
    end_time = dt(1974, 10, 16, 6, 0)
    time_zone = 'UTC'  # is that correct??
    name = 'USAF: 488260, NCDC WBAN NUMBER: 99999'
    lat_long = (None, None)
    fields = ['AirTemp',  # that's all it reads now!
              'WindSpeed',
              'WindDirection',
              'WindGusts'
              ]

    units = {'AirTemp': 'degreesF',
             'WindSpeed': 'mph',
             'WindDirection': 'degrees',
             'WindGusts': 'mph',
             }
예제 #9
0
class Test_NDBC_Historical(ReaderTester):
    filename = "42035h2000-sept.txt"
    MD = MetData(os.path.join(TestDataDir, filename))
    start_time = dt(2000, 9, 1, 00)
    end_time = dt(2000, 10, 27, 0o7)
    time_zone = 'UTC'
    name = '42035h2000-sept'
    lat_long = (None, None)
    fields = ['AirTemp',
              'DominantWavePeriod',
              'WindGusts',
              'WaveHeight',
              'WindDirection',
              'AverageWavePeriod',
              'WindSpeed',
              'Visibility',
              'AirPressure',
              'MeanWaveDirection',
              'WaterTemp',
              'DewPoint',
              'TideHeight',
              'AirTemp',
              'Year',
              'Month',
              'Hour',
              'Day',
              ]

    units = {'AirTemp': 'degreesC',
             'AirPressure': 'hPa',
             'DewPoint': 'degreesC',
             'WindGusts': 'm/s',
             'WindSpeed': 'm/s',
             'WaterTemp': 'degreesC',
             'WindDirection': 'degrees',
             'DominantWavePeriod': 'seconds',
             'WaveHeight': 'meters',
             'AverageWavePeriod': 'seconds',
             'MeanWaveDirection': 'degrees',
             'Visibility': 'nauticalmiles',
             'TideHeight': 'feet',
             }
예제 #10
0
Translate from any supported format to OSSM format

"""

import sys
from windtools import MetData

# #fixme: "This shifts to Pacific time!!!"
try:
    infilename = sys.argv[1]
except IndexError:
    print("You need to give me a file to process!!")
    sys.exit(1)

print("split name:", infilename.rsplit('.', 1))
outfilename = infilename.rsplit('.', 1)[0] + ".wave.OSM"

data = MetData(infilename)
# check for lat-lon
if data.LatLong == (None, None):
    latlon = input("I need the lat, lon (ex: 28.54, -92.45): > ").strip()
    lat, lon = (float(l) for l in latlon.split(","))
    data.LatLong = (lat, lon)
data.ChangeTZ(8, "PST")

print("Converting to PST!!!!")

#Data.SaveAsOSSMWind(outfilename, units='knots')

data.SaveAsOSSMWave(outfilename)
예제 #11
0
    outfilename = sys.argv[-1]

if not outfilename.lower().endswith(".osm"):
    outfilename += ".osm"

# try:
#     timeZone = int(sys.argv[2])
# except IndexError:
#     timeZone = 0

# try:
#     timeZoneName = sys.argv[3]
# except IndexError:
#     timeZoneName = ""

print("Reading:", infilenames[0])
data = MetData(infilenames[0])

for infile in infilenames[1:]:
    print("Reading:", infile)
    new_data = MetData(infile)
    data += new_data

# print "Converting to:", outfilename
# if timeZone != 0:
#     data.ChangeTZ(timeZone, timeZoneName)

data.SaveAsOSSMWind(outfilename, units='knots')

#Data.SaveAsOSSMWind(outfilename)
예제 #12
0
def test_BrokenPorts():
    filename = "DummyFile.txt"
    with pytest.raises(NoFileTypeMatchError):
        MetData(os.path.join(TestDataDir, filename))
예제 #13
0
class Test_RawPorts_html(Test_RawPorts):
    filename = "RawPortsSample.html"
    MD = MetData(os.path.join(TestDataDir, filename))
예제 #14
0
DummyData = MetData(TimeZone='PST',
                             Name='A test data set',
                             LatLong=(34.12, -119.32),
                             Fields={"WindSpeed": 0,
                                     "WaterTemp": 1,
                                     "WindDirection": 2,
                                     },
                            Units={"WindSpeed": "knots",   # most often?
                                   "WindDirection": "degrees",
                                   "WaterTemp": "C"
                                   },
                            DataArray = np.array([[14, 17.2, 310],
                                                  [18, 16.2, 300],
                                                  [16, 17.3, 290],
                                                  [18, 18.2, 280],
                                                  [16, 14.6, 260],
                                                  [12, 12.1, 250],
                                                  [18, 12.2, 270],
                                                  [24, 13.2, 300],
                                                  [24, 13.3, 290],
                                                  [22, 15.1, 315],
                                                  [22, 10.4, 315],
                                                  [20,  9.2, 315],
                                                  [20,  9.1, 315],
                                                  [20, 10.2, 315],
                                                  [15, 11.3, 340],
                                                  [15, 12.2, 340],
                                                  [15, 13.4, 340],
                                                  [12, 14.5, 340]],
                                                 dtype=np.float64),
                            Times = [datetime.datetime(*dt) for dt in [(2004, 1, 5, 4, 0),
                                                                       (2004, 1, 6, 5, 0),
                                                                       (2004, 2, 6, 4, 0),
                                                                       (2004, 2, 7, 4, 0),
                                                                       (2004, 3, 5, 4, 0),
                                                                       (2004, 3, 5, 6, 0),
                                                                       (2004, 4, 5, 4, 0),
                                                                       (2004, 4, 5, 5, 0),
                                                                       (2004, 5, 5, 1, 0),
                                                                       (2004, 5, 5, 4, 0),
                                                                       (2004, 6, 5, 4, 0),
                                                                       (2004, 7, 5, 4, 0),
                                                                       (2004, 8, 5, 4, 0),
                                                                       (2004, 9, 5, 4, 0),
                                                                       (2004, 10, 5, 4, 0),
                                                                       (2004, 11, 5, 4, 0),
                                                                       (2004, 12, 5, 4, 0),
                                                                       (2004, 12, 5, 4, 0),]
                                     ],
                            )
예제 #15
0
class RoseFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.LastDir = os.getcwd()

        MenuBar = wx.MenuBar()

        FileMenu = wx.Menu()

        item = FileMenu.Append(wx.ID_ANY, "&Open")
        self.Bind(wx.EVT_MENU, self.OnOpen, item)

        item = FileMenu.Append(wx.ID_ANY, "&Save Image")
        self.Bind(wx.EVT_MENU, self.OnSaveImage, item)

        item = FileMenu.Append(wx.ID_ANY, "&Save Data Table")
        self.Bind(wx.EVT_MENU, self.OnSaveData, item)

        item = FileMenu.Append(wx.ID_PREFERENCES, "&Preferences")
        self.Bind(wx.EVT_MENU, self.OnPrefs, item)

        item = FileMenu.Append(wx.ID_EXIT, "&Exit")
        self.Bind(wx.EVT_MENU, self.OnQuit, item)

        MenuBar.Append(FileMenu, "&File")

        HelpMenu = wx.Menu()

        item = HelpMenu.Append(wx.ID_HELP, "Test &Help",
                               "Help for this simple test")
        self.Bind(wx.EVT_MENU, self.OnHelp, item)

        ## this gets put in the App menu on OS-X
        item = HelpMenu.Append(wx.ID_ABOUT, "&About",
                               "More information About this program")
        self.Bind(wx.EVT_MENU, self.OnAbout, item)
        MenuBar.Append(HelpMenu, "&Help")

        self.SetMenuBar(MenuBar)

        self.Bind(wx.EVT_CLOSE, self.OnQuit)

        # a panel just to the the background color right on windows
        BGPanel = wx.Panel(self)
        self.WindRose = WindRosePanel(
            BGPanel,
            size=(600, 600),
        )
        self.WindRose.SetSizeHints(50, 50, -1, -1)
        self.WindRose.Canvas.SetSizeHints(50, 50, -1, -1)

        self.MonthSelector = wx.Choice(BGPanel, choices=months)
        self.MonthSelector.Selection = 0
        self.MonthSelector.Bind(wx.EVT_CHOICE, self.OnSelectMonth)

        self.NumBinsSelector = wx.Choice(BGPanel,
                                         choices=['4', '8', '16', '32'])
        self.NumBinsSelector.Selection = 2
        self.NumBinsSelector.Bind(wx.EVT_CHOICE, self.OnSelectNumBins)

        Stop = wx.BoxSizer(wx.HORIZONTAL)
        Stop.Add(self.MonthSelector, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        Stop.Add((1, 1), 1)
        Stop.Add(wx.StaticText(BGPanel, label="Number of Bins:"), 0,
                 wx.ALIGN_CENTER_VERTICAL)
        Stop.Add(self.NumBinsSelector, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        S = wx.BoxSizer(wx.VERTICAL)
        S.Add(Stop, 0, wx.EXPAND)
        S.Add(self.WindRose, 1, wx.EXPAND)

        BGPanel.SetSizer(S)
        self.Show()

        #self.vel_bins = [1, 5, 10, 15, 21,]
        self.vel_bins = [3, 6, 10, 15, 20, 25, 35, 55]
        self.num_dir_bins = 16

    def OnQuit(self, Event):
        self.Destroy()

    def OnAbout(self, event):
        dlg = wx.MessageDialog(
            self, "This is a small program to generate\n"
            "Wind Roses from historical wind data\n"
            " See Chris Barker for more info\n"
            "About Me", wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnHelp(self, event):
        dlg = wx.MessageDialog(self, "This would be help\n"
                               "If there was any\n", "Test Help",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnOpen(self, event):
        dlg = wx.FileDialog(
            self,
            message="Choose a wind file",
            defaultDir=self.LastDir,
            defaultFile="",
            #wildcard=wildcard,
            style=wx.FD_OPEN | wx.FD_CHANGE_DIR)

        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            path = dlg.GetPath()
            self.LastDir = os.path.split(path)[0]
            self.LoadNewFile(path)
        dlg.Destroy()

    def OnSaveImage(self, evt):
        dlg = wx.FileDialog(self,
                            message="Choose an image file name",
                            defaultDir=self.LastDir,
                            defaultFile="",
                            wildcard="*.png",
                            style=wx.FD_SAVE | wx.FD_CHANGE_DIR)

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            self.LastDir = os.path.split(path)[0]
            self.WindRose.SaveImage(path)
        dlg.Destroy()

    def OnSaveData(self, evt):
        dlg = wx.FileDialog(self,
                            message="Choose a data file",
                            defaultDir=self.LastDir,
                            defaultFile="",
                            wildcard="*.csv",
                            style=wx.SAVE | wx.CHANGE_DIR)

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            self.LastDir = os.path.split(path)[0]
            self.WindRose.SaveBinTable(path)
        dlg.Destroy()

    def OnPrefs(self, event):
        dlg = wx.MessageDialog(
            self, "This would be an preferences Dialog\n"
            "If there were any preferences to set.\n", "Preferences",
            wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def LoadNewFile(self, infilename):
        try:
            self.MetData = MetData(infilename)
        except Exception as err:
            dlg = wx.MessageDialog(self, str(err), "File Not Loaded",
                                   wx.OK | wx.ICON_WARNING)
            dlg.ShowModal()
            dlg.Destroy()
        self.MonthSelector.SetStringSelection("All Year")
        self.OnSelectMonth()

    def OnSelectMonth(self, evt=None):
        month = self.MonthSelector.StringSelection
        month_ind = months.index(month)

        if month_ind == 0:  # All Year
            data = self.MetData.GetFieldsAsArray(
                ("WindSpeed", "WindDirection"))
        else:
            data = self.MetData.GetFieldsMonthlyAsArray(
                (month_ind, ), ("WindSpeed", "WindDirection"))

        if len(data) == 0:
            self.WindRose.DrawMessage("No Data for %s" % month)
        else:
            units = self.MetData.Units['WindSpeed']
            if units == 'knots':
                vel_bins = [3, 6, 10, 15, 20, 25, 35, 55]
            elif units == 'm/s':
                vel_bins = [1, 5, 10, 15, 21]
            else:
                vel_bins = self.vel_bins

            title = title = "%s: %s" % (self.MetData.Name, month)
            Rose = WindRose(
                data,
                vel_bins,
                num_dir_bins=self.num_dir_bins,
                units=units,
                title=title,
            )
            self.WindRose.DrawRose(Rose)

    def OnSelectNumBins(self, evt=None):
        self.num_dir_bins = int(self.NumBinsSelector.StringSelection)
        self.OnSelectMonth()
예제 #16
0
import sys
from windtools import MetData

try:
    infilename = sys.argv[1]
except IndexError:
    print(Usage)
    sys.exit()
outfilename = infilename.rsplit('.', 1)[0] + ".OSM"

try:
    timeZone = int(sys.argv[2])
except IndexError:
    timeZone = 0

try:
    timeZoneName = sys.argv[3]
except IndexError:
    timeZoneName = ""

print("Reading:", infilename)
data = MetData(infilename)

print("Converting to:", outfilename)
if timeZone != 0:
    data.ChangeTZ(timeZone, timeZoneName)

data.SaveAsOSSMWind(outfilename, units='knots')

#Data.SaveAsOSSMWind(outfilename)