<commit_before># -*- mode: python; coding: utf-8 -*
# Copyright (c) 2018 Radio Astronomy Software Group
# Licensed under the 2-clause BSD License

"""Tests for FHD_cal object."""
from __future__ import absolute_import, division, print_function

import pytest
import os

from pyuvdata import UVCal
import pyuvdata.tests as uvtest
from pyuvdata.data import DATA_PATH

# set up FHD file list
testdir = os.path.join(DATA_PATH, 'fhd_cal_data/')
testfile_prefix = '1061316296_'
obs_testfile = os.path.join(testdir, testfile_prefix + 'obs.sav')
cal_testfile = os.path.join(testdir, testfile_prefix + 'cal.sav')
settings_testfile = os.path.join(testdir, testfile_prefix + 'settings.txt')


def test_ReadFHDcalWriteReadcalfits():
    """
    FHD cal to calfits loopback test.

    Read in FHD cal files, write out as calfits, read back in and check for
    object equality.
    """
    fhd_cal = UVCal()
    calfits_cal = UVCal()
    fhd_cal.read_fhd_cal(cal_testfile, obs_testfile,
                         settings_file=settings_testfile)

    outfile = os.path.join(DATA_PATH, 'test/outtest_FHDcal_1061311664.calfits')
    fhd_cal.write_calfits(outfile, clobber=True)
    calfits_cal.read_calfits(outfile)
    assert fhd_cal == calfits_cal

    # do it again with fit gains (rather than raw)
    fhd_cal.read_fhd_cal(cal_testfile, obs_testfile,
                         settings_file=settings_testfile, raw=False)
    outfile = os.path.join(DATA_PATH, 'test/outtest_FHDcal_1061311664.calfits')
    fhd_cal.write_calfits(outfile, clobber=True)
    calfits_cal.read_calfits(outfile)
    assert fhd_cal == calfits_cal


def test_extra_history():
    """Test that setting the extra_history keyword works."""
    fhd_cal = UVCal()
    calfits_cal = UVCal()
    extra_history = 'Some extra history for testing\n'
    fhd_cal.read_fhd_cal(cal_testfile, obs_testfile,
                         settings_file=settings_testfile,<commit_msg>add test that fails on master because of the bug<commit_after># -*- mode: python; coding: utf-8 -*
# Copyright (c) 2018 Radio Astronomy Software Group
# Licensed under the 2-clause BSD License

"""Tests for FHD_cal object."""
from __future__ import absolute_import, division, print_function

import pytest
import os

import numpy as np

from pyuvdata import UVCal
import pyuvdata.tests as uvtest
from pyuvdata.data import DATA_PATH

# set up FHD file list
testdir = os.path.join(DATA_PATH, 'fhd_cal_data/')
testfile_prefix = '1061316296_'
obs_testfile = os.path.join(testdir, testfile_prefix + 'obs.sav')
cal_testfile = os.path.join(testdir, testfile_prefix + 'cal.sav')
settings_testfile = os.path.join(testdir, testfile_prefix + 'settings.txt')


def test_ReadFHDcalWriteReadcalfits():
    """
    FHD cal to calfits loopback test.

    Read in FHD cal files, write out as calfits, read back in and check for
    object equality.
    """
    fhd_cal = UVCal()
    calfits_cal = UVCal()
    fhd_cal.read_fhd_cal(cal_testfile, obs_testfile,
                         settings_file=settings_testfile)

    assert np.max(fhd_cal.gain_array) < 2.

    outfile = os.path.join(DATA_PATH, 'test/outtest_FHDcal_1061311664.calfits')
    fhd_cal.write_calfits(outfile, clobber=True)
    calfits_cal.read_calfits(outfile)
    assert fhd_cal == calfits_cal

    # do it again with fit gains (rather than raw)
    fhd_cal.read_fhd_cal(cal_testfile, obs_testfile,
                         settings_file=settings_testfile, raw=False)
    outfile = os.path.join(DATA_PATH, 'test/outtest_FHDcal_1061311664.calfits')
    fhd_cal.write_calfits(outfile, clobber=True)
    calfits_cal.read_calfits(outfile)
    assert fhd_cal == calfits_cal


def test_extra_history():
    """Test that setting the extra_history keyword works."""
    fhd_cal = UVCal()
    calfits_cal = UVCal()
    extra_history = 'Some extra history for testing\n'
    fhd_cal.read_fhd_cal(cal_testfile, obs_testfile,
                         settings_file=settings_testfile,
{'fraction_non_alphanumeric': 0.08973384030418251, 'fraction_numerical': 0.01850443599493029, 'mean_word_length': 3.8655980271270036, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '100314', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1330, 'n_words': 317}