Skip to content

Commit

Permalink
Fix issue #20
Browse files Browse the repository at this point in the history
  • Loading branch information
giovaniceotto committed Jan 29, 2019
1 parent ef4067b commit a97620f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions nbks/rocketpyAlpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from datetime import datetime
from inspect import signature, getsourcelines
import bisect
import warnings

try:
import netCDF4
Expand Down Expand Up @@ -2320,6 +2321,28 @@ def processNetCDFFile(self, windData):
# Find time index
timeIndex = netCDF4.date2index(self.date, times, select='nearest')

# Convert times do dates and numbers
inputTimeNum = netCDF4.date2num(self.date, times.units)
fileTimeNum = times[timeIndex]
fileTimeDate = netCDF4.num2date(times[timeIndex], times.units)

# Temporary prints
# print('Time index: ', timeIndex)
# print('Input Num: ', inputTimeNum)
# print('Input Date: ', self.date)
# print('File Num: ', fileTimeNum)
# print('File Date: ', fileTimeDate)

# Check if time is inside range supplied by file
if timeIndex == 0 and inputTimeNum < fileTimeNum:
raise ValueError('Chosen launch time is not available in the provided file, which starts at {:%Y-%m-%d %H:%M}.'.format(fileTimeDate))
elif timeIndex == len(times) - 1 and inputTimeNum > fileTimeNum:
raise ValueError('Chosen launch time is not available in the provided file, which ends at {:%Y-%m-%d %H:%M}.'.format(fileTimeDate))

# Check if time is exactly equal to one in the file
if inputTimeNum != fileTimeNum:
warnings.warn('Exact chosen launch time is not available in the provided file, using {:%Y-%m-%d %H:%M} UTC instead.'.format(fileTimeDate))

# Find longitude index
lon = self.lon%360
lonIndex = None
Expand Down Expand Up @@ -2448,6 +2471,29 @@ def reprocessNetCDFFile(self):
# Find time index
timeIndex = netCDF4.date2index(self.date, times, select='nearest')

# Convert times do dates and numbers
inputTimeNum = netCDF4.date2num(self.date, times.units)
fileTimeNum = times[timeIndex]
fileTimeDate = netCDF4.num2date(times[timeIndex], times.units)

# Temporary prints
# print('Time index: ', timeIndex)
# print('Input Num: ', inputTimeNum)
# print('Input Date: ', self.date)
# print('File Num: ', fileTimeNum)
# print('File Date: ', fileTimeDate)

# Check if time is inside range supplied by file
if timeIndex == 0 and inputTimeNum < fileTimeNum:
raise ValueError('Chosen launch time is not available in the provided file, which starts at {:%Y-%m-%d %H:%M}.'.format(fileTimeDate))
elif timeIndex == len(times) - 1 and inputTimeNum > fileTimeNum:
raise ValueError('Chosen launch time is not available in the provided file, which ends at {:%Y-%m-%d %H:%M}.'.format(fileTimeDate))

# Check if time is exactly equal to one in the file
if inputTimeNum != fileTimeNum:
warnings.warn('Exact chosen launch time is not available in the provided file, using {:%Y-%m-%d %H:%M} UTC instead.'.format(fileTimeDate))


# Determine wind u and v components and height
windU = []
for i in range(len(levels)):
Expand Down

0 comments on commit a97620f

Please sign in to comment.