def test_netcdf_time_to_timestamp(self): s = "2015-01-01" dt = eva.netcdf_time_to_timestamp(s) self.assertEqual(dt.year, 2015) self.assertEqual(dt.month, 1) self.assertEqual(dt.day, 1) self.assertEqual(dt.hour, 0) self.assertEqual(dt.minute, 0) self.assertEqual(dt.second, 0) self.assertEqual(dt.tzinfo.tzname(None), 'UTC') s = "2016-06-13 06" dt = eva.netcdf_time_to_timestamp(s) self.assertEqual(dt.year, 2016) self.assertEqual(dt.month, 6) self.assertEqual(dt.day, 13) self.assertEqual(dt.hour, 6) self.assertEqual(dt.minute, 0) self.assertEqual(dt.second, 0) self.assertEqual(dt.tzinfo.tzname(None), 'UTC')
def parse_file_recognition_output(self, lines): """! @brief Parse standard output containing time dimensions from NetCDF files into a structured format. @returns A list of dictionaries with file and time dimension information. """ result = [] for line in lines: # Each output line looks like this: # /tmp/meteo20160606_00.nc time = "2016-06-06 12", "2016-06-06 15", "2016-06-06 18", "2016-06-06 21", "2016-06-07" ; if len(line) < 5: continue data = {} tokens = line.split() data['path'] = tokens[0] data['extension'] = os.path.splitext(data['path'])[1] if self.is_netcdf_data_output(data): time_str = ' '.join(tokens[3:-1]) times = sorted([eva.netcdf_time_to_timestamp(x.strip(' "')) for x in time_str.split(',')]) data['time_steps'] = times result += [data] return result