Skip to content

Commit 2606ba8

Browse files
committed
bugs: fism csv file needs to be comma separated, without any #start
1 parent 50efe33 commit 2606ba8

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

srcPython/fism.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ def getFism2(dateStart, dateEnd, source, downloadDir=None):
4949
A 2D array where each row is a spectrum at a particular time, and the columns are wavelength bands.
5050
"""
5151
# Converting the input time strings to datetimes:
52-
dateStartDatetime = datetime.strptime(dateStart, "%Y-%m-%d")
53-
dateEndDatetime = datetime.strptime(dateEnd, "%Y-%m-%d")
52+
try:
53+
dateStartDatetime = datetime.strptime(dateStart, "%Y-%m-%d")
54+
dateEndDatetime = datetime.strptime(dateEnd, "%Y-%m-%d")
55+
except:
56+
dateStartDatetime = datetime.strptime(dateStart, "%Y%m%d")
57+
dateEndDatetime = datetime.strptime(dateEnd, "%Y%m%d")
5458

5559
# Check if the user has asked for a source that can be obtained:
5660
validSources = ['FISM2', 'FISM2S']
@@ -262,10 +266,7 @@ def saveFism(data, times, filename):
262266
"""
263267
# A helper function for working with integers:
264268
def numStr(num):
265-
if int(num) < 10:
266-
return ' ' + str(int(num))
267-
else:
268-
return str(int(num))
269+
return ',' + str(int(num))
269270

270271
# Define a helper function for opening a file to write the data, in such a way as to include parent directories if
271272
# needed:
@@ -279,23 +280,23 @@ def safe_open_w(path):
279280
# Open the new file and begin writing, line by line:
280281
with safe_open_w(str(filename)) as output:
281282
# Write the header information:
282-
output.write("#START\n")
283+
# output.write("#START\n")
283284
# Write the irradiances themselves:
284285
firstLine = ['%.6g' % (element) for element in data[0, :]]
285-
firstLine_joined = ' '.join(firstLine)
286+
firstLine_joined = ','.join(firstLine)
286287
# The first line should always be a duplicate of the first line of data, but starting at UTC=00:00 of the first date:
287-
output.write(' ' + str(times[0].year) + ' ' + numStr(times[0].month) + ' ' + numStr(
288-
times[0].day) + ' 0 0 0 ' + firstLine_joined + '\n')
288+
output.write(str(times[0].year) + numStr(times[0].month) + numStr(
289+
times[0].day) + ',0,0,0,' + firstLine_joined + '\n')
289290
# The rest of the lines can be straight from the data:
290291
for i in range(data.shape[0]):
291-
currentLine_joined = ' '.join(['%.6g' % (element) for element in data[i, :]])
292-
output.writelines(' ' + str(times[i].year) + ' ' + numStr(times[i].month) + ' ' + numStr(
293-
times[i].day) + ' ' + numStr(times[i].hour) + ' 0 0 ' + currentLine_joined + '\n')
292+
currentLine_joined = ','.join(['%.6g' % (element) for element in data[i, :]])
293+
output.writelines(str(times[i].year) + numStr(times[i].month) + numStr(
294+
times[i].day) + numStr(times[i].hour) + ',0,0,' + currentLine_joined + '\n')
294295
# The last line should occur 12 hours from the last datapoint, but have duplicate values there:
295-
lastLine_joined = ' '.join(['%.6g' % (element) for element in data[-1, :]])
296+
lastLine_joined = ','.join(['%.6g' % (element) for element in data[-1, :]])
296297
lastTime = times[-1] + timedelta(hours=12)
297-
output.write(' ' + str(lastTime.year) + ' ' + numStr(lastTime.month) + ' ' + numStr(
298-
lastTime.day) + ' 0 0 0 ' + lastLine_joined + '\n')
298+
output.write(str(lastTime.year) + numStr(lastTime.month) + numStr(
299+
lastTime.day) + ',0,0,0,' + lastLine_joined + '\n')
299300

300301
print('FISM2 data saved to: ')
301302
os.system('readlink -f '+str(filename))

0 commit comments

Comments
 (0)