Skip to content

Commit a85cd9d

Browse files
authored
Merge pull request #73 from Projeto-Jupiter/bug/mixed-calendars
Fix bug caused by mixed calendar systems.
2 parents f295465 + de682e8 commit a85cd9d

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

rocketpy/Environment.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

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

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

17641764
# Find time index
1765-
timeIndex = netCDF4.date2index(self.date, timeArray, select="nearest")
1765+
timeIndex = netCDF4.date2index(
1766+
self.date, timeArray, calendar="gregorian", select="nearest"
1767+
)
17661768
# Convert times do dates and numbers
1767-
inputTimeNum = netCDF4.date2num(self.date, timeArray.units, calendar="standard")
1769+
inputTimeNum = netCDF4.date2num(
1770+
self.date, timeArray.units, calendar="gregorian"
1771+
)
17681772
fileTimeNum = timeArray[timeIndex]
1769-
fileTimeDate = netCDF4.num2date(timeArray[timeIndex], timeArray.units)
1773+
fileTimeDate = netCDF4.num2date(
1774+
timeArray[timeIndex], timeArray.units, calendar="gregorian"
1775+
)
17701776
# Check if time is inside range supplied by file
17711777
if timeIndex == 0 and inputTimeNum < fileTimeNum:
17721778
raise ValueError(
@@ -2039,10 +2045,16 @@ def processForecastReanalysis(self, file, dictionary):
20392045
)
20402046

20412047
# Compute info data
2042-
self.atmosphericModelInitDate = netCDF4.num2date(timeArray[0], timeArray.units)
2043-
self.atmosphericModelEndDate = netCDF4.num2date(timeArray[-1], timeArray.units)
2048+
self.atmosphericModelInitDate = netCDF4.num2date(
2049+
timeArray[0], timeArray.units, calendar="gregorian"
2050+
)
2051+
self.atmosphericModelEndDate = netCDF4.num2date(
2052+
timeArray[-1], timeArray.units, calendar="gregorian"
2053+
)
20442054
self.atmosphericModelInterval = netCDF4.num2date(
2045-
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1), timeArray.units
2055+
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1),
2056+
timeArray.units,
2057+
calendar="gregorian",
20462058
).hour
20472059
self.atmosphericModelInitLat = latArray[0]
20482060
self.atmosphericModelEndLat = latArray[-1]
@@ -2145,11 +2157,17 @@ def processEnsemble(self, file, dictionary):
21452157
latArray = weatherData.variables[dictionary["latitude"]][:].tolist()
21462158

21472159
# Find time index
2148-
timeIndex = netCDF4.date2index(self.date, timeArray, select="nearest")
2160+
timeIndex = netCDF4.date2index(
2161+
self.date, timeArray, calendar="gregorian", select="nearest"
2162+
)
21492163
# Convert times do dates and numbers
2150-
inputTimeNum = netCDF4.date2num(self.date, timeArray.units)
2164+
inputTimeNum = netCDF4.date2num(
2165+
self.date, timeArray.units, calendar="gregorian"
2166+
)
21512167
fileTimeNum = timeArray[timeIndex]
2152-
fileTimeDate = netCDF4.num2date(timeArray[timeIndex], timeArray.units)
2168+
fileTimeDate = netCDF4.num2date(
2169+
timeArray[timeIndex], timeArray.units, calendar="gregorian"
2170+
)
21532171
# Check if time is inside range supplied by file
21542172
if timeIndex == 0 and inputTimeNum < fileTimeNum:
21552173
raise ValueError(
@@ -2390,10 +2408,16 @@ def processEnsemble(self, file, dictionary):
23902408
)
23912409

23922410
# Compute info data
2393-
self.atmosphericModelInitDate = netCDF4.num2date(timeArray[0], timeArray.units)
2394-
self.atmosphericModelEndDate = netCDF4.num2date(timeArray[-1], timeArray.units)
2411+
self.atmosphericModelInitDate = netCDF4.num2date(
2412+
timeArray[0], timeArray.units, calendar="gregorian"
2413+
)
2414+
self.atmosphericModelEndDate = netCDF4.num2date(
2415+
timeArray[-1], timeArray.units, calendar="gregorian"
2416+
)
23952417
self.atmosphericModelInterval = netCDF4.num2date(
2396-
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1), timeArray.units
2418+
(timeArray[-1] - timeArray[0]) / (len(timeArray) - 1),
2419+
timeArray.units,
2420+
calendar="gregorian",
23972421
).hour
23982422
self.atmosphericModelInitLat = latArray[0]
23992423
self.atmosphericModelEndLat = latArray[-1]

0 commit comments

Comments
 (0)