@@ -49,8 +49,12 @@ def getFism2(dateStart, dateEnd, source, downloadDir=None):
49
49
A 2D array where each row is a spectrum at a particular time, and the columns are wavelength bands.
50
50
"""
51
51
# 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" )
54
58
55
59
# Check if the user has asked for a source that can be obtained:
56
60
validSources = ['FISM2' , 'FISM2S' ]
@@ -262,10 +266,7 @@ def saveFism(data, times, filename):
262
266
"""
263
267
# A helper function for working with integers:
264
268
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 ))
269
270
270
271
# Define a helper function for opening a file to write the data, in such a way as to include parent directories if
271
272
# needed:
@@ -279,23 +280,23 @@ def safe_open_w(path):
279
280
# Open the new file and begin writing, line by line:
280
281
with safe_open_w (str (filename )) as output :
281
282
# Write the header information:
282
- output .write ("#START\n " )
283
+ # output.write("#START\n")
283
284
# Write the irradiances themselves:
284
285
firstLine = ['%.6g' % (element ) for element in data [0 , :]]
285
- firstLine_joined = ' ' .join (firstLine )
286
+ firstLine_joined = ', ' .join (firstLine )
286
287
# 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 ' )
289
290
# The rest of the lines can be straight from the data:
290
291
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 ' )
294
295
# 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 , :]])
296
297
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 ' )
299
300
300
301
print ('FISM2 data saved to: ' )
301
302
os .system ('readlink -f ' + str (filename ))
0 commit comments