Exemplo n.º 1
0
def test_method_rename_ext_1():  # Raise on multi-ext
    ad = AstroData(TESTFILE)
    with pytest.raises(SingleHDUMemberExcept):
        ad.rename_ext("SCI", ver=99)
Exemplo n.º 2
0
def test_constructor_2():
    """ filename w mode option """
    ad = AstroData(dataset=TESTFILE, mode="update")
    assert ad.mode == 'update'
Exemplo n.º 3
0
def test_method_phu_get_key_val_3():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.phu_get_key_value('RA'), float)
Exemplo n.º 4
0
def test_method_set_key_val_6():
    ad = AstroData(TESTFILE2)
    with pytest.raises(TypeError):
        assert ad.set_key_value('FOO')
Exemplo n.º 5
0
def test_method_set_key_val_8():
    ad = AstroData(TESTFILE)
    with pytest.raises(AstroDataError):
        assert ad.set_key_value('BITPIX', 1)
Exemplo n.º 6
0
def test_method_set_key_val_1():
    ad = AstroData(TESTFILE2)
    ad.set_key_value('TESTKEY', 'TESTVALUE')
    assert ad.header['TESTKEY']
Exemplo n.º 7
0
def test_method_set_key_val_3():
    ad = AstroData(TESTFILE2)
    ad.set_key_value('CRVAL1', 1.0)
    assert isinstance(ad.header['CRVAL1'], float)
Exemplo n.º 8
0
def test_method_extname_2():
    ad = AstroData(TESTFILE2)
    assert ad.extname() == 'SCI'
Exemplo n.º 9
0
def test_method_extver_1():
    ad = AstroData(TESTFILE2)  # Single 'SCI' ext
    assert isinstance(ad.extver(), int)
Exemplo n.º 10
0
def test_method_rename_ext_5():  # TypeError w/ only 'ver=' param
    ad = AstroData(TESTFILE2)
    with pytest.raises(TypeError):
        ad.rename_ext(ver=2)
Exemplo n.º 11
0
def test_method_extname_1():
    ad = AstroData(TESTFILE2)  # Single 'SCI' ext
    assert isinstance(ad.extname(), str)
Exemplo n.º 12
0
def test_method_rename_ext_4():
    ad = AstroData(TESTFILE2)
    ad.rename_ext("FOO", ver=99)
    assert ad.extname() == "FOO"
    assert ad.extver() == 99
Exemplo n.º 13
0
def test_method_rename_ext_3():
    ad = AstroData(TESTFILE2)  # Single 'SCI' ext
    ad.rename_ext("FOO")
    assert ad.extname() == "FOO"
Exemplo n.º 14
0
def test_method_rename_ext_2():
    ad = AstroData(TESTFILE)
    with pytest.raises(SingleHDUMemberExcept):
        ad.rename_ext("FOO")
Exemplo n.º 15
0
def test_method_get_key_val_7():
    ad = AstroData(TESTFILE2)
    with pytest.raises(TypeError):
        assert ad.get_key_value()
Exemplo n.º 16
0
def test_method_extver_2():
    ad = AstroData(TESTFILE2)
    assert ad.extver() == 1
Exemplo n.º 17
0
def test_constructor_1():
    """ Good filename, def mode """
    ad = AstroData(dataset=TESTFILE)
    assert ad.mode == 'readonly'
Exemplo n.º 18
0
def test_method_extver_3():
    ad = AstroData(TESTFILE)
    with pytest.raises(SingleHDUMemberExcept):
        ad.extver()
Exemplo n.º 19
0
def test_method_set_key_val_2():
    ad = AstroData(TESTFILE2)
    ad.set_key_value('BITPIX', 999)
    assert isinstance(ad.header['BITPIX'], int)
Exemplo n.º 20
0
def test_constructor_0():
    """ Good filename """
    assert AstroData(dataset=TESTFILE)
Exemplo n.º 21
0
def test_method_set_key_val_4():
    ad = AstroData(TESTFILE2)
    test_comment = "This is a TESTKEY"
    ad.set_key_value('TESTKEY', 'TESTVALUE', comment=test_comment)
    assert ad.header.cards['TESTKEY'].comment.endswith(test_comment)
