<commit_before>#!/usr/bin/env python
# encoding: utf-8
#
# test_modelcube.py
#
# Created by <NAME> on 25 Sep 2016.


from __future__ import division, print_function, absolute_import

import os

import pytest
from astropy.io import fits
from astropy.wcs import WCS

from marvin import config
from marvin.core.exceptions import MarvinError
from marvin.tools.cube import Cube
from marvin.tools.maps import Maps
from marvin.tools.modelcube import ModelCube
from marvin.tests import marvin_test_if


class TestModelCubeInit(object):

    def _test_init(self, model_cube, galaxy, bintype='SPX', template_kin='GAU-MILESHC'):
        assert model_cube._release == galaxy.release
        assert model_cube._drpver == galaxy.drpver
        assert model_cube._dapver == galaxy.dapver
        assert model_cube.bintype == bintype
        assert model_cube.template_kin == template_kin
        assert model_cube.plateifu == galaxy.plateifu
        assert model_cube.mangaid == galaxy.mangaid
        assert isinstance(model_cube.header, fits.Header)
        assert isinstance(model_cube.wcs, WCS)
        assert model_cube.wavelength is not None
        assert model_cube.redcorr is not None

    @pytest.mark.parametrize('data_origin', ['file', 'db', 'api'])
    def test_init_modelcube(self, galaxy, data_origin):
        if data_origin == 'file':
            kwargs = {'filename': galaxy.modelpath}
        elif data_origin == 'db':
            kwargs = {'plateifu': galaxy.plateifu}
        elif data_origin == 'api':
            kwargs = {'plateifu': galaxy.plateifu, 'mode': 'remote'}

        model_cube = ModelCube(**kwargs)
        assert model_cube.data_origin == data_origin
        self._test_init(model_cube, galaxy)

    # TODO remove set_tmp_mpl
    # def test_init_from_file_global_mpl4(self, galaxy):
    #     with set_tmp_mpl('MPL-4'):
    #         config.setMPL('MPL-4')
    #         model_cube = ModelCube(filename=galaxy.modelpath)
    #         assert model_cube.data_origin == 'file'
    #         self._test_init(model_cube, galaxy)

    # TODO remove set_tmp_mpl
    # def test_raises_exception_mpl4(self, galaxy):
    #     with set_tmp_mpl('MPL-4'):
    #         config.setMPL('MPL-4')
    #         with pytest.raises(MarvinError) as cm:
    #             ModelCube(plateifu=galaxy.plateifu)
    #         assert 'ModelCube requires at least dapver=\'2.0.2\'' in str(cm.value)

    @pytest.mark.parametrize('data_origin', ['file', 'db', 'api'])
    def test_init_modelcube_bintype(self, galaxy, data_origin):
        kwargs = {'bintype': galaxy.bintype}
        if data_origin == 'file':
            kwargs['filename'] = galaxy.modelpath
        elif data_origin == 'db':
            kwargs['plateifu'] = galaxy.plateifu
        elif data_origin == 'api':
            kwargs['plateifu'] = galaxy.plateifu
            kwargs['mode'] = 'remote'

        model_cube = ModelCube(**kwargs)
        assert model_cube.data_origin == data_origin
        self._test_init(model_cube, galaxy, bintype=galaxy.bintype)

class TestModelCube(object):<commit_msg>removes set_tmp_mpl references<commit_after>#!/usr/bin/env python
# encoding: utf-8
#
# test_modelcube.py
#
# Created by <NAME> on 25 Sep 2016.


from __future__ import division, print_function, absolute_import

import os

import pytest
from astropy.io import fits
from astropy.wcs import WCS

from marvin import config
from marvin.core.exceptions import MarvinError
from marvin.tools.cube import Cube
from marvin.tools.maps import Maps
from marvin.tools.modelcube import ModelCube
from marvin.tests import marvin_test_if


class TestModelCubeInit(object):

    def _test_init(self, model_cube, galaxy, bintype='SPX', template_kin='GAU-MILESHC'):
        assert model_cube._release == galaxy.release
        assert model_cube._drpver == galaxy.drpver
        assert model_cube._dapver == galaxy.dapver
        assert model_cube.bintype == bintype
        assert model_cube.template_kin == template_kin
        assert model_cube.plateifu == galaxy.plateifu
        assert model_cube.mangaid == galaxy.mangaid
        assert isinstance(model_cube.header, fits.Header)
        assert isinstance(model_cube.wcs, WCS)
        assert model_cube.wavelength is not None
        assert model_cube.redcorr is not None

    @marvin_test_if(mark='skip', galaxy=dict(release='MPL-4'))
    def test_init_modelcube(self, galaxy, data_origin):

        # TODO Remove
        files_to_download = ['manga-7443-12701-LOGCUBE-NRE-GAU-MILESHC.fits.gz',
                             'manga-7443-12701-LOGCUBE-ALL-GAU-MILESHC.fits.gz',
                             'manga-7443-12701-LOGCUBE-SPX-GAU-MILESHC.fits.gz',
                             'manga-7443-12701-LOGCUBE-VOR10-GAU-MILESHC.fits.gz']
        if galaxy.modelpath.split('/')[-1] in files_to_download:
            pytest.skip('Remove this skip once I download the files.')

        if data_origin == 'file':
            kwargs = {'filename': galaxy.modelpath}
        elif data_origin == 'db':
            kwargs = {'plateifu': galaxy.plateifu}
        elif data_origin == 'api':
            kwargs = {'plateifu': galaxy.plateifu, 'mode': 'remote'}

        model_cube = ModelCube(**kwargs)
        assert model_cube.data_origin == data_origin
        self._test_init(model_cube, galaxy)

    @marvin_test_if(mark='include', release='MPL-4')
    @marvin_test_if(mark='include', galaxy=dict(release=['MPL-5']))
    def test_init_from_file_global_mpl4(self, galaxy):

        # TODO Remove
        files_to_download = ['manga-7443-12701-LOGCUBE-NRE-GAU-MILESHC.fits.gz',
                             'manga-7443-12701-LOGCUBE-ALL-GAU-MILESHC.fits.gz',
                             'manga-7443-12701-LOGCUBE-SPX-GAU-MILESHC.fits.gz',
                             'manga-7443-12701-LOGCUBE-VOR10-GAU-MILESHC.fits.gz']
        if galaxy.modelpath.split('/')[-1] in files_to_download:
            pytest.skip('Remove this skip once I download the files.')

        model_cube = ModelCube(filename=galaxy.modelpath)
        assert model_cube.data_origin == 'file'
        self._test_init(model_cube, galaxy)

    @marvin_test_if(mark='include', galaxy=dict(release=['MPL-4']))
    def test_raises_exception_mpl4(self, galaxy):
        with pytest.raises(MarvinError) as cm:
            ModelCube(plateifu=galaxy.plateifu)
        assert 'ModelCube requires at least dapver=\'2.0.2\'' in str(cm.value)

    # TODO remove parametrization
    @pytest.mark.parametrize('data_origin', ['file', 'db', 'api'])
    def test_init_modelcube_bintype(self, galaxy, data_origin):
        kwargs = {'bintype': galaxy.bintype}
        if data_origin == 'file':
            kwargs['filename'] = galaxy.modelpath
        elif data_origin == 'db':
            kwargs['plateifu'] = galaxy.plateifu
        elif data_origin == 'api':
            kwargs['plateifu'] = galaxy.plateifu
            kwargs['mode'] = 'remote'

        model_cube = ModelCube(**kwargs)
        assert model_cube.data_origin == data_origin
        self._test_init(model_cube, galaxy, bintype=galaxy.bintype)

class TestModelCube(object):
{'fraction_non_alphanumeric': 0.1116751269035533, 'fraction_numerical': 0.01551043429216018, 'mean_word_length': 2.890839275918815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4813128', 'n_tokens_mistral': 2462, 'n_tokens_neox': 2311, 'n_words': 454}