Skip to content

Commit

Permalink
Merge pull request #73 from Projeto-Jupiter/bug/mixed-calendars
Browse files Browse the repository at this point in the history
Fix bug caused by mixed calendar systems.
  • Loading branch information
Lucas-KB committed Aug 11, 2021
2 parents f295465 + de682e8 commit a85cd9d
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions rocketpy/Environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

__author__ = "Giovani Hidalgo Ceotto, Guilherme Fernandes Alves, Lucas Azevedo Pezente"
__author__ = "Giovani Hidalgo Ceotto, Guilherme Fernandes Alves, Lucas Azevedo Pezente, Oscar Mauricio Prada Ramirez, Lucas Kierulff Balabram"
__copyright__ = "Copyright 20XX, Projeto Jupiter"
__license__ = "MIT"

Expand Down Expand Up @@ -1713,7 +1713,7 @@ def processForecastReanalysis(self, file, dictionary):
file : string
String containing path to local netCDF file or URL of an
OPeNDAP file, such as NOAA's NOMAD or UCAR TRHEDDS server.
dicitonary : dictionary
dictionary : dictionary
Specifies the dictionary to be used when reading netCDF and
OPeNDAP files, allowing for the correct retrieval of data.
The dictionary structure should specify the short names
Expand Down Expand Up @@ -1762,11 +1762,17 @@ def processForecastReanalysis(self, file, dictionary):
latArray = weatherData.variables[dictionary["latitude"]][:].tolist()

# Find time index
timeIndex = netCDF4.date2index(self.date, timeArray, select="nearest")
timeIndex = netCDF4.date2index(
self.date, timeArray, calendar="gregorian", select="nearest"
)
# Convert times do dates and numbers
inputTimeNum = netCDF4.date2num(self.date, timeArray.units, calendar="standard")
inputTimeNum = netCDF4.date2num(
self.date, timeArray.units, calendar="gregorian"
)
fileTimeNum = timeArray[timeIndex]
fileTimeDate = netCDF4.num2date(timeArray[timeIndex], timeArray.units)
fileTimeDate = netCDF4.num2date(
timeArray[timeIndex], timeArray.units, calendar="gregorian"
)
# Check if time is inside range supplied by file
if timeIndex == 0 and inputTimeNum < fileTimeNum:
raise ValueError(
Expand Down Expand Up @@ -2039,10 +2045,16 @@ def processForecastReanalysis(self, file, dictionary):
)

# Compute info data
self.atmosphericModelInitDate = netCDF4.num2date(timeArray[0], timeArray.units)
self.atmosphericModelEndDate = netCDF4.num2date(timeArray[-1], timeArray.units)
self.atmosphericModelInitDate = netCDF4.num2date(
timeArray[0], timeArray.units, calendar="gregorian"
)
self.atmosphericModelEndDate = netCDF4.num2date(
timeArray[-1], timeArray.units, calendar="gregorian"
)
self.atmosphericModelInterval = netCDF4.num2date(
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1), timeArray.units
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1),
timeArray.units,
calendar="gregorian",
).hour
self.atmosphericModelInitLat = latArray[0]
self.atmosphericModelEndLat = latArray[-1]
Expand Down Expand Up @@ -2145,11 +2157,17 @@ def processEnsemble(self, file, dictionary):
latArray = weatherData.variables[dictionary["latitude"]][:].tolist()

# Find time index
timeIndex = netCDF4.date2index(self.date, timeArray, select="nearest")
timeIndex = netCDF4.date2index(
self.date, timeArray, calendar="gregorian", select="nearest"
)
# Convert times do dates and numbers
inputTimeNum = netCDF4.date2num(self.date, timeArray.units)
inputTimeNum = netCDF4.date2num(
self.date, timeArray.units, calendar="gregorian"
)
fileTimeNum = timeArray[timeIndex]
fileTimeDate = netCDF4.num2date(timeArray[timeIndex], timeArray.units)
fileTimeDate = netCDF4.num2date(
timeArray[timeIndex], timeArray.units, calendar="gregorian"
)
# Check if time is inside range supplied by file
if timeIndex == 0 and inputTimeNum < fileTimeNum:
raise ValueError(
Expand Down Expand Up @@ -2390,10 +2408,16 @@ def processEnsemble(self, file, dictionary):
)

# Compute info data
self.atmosphericModelInitDate = netCDF4.num2date(timeArray[0], timeArray.units)
self.atmosphericModelEndDate = netCDF4.num2date(timeArray[-1], timeArray.units)
self.atmosphericModelInitDate = netCDF4.num2date(
timeArray[0], timeArray.units, calendar="gregorian"
)
self.atmosphericModelEndDate = netCDF4.num2date(
timeArray[-1], timeArray.units, calendar="gregorian"
)
self.atmosphericModelInterval = netCDF4.num2date(
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1), timeArray.units
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1),
timeArray.units,
calendar="gregorian",
).hour
self.atmosphericModelInitLat = latArray[0]
self.atmosphericModelEndLat = latArray[-1]
Expand Down

0 comments on commit a85cd9d

Please sign in to comment.