Skip to content
Snippets Groups Projects
Commit 672f7ec5 authored by Mattia Mancini's avatar Mattia Mancini
Browse files

SSB-47: checking speed without reading data

parent fcb0eb7b
No related branches found
No related tags found
1 merge request!44Merge back holography to master
import logging import logging
import os import os
import h5py import h5py
from lofar.calibration.common.datacontainers.holography_observation import HolographyObservation
from .holography_dataset_definitions import * from .holography_dataset_definitions import *
from .holography_specification import HolographySpecification from .holography_specification import HolographySpecification
from .holography_observation import HolographyObservation
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
...@@ -544,13 +542,52 @@ class HolographyDataset(): ...@@ -544,13 +542,52 @@ class HolographyDataset():
@staticmethod @staticmethod
def load_from_file(path): def load_from_file(path):
""" """
It reads a holography dataset from an HDF5 file and returns a Read a holography dataset from an HDF5 file and returns a
HolographyDataset class HolographyDataset class
:param path: path to file :param path: path to file
:return: the read dataset :return: the read dataset
""" """
f = None f = None
try:
result, f = HolographyDataset.open_holography_file(path)
result.data = dict()
for reference_station in f["CROSSCORRELATION"].keys():
for frequency in f["CROSSCORRELATION"][reference_station].keys():
for beamlet in f["CROSSCORRELATION"][reference_station][frequency].keys():
if reference_station not in result.data:
result.data[reference_station] = dict()
if frequency not in result.data[reference_station]:
result.data[reference_station][frequency] = dict()
result.data[reference_station][frequency][beamlet] = numpy.array(
f["CROSSCORRELATION"][reference_station][frequency][beamlet])
if '/DERIVED_DATA' in f:
result.derived_data = HolographyDataset._read_grouped_data(f, '/DERIVED_DATA')
except Exception as e:
logger.exception(
"Cannot read the Holography Data Set data from the HDF5 file \"%s\"."
" This is the exception that was thrown: %s",
path, e)
raise e
finally:
if f is not None:
f.close()
return result
@staticmethod
def open_holography_file(path: str):
"""
Opens the Holography HDF file for access and returns the Holography Dataset and
it's file descriptor
:param path: path to file
:return: the read dataset
:rtype: List[HolographyDataset, h5py.File]
"""
f = None
if not os.path.exists(path): if not os.path.exists(path):
raise FileNotFoundError(path) raise FileNotFoundError(path)
...@@ -584,32 +621,26 @@ class HolographyDataset(): ...@@ -584,32 +621,26 @@ class HolographyDataset():
result.ra_dec[frequency][beamlet] = numpy.array(f["RA_DEC"][frequency][beamlet]) result.ra_dec[frequency][beamlet] = numpy.array(f["RA_DEC"][frequency][beamlet])
beamlets = set() beamlets = set()
result.data = dict()
for reference_station in f["CROSSCORRELATION"].keys(): for reference_station in f["CROSSCORRELATION"].keys():
for frequency in f["CROSSCORRELATION"][reference_station].keys(): for frequency in f["CROSSCORRELATION"][reference_station].keys():
for beamlet in f["CROSSCORRELATION"][reference_station][frequency].keys(): for beamlet in f["CROSSCORRELATION"][reference_station][frequency].keys():
beamlets.add(int(beamlet)) beamlets.add(int(beamlet))
if reference_station not in result.data:
result.data[reference_station] = dict() result.data = f['CROSSCORRELATION']
if frequency not in result.data[reference_station]:
result.data[reference_station][frequency] = dict()
result.data[reference_station][frequency][beamlet] = numpy.array(
f["CROSSCORRELATION"][reference_station][frequency][beamlet])
result.central_beamlets = HolographyDataset._read_grouped_data(f, HDS_CENTRAL_BEAMLETS) result.central_beamlets = HolographyDataset._read_grouped_data(f, HDS_CENTRAL_BEAMLETS)
if '/DERIVED_DATA' in f: if '/DERIVED_DATA' in f:
result.derived_data = HolographyDataset._read_grouped_data(f, '/DERIVED_DATA') result.derived_data = f['/DERIVED_DATA']
except Exception as e: except Exception as e:
logger.exception( logger.exception(
"Cannot read the Holography Data Set data from the HDF5 file \"%s\". This is the exception that was thrown: %s", "Cannot read the Holography Data Set data from the HDF5 file \"%s\"."
" This is the exception that was thrown: %s",
path, e) path, e)
raise e raise e
finally:
if f is not None:
f.close()
return result return result, f
def store_to_file(self, path): def store_to_file(self, path):
""" """
...@@ -679,7 +710,8 @@ class HolographyDataset(): ...@@ -679,7 +710,8 @@ class HolographyDataset():
except Exception as e: except Exception as e:
logger.exception( logger.exception(
"Cannot write the Holography Data Set data to the HDF5 file \"%s\". This is the exception that was thrown: %s", "Cannot write the Holography Data Set data to the HDF5 file \"%s\"."
" This is the exception that was thrown: %s",
path, e) path, e)
raise e raise e
finally: finally:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment