<commit_before>#!/usr/bin/env python
# encoding: utf-8
#
# test_map.py
#
# Created by <NAME> on 2 Jul 2017.

import numpy as np
import astropy
import matplotlib
import pytest

from marvin.tools.maps import Maps
from marvin.tools.map import Map


def _get_maps_kwargs(galaxy, data_origin):

    if data_origin == 'file':
        maps_kwargs = dict(filename=galaxy.mapspath)
    else:
        maps_kwargs = dict(plateifu=galaxy.plateifu, release=galaxy.release,
                           bintype=galaxy.bintype, template_kin=galaxy.template,
                           mode='local' if data_origin == 'db' else 'remote')

    return maps_kwargs


@pytest.fixture(scope='function', params=[('emline_gflux', 'ha_6564'),
                                          ('emline_gvel', 'oiii_5008'),
                                          ('stellar_vel', None),
                                          ('stellar_sigma', None)])
def map_(request, galaxy, data_origin):

    # TODO Remove
    files_to_download = ['manga-7443-12701-MAPS-SPX-GAU-MILESHC.fits.gz',
                         'manga-7443-12701-MAPS-ALL-GAU-MILESHC.fits.gz',
                         'manga-7443-12701-MAPS-NRE-GAU-MILESHC.fits.gz',
                         'manga-7443-12701-MAPS-VOR10-GAU-MILESHC.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-NONE-003.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-NONE-013.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-NONE-023.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-NONE-023.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-RADIAL-007.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-RADIAL-007.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-RADIAL-017.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-RADIAL-017.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-RADIAL-027.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-RADIAL-027.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-STON-001.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-STON-001.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-STON-011.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-STON-011.fits.gz',
                         'manga-7443-12701-LOGCUBE_MAPS-STON-021.fits.gz',
                         'manga-8485-1901-LOGCUBE_MAPS-STON-021.fits.gz']
    if galaxy.mapspath.split('/')[-1] in files_to_download:
        pytest.skip('Remove this skip once I download the files.')

    maps = Maps(**_get_maps_kwargs(galaxy, data_origin))
    map_ = maps.getMap(property_name=request.param[0], channel=request.param[1])
    return map_


class TestMap(object):

    def test_map(self, map_, galaxy):

        assert map_.release == galaxy.release

        assert tuple(map_.shape) == tuple(galaxy.shape)
        assert map_.value.shape == tuple(galaxy.shape)
        assert map_.ivar.shape == tuple(galaxy.shape)
        assert map_.mask.shape == tuple(galaxy.shape)

        assert (map_.masked.data == map_.value).all()
        assert (map_.masked.mask == map_.mask.astype(bool)).all()

        assert pytest.approx(map_.snr, np.abs(map_.value * np.sqrt(map_.ivar)))

        assert map_.header['BUNIT'] == map_.unit

        assert isinstance(map_.header, astropy.io.fits.header.Header)

    def test_plot(self, map_):

        fig, ax = map_.plot()
        assert isinstance(fig, matplotlib.figure.Figure)
        assert isinstance(ax, matplotlib.axes._subplots.Subplot)

    def test_save_and_restore(self, temp_scratch, map_):

        fout = temp_scratch.join('test_map.mpf')
        map_.save(str(fout))
        assert fout.check() is True

        map_restored = Map.restore(str(fout), delete=False)
        assert tuple(map_.shape) == tuple(map_restored.shape)
<commit_msg>removes skips of non-local files for test_map.py<commit_after>#!/usr/bin/env python
# encoding: utf-8
#
# test_map.py
#
# Created by <NAME> on 2 Jul 2017.

import numpy as np
import astropy
import matplotlib
import pytest

from marvin.tools.maps import Maps
from marvin.tools.map import Map
from marvin.tests import marvin_test_if


def _get_maps_kwargs(galaxy, data_origin):

    if data_origin == 'file':
        maps_kwargs = dict(filename=galaxy.mapspath)
    else:
        maps_kwargs = dict(plateifu=galaxy.plateifu, release=galaxy.release,
                           bintype=galaxy.bintype, template_kin=galaxy.template,
                           mode='local' if data_origin == 'db' else 'remote')

    return maps_kwargs


@pytest.fixture(scope='function', params=[('emline_gflux', 'ha_6564'),
                                          ('emline_gvel', 'oiii_5008'),
                                          ('stellar_vel', None),
                                          ('stellar_sigma', None)])
def map_(request, galaxy, data_origin):

    maps = Maps(**_get_maps_kwargs(galaxy, data_origin))
    map_ = maps.getMap(property_name=request.param[0], channel=request.param[1])
    return map_


class TestMap(object):

    def test_map(self, map_, galaxy):
        assert map_.release == galaxy.release

        assert tuple(map_.shape) == tuple(galaxy.shape)
        assert map_.value.shape == tuple(galaxy.shape)
        assert map_.ivar.shape == tuple(galaxy.shape)
        assert map_.mask.shape == tuple(galaxy.shape)

        assert (map_.masked.data == map_.value).all()
        assert (map_.masked.mask == map_.mask.astype(bool)).all()

        assert pytest.approx(map_.snr, np.abs(map_.value * np.sqrt(map_.ivar)))

        assert map_.header['BUNIT'] == map_.unit

        assert isinstance(map_.header, astropy.io.fits.header.Header)

    def test_plot(self, map_):
        fig, ax = map_.plot()
        assert isinstance(fig, matplotlib.figure.Figure)
        assert isinstance(ax, matplotlib.axes._subplots.Subplot)

    @marvin_test_if(mark='skip', data_origin=['db'])
    def test_save_and_restore(self, temp_scratch, map_, data_origin):
        
        print(f'\n\n{data_origin}\n\n')

        fout = temp_scratch.join('test_map.mpf')
        map_.save(str(fout))
        assert fout.check() is True

        map_restored = Map.restore(str(fout), delete=True)
        assert tuple(map_.shape) == tuple(map_restored.shape)

{'fraction_non_alphanumeric': 0.12606098711097138, 'fraction_numerical': 0.040238918579063185, 'mean_word_length': 2.210393541876892, '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': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3383241', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2084, 'n_words': 327}