def test_astro_utils_time_fits_to_mjd_2(self): sec_tol = 0.00000001 mjd = AstroUtils.time_fits_to_mjd("2020-01-23T10:56:53.000") assert abs(58871.45616898 - mjd) <= sec_tol
def test_astro_utils_time_utc_to_mjd(self): tol = 0.00000001 dt = "2020-01-23T10:56:53.000" mjd = AstroUtils.time_fits_to_mjd(dt) assert abs(58871.45616898 - mjd) <= tol
def test_unix_conversion(input_date, expected): assert AstroUtils.time_fits_to_agile_seconds( input_date) == expected["agile_seconds"] assert AstroUtils.time_fits_to_jd(input_date) == pytest.approx( expected["jd"], 0.00001) assert AstroUtils.time_fits_to_mjd(input_date) == pytest.approx( expected["mjd"], 0.00001) assert AstroUtils.time_fits_to_unix(input_date) == expected["unix"] assert AstroUtils.time_fits_to_iso(input_date) == expected["iso"]
def test_extract_data_log(self, logger, datacoveragepath): queryLOGPath = Path(__file__).absolute().parent.joinpath( "test_data", "test_extract_data_LOG.qfile") agdataset = AGDataset(logger, datacoveragepath=datacoveragepath) # Test - inside of multiple lines # ================= # ^ # ================= # ^ tmin = "2017-10-27T00:00:00" tmax = "2017-10-30T00:00:00" assert DataStatus.OK == agdataset.dataIsMissing( AstroUtils.time_fits_to_mjd(tmin), AstroUtils.time_fits_to_mjd(tmax), queryLOGPath) # Test - inside range # ================= # ^ ^ tmin = "2017-10-27T00:00:00" tmax = "2017-10-27T05:00:00" assert DataStatus.OK == agdataset.dataIsMissing( AstroUtils.time_fits_to_mjd(tmin), AstroUtils.time_fits_to_mjd(tmax), queryLOGPath) # Test - totally missing data # ================= # ^ ^ tmin = "2022-01-27T00:00:00" # 2015-01-10T00:00:00 tmax = "2022-01-30T00:00:00" # 2015-01-20T00:00:00 assert DataStatus.MISSING == agdataset.dataIsMissing( AstroUtils.time_fits_to_mjd(tmin), AstroUtils.time_fits_to_mjd(tmax), queryLOGPath) # Test - partial missing data on multiple lines # ================= # ^ # ================= # ^ tmin = "2018-02-09T00:00:00" tmax = "2018-02-25T00:00:00" assert DataStatus.MISSING == agdataset.dataIsMissing( AstroUtils.time_fits_to_mjd(tmin), AstroUtils.time_fits_to_mjd(tmax), queryLOGPath)
def downloadData(self, tmin, tmax, dataPath, evtIndex, logIndex): """ It downloads EVT and LOG data that the user requires to perform a scientific analysis from tmin to tmax (in MJD format). If the data is already present on disk, the download will be skipped. The actual data being downloaded could correspond to a bigger interval than tmin and tmax: this is because the SSDC rest service. @param tmin: mjd @param tmax: mjd """ # print(tmax, self.coverage_tmax) if tmax > AstroUtils.time_fits_to_mjd(self.coverage_tmax): raise NoCoverageDataError("tmax exceeds AGILE data coverage") dataPath = Path(dataPath) evtPath = dataPath.joinpath("EVT") logPath = dataPath.joinpath("LOG") evtQfile = dataPath.joinpath("EVT.qfile") logQfile = dataPath.joinpath("LOG.qfile") evtDataMissing = False logDataMissing = False if self.dataIsMissing(tmin, tmax, evtQfile) == DataStatus.MISSING: self.logger.info( self, f"EVT data in interval {tmin} {tmax} is missing!") evtDataMissing = True else: self.logger.info(self, f"Local data for EVT already in dataset") if self.dataIsMissing(tmin, tmax, logQfile) == DataStatus.MISSING: self.logger.info( self, f"LOG data in interval {tmin} {tmax} is missing!") logDataMissing = True else: self.logger.info(self, f"Local data for LOG already in dataset") if evtDataMissing or logDataMissing: self.logger.info(self, f"Downloading data from ssdc..") _ = self.agrest.gridList(tmin, tmax) tarFilePath = self.agrest.gridFiles(tmin, tmax) self.logger.info(self, f"Extracting data from the tarball..") if evtDataMissing: extractedFiles = self.extractData("EVT", tarFilePath, dataPath) self.logger.debug(self, f"Extracted files: {extractedFiles}") self.updateQFile(evtQfile, tmin, tmax, evtQfile) self.generateIndex(evtPath, "EVT", evtIndex) if logDataMissing: extractedFiles = self.extractData("LOG", tarFilePath, dataPath) self.logger.debug(self, f"Extracted files: {extractedFiles}") self.updateQFile(logQfile, tmin, tmax, logQfile) self.generateIndex(logPath, "LOG", logIndex) if evtDataMissing or logDataMissing: os.remove(tarFilePath) return evtDataMissing or logDataMissing