示例#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)
示例#2
0
def test_constructor_2():
    """ filename w mode option """
    ad = AstroData(dataset=TESTFILE, mode="update")
    assert ad.mode == 'update'
示例#3
0
def test_method_phu_get_key_val_3():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.phu_get_key_value('RA'), float)
示例#4
0
def test_method_set_key_val_6():
    ad = AstroData(TESTFILE2)
    with pytest.raises(TypeError):
        assert ad.set_key_value('FOO')
示例#5
0
def test_method_set_key_val_8():
    ad = AstroData(TESTFILE)
    with pytest.raises(AstroDataError):
        assert ad.set_key_value('BITPIX', 1)
示例#6
0
def test_method_set_key_val_1():
    ad = AstroData(TESTFILE2)
    ad.set_key_value('TESTKEY', 'TESTVALUE')
    assert ad.header['TESTKEY']
示例#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)
示例#8
0
def test_method_extname_2():
    ad = AstroData(TESTFILE2)
    assert ad.extname() == 'SCI'
示例#9
0
def test_method_extver_1():
    ad = AstroData(TESTFILE2)  # Single 'SCI' ext
    assert isinstance(ad.extver(), int)
示例#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)
示例#11
0
def test_method_extname_1():
    ad = AstroData(TESTFILE2)  # Single 'SCI' ext
    assert isinstance(ad.extname(), str)
示例#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
示例#13
0
def test_method_rename_ext_3():
    ad = AstroData(TESTFILE2)  # Single 'SCI' ext
    ad.rename_ext("FOO")
    assert ad.extname() == "FOO"
示例#14
0
def test_method_rename_ext_2():
    ad = AstroData(TESTFILE)
    with pytest.raises(SingleHDUMemberExcept):
        ad.rename_ext("FOO")
示例#15
0
def test_method_get_key_val_7():
    ad = AstroData(TESTFILE2)
    with pytest.raises(TypeError):
        assert ad.get_key_value()
示例#16
0
def test_method_extver_2():
    ad = AstroData(TESTFILE2)
    assert ad.extver() == 1
示例#17
0
def test_constructor_1():
    """ Good filename, def mode """
    ad = AstroData(dataset=TESTFILE)
    assert ad.mode == 'readonly'
示例#18
0
def test_method_extver_3():
    ad = AstroData(TESTFILE)
    with pytest.raises(SingleHDUMemberExcept):
        ad.extver()
示例#19
0
def test_method_set_key_val_2():
    ad = AstroData(TESTFILE2)
    ad.set_key_value('BITPIX', 999)
    assert isinstance(ad.header['BITPIX'], int)
示例#20
0
def test_constructor_0():
    """ Good filename """
    assert AstroData(dataset=TESTFILE)
示例#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)
示例#22
0
def test_method_get_key_val_1():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.get_key_value('EXTNAME'), str)
示例#23
0
def test_method_set_key_val_7():
    ad = AstroData(TESTFILE2)
    with pytest.raises(AstroDataError):
        assert ad.set_key_value('FOO', None)
示例#24
0
def test_method_get_key_val_3():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.get_key_value('CRVAL1'), float)
示例#25
0
def test_method_phu_get_key_val_1():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.phu_get_key_value('SIMPLE'), bool)
示例#26
0
def test_method_get_key_val_4():
    ad = AstroData(TESTFILE2)
    assert ad.get_key_value('DATATYP') is None
示例#27
0
def test_method_phu_get_key_val_2():
    ad = AstroData(TESTFILE2)
    assert isinstance(ad.phu_get_key_value('BITPIX'), int)
示例#28
0
def test_method_get_key_val_6():
    ad = AstroData(TESTFILE2)
    assert ad.get_key_value('FOO') is None
示例#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
示例#30
0
def test_method_ext_index_3():
    ad = AstroData(TESTFILE)
    assert ad.ext_index(('SCI', 3)) == 2