<commit_before># ancestry-german

from ..image_provider import ImageProvider
from . import get_data
from ...utils.download.abs import abs_data_to_dataframe

from matplotlib.cm import get_cmap
import matplotlib as mpl
import cartopy.crs as ccrs

FILENAME = 'german.json'


class GermanAncestryImageProvider(ImageProvider):
    def has_required_data(self):
        return self.data_dir_exists(FILENAME)

    def obtain_data(self):
        return self.save_json(FILENAME, get_data('German'))

    def build_image(self):
        data = abs_data_to_dataframe(self.load_json(FILENAME))
        data = data[data.pop('Time') == 2011]
        del data['ANCP']
        del data['FREQUENCY']
        del data['REGIONTYPE']

        lga_lookup = lambda code: self.services.lga.get('LGA_CODE11', code)

        aus_map = self.services.aus_map.get_map()
        colors = get_cmap('Purples')
        norm = mpl.colors.Normalize(
            vmin=data.Value.min(),
            vmax=data.Value.max()
        )

        for idx, loco in data.iterrows():
            aus_map.add_geometries(
                [
                    shape.geometry
                    for shape in lga_lookup(loco.REGION).rec
                    if shape.geometry
                ],
                crs=ccrs.PlateCarree(),
                color=colors(norm(loco.Value))
            )

        return aus_map
<commit_msg>Have filename be a class field<commit_after># ancestry-german

from ..image_provider import ImageProvider
from . import get_data
from ...utils.download.abs import abs_data_to_dataframe

from matplotlib.cm import get_cmap
import matplotlib as mpl
import cartopy.crs as ccrs


class GermanAncestryImageProvider(ImageProvider):
    filename = 'german.json'

    def has_required_data(self):
        return self.data_dir_exists(self.filename)

    def obtain_data(self):
        return self.save_json(self.filename, get_data('German'))

    def build_image(self):
        data = abs_data_to_dataframe(self.load_json(self.filename))
        data = data[data.pop('Time') == 2011]
        del data['ANCP']
        del data['FREQUENCY']
        del data['REGIONTYPE']

        lga_lookup = lambda code: self.services.lga.get('LGA_CODE11', code)

        aus_map = self.services.aus_map.get_map()
        colors = get_cmap('Purples')
        norm = mpl.colors.Normalize(
            vmin=data.Value.min(),
            vmax=data.Value.max()
        )

        for idx, loco in data.iterrows():
            aus_map.add_geometries(
                [
                    shape.geometry
                    for shape in lga_lookup(loco.REGION).rec
                    if shape.geometry
                ],
                crs=ccrs.PlateCarree(),
                color=colors(norm(loco.Value))
            )

        return aus_map

{'fraction_non_alphanumeric': 0.09763948497854077, 'fraction_numerical': 0.004291845493562232, 'mean_word_length': 2.153325817361894, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3808780', 'n_tokens_mistral': 891, 'n_tokens_neox': 841, 'n_words': 167}