Exemplo n.º 22
0
def test_method_get_key_val_1():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.get_key_value('EXTNAME'), str)
Exemplo n.º 23
0
def test_method_set_key_val_7():
    ad = AstroData(TESTFILE2)
    with pytest.raises(AstroDataError):
        assert ad.set_key_value('FOO', None)
Exemplo n.º 24
0
def test_method_get_key_val_3():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.get_key_value('CRVAL1'), float)
Exemplo n.º 25
0
def test_method_phu_get_key_val_1():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.phu_get_key_value('SIMPLE'), bool)
Exemplo n.º 26
0
def test_method_get_key_val_4():
    ad = AstroData(TESTFILE2)
    assert ad.get_key_value('DATATYP') is None
Exemplo n.º 27
0
def test_method_phu_get_key_val_2():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.phu_get_key_value('BITPIX'), int)
Exemplo n.º 28
0
def test_method_get_key_val_6():
    ad = AstroData(TESTFILE2)
    assert ad.get_key_value('FOO') is None
Exemplo n.º 29
0
def mktable_helper(tablename, auto=True, rawdir="./"):
    """
    Create or append to an observation summary table.
    This function is interactive and requires input from the users.

    :param tablename: Filename for the table.  If it exists it will
        be extended.
    :type tablename: str
    :param auto: If True, get some of the information directly from
        the FITS headers.  [Default: True]
    :type auto: boolean
    :param rawdir: Path to raw data.  Required for auto=True.
        [Default: "./"]
    :type rawdir: str
    """
    from klpyastro.utils import obstable
    import os.path
    # TODO: change to new astrodata when ready
    if auto:
        from astrodata import AstroData

    # Create an ObsTable.  If the file already exists on disk,
    # then read it.  Otherwise, leave it empty.
    # Error handling: If the file exists but there's an read error,
    # raise, otherwise assume that you are creating a new file.
    table = obstable.ObsTable()
    table.filename = tablename
    try:
        table.read_table()
    except IOError:
        if os.path.exists(tablename):
            print("Error reading table %s\n" % tablename)
            raise
        else:
            print("New table will be created.")

    # Start the prompting the user and the data for the information
    # that needs to go in the table.

    user_not_done = True
    while user_not_done:
        user_inputs = {}
        if auto:
            filename_not_known = True

        # Get list of prompts for user or data supplied information.
        req_input_list = get_req_input_list()

        # Loop through record elements
        for input_request in req_input_list:
            if not input_request['in_hdr'] or not auto:
                # if auto and this is a Science entry, get the targetname from
                # the header.  If not Science, then you need to prompt user.
                if auto and input_request['id'] == 'targetname' and \
                        'datatype' in user_inputs and \
                                user_inputs['datatype'] == 'Science':

                    input_value = query_header(ad, input_request['id'])
                else:
                    # prompt the user
                    try:
                        input = raw_input
                    except NameError:
                        pass
                    input_value = input(input_request['prompt'])

                user_inputs[input_request['id']] = input_value

                # Assume that the user has a brain.
                # Probe only the first file in 'filerange' since all the
                # files in 'filerange' should be similar.
                #
                # Once we know the name of the first MEF file, open it
                # and keep it open until we're done requesting inputs
                # (instead of opening and closing it every time).
                if auto and filename_not_known:
                    if 'rootname' in user_inputs and 'filerange' in user_inputs:
                        # parse filerange, build filename (with rawdir path)
                        filenumbers = parse_filerange(user_inputs['filerange'])
                        filename = "%sS%04d.fits" % \
                                   (user_inputs['rootname'], filenumbers[0])
                        filename = os.path.join(rawdir, filename)

                        # open ad
                        ad = AstroData(filename)
                        filename_not_known = False
            else:

                # get value from header
                input_value = query_header(ad, input_request['id'])
                user_inputs[input_request['id']] = input_value

        if auto:
            ad.close()

        # Create record
        new_record = create_record(user_inputs)

        # Append to table
        table.add_records_to_table(new_record)

        # Prompt user: add another entry?
        try:
            input = raw_input
        except NameError:
            pass
        answer = input('Add another entry (y/n): ')
        user_not_done = ((answer == 'y') or False)

    # All the info is now in the ObsTable.
    # Write the ObsTable to disk and close everything, we're done.
    table.write_table()
    table.pretty_table()

    return
Exemplo n.º 30
0
def test_method_ext_index_3():
    ad = AstroData(TESTFILE)
    assert ad.ext_index(('SCI', 3)) == 2