Skip to content

Commit

Permalink
Merge pull request #128 from casangi/103-write-unit-tests-for-astroha…
Browse files Browse the repository at this point in the history
…ckdio

103 write unit tests for astrohackdio
  • Loading branch information
jrhosk authored Aug 1, 2023
2 parents 8b4e68e + c1cba74 commit 5e6dc30
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/unit/test_dio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from astrohack.gdown_utils import gdown_data
from astrohack.dio import open_holog
from astrohack.dio import open_image
from astrohack.dio import open_panel
from astrohack.dio import open_pointing
from astrohack.extract_holog import extract_holog
from astrohack.extract_holog import extract_pointing
from astrohack.panel import panel
from astrohack import holog

import pytest
import numpy as np
import shutil

class TestAstrohackDio():
datafolder = 'dioData'
holog_mds = dict()
image_mds = dict()
panel_mds = dict()

@classmethod
def setup_class(cls):
gdown_data('ea25_cal_small_after_fixed.split.ms', download_folder=cls.datafolder)

extract_pointing(ms_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.ms',
point_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr',
parallel=True,
overwrite=True)

cls.holog_mds = extract_holog(ms_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.ms',
point_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr',
data_column='CORRECTED_DATA',
parallel=True,
overwrite=True)

cell_size = np.array([-0.0006442, 0.0006442]) # arcseconds
grid_size = np.array([31, 31]) # pixels

cls.image_mds = holog(holog_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.holog.zarr',
overwrite=True,
phase_fit=True,
apply_mask=True,
to_stokes=True,
parallel=True)

panel_model = 'rigid'

cls.panel_mds = panel(image_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.image.zarr',
panel_model=panel_model,
parallel=True,
overwrite=True)

@classmethod
def teardown_class(cls):
shutil.rmtree(cls.datafolder)

def test_open_holog(self):
'''Open a holog file and return a holog data object'''
holog_data = open_holog(self.datafolder + '/ea25_cal_small_after_fixed.split.holog.zarr')
assert holog_data == self.holog_mds

def test_open_image(self):
'''Open an image file and return an image data object'''
image_data = open_image(self.datafolder + '/ea25_cal_small_after_fixed.split.image.zarr')
assert image_data == self.image_mds

def test_open_panel(self):
'''Open a panel file and return a panel data object'''
panel_data = open_panel(self.datafolder + '/ea25_cal_small_after_fixed.split.panel.zarr')
assert panel_data == self.panel_mds

def test_open_pointing(self):
'''Open a pointing file and return a pointing data object'''
pointing_data = open_pointing(self.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr')
# check if keys match expected?
# How to check xarray content...
expected_keys = ['point_meta_ds', 'ant_ea25', 'ant_ea04', 'ant_ea06']
for key in pointing_data.keys():
assert key in expected_keys

0 comments on commit 5e6dc30

Please sign in to comment.