<commit_before>from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
from config import ul, lr
from read_headers import variable_names
from get_data import get_dataset


def draw_map(file, map=None, show=True, title=None):
    '''Use Matplotlib's basemap to generate a map of a given BIOCLIM data 
    file.

    You can supply a Basemap object (in any projection) as the optional 
    keyword argument "map." If none is provided, the default Miller 
    projection will be used.'''

    data = get_dataset(file)
    lats = np.linspace(ul[0], lr[0], data.RasterYSize, endpoint=False)
    lons = np.linspace(ul[1], lr[1], data.RasterXSize, endpoint=False)

    values = data.ReadAsArray()    
    values = np.ma.masked_where(values==-9999, values)

    plt.figure()
    if title is None: title = '%s: %s' % (file, variable_names[file])
    plt.title(title)
    if map is None: map = Basemap(projection='mill',lon_0=0)
    map.drawcoastlines(linewidth=1)
    map.drawcountries(linewidth=1)
    map.drawstates(linewidth=0.5)

    x, y = np.meshgrid(lons, lats)
    data = np.zeros(x.shape)
            
    map.pcolormesh(x, y, data=values, latlon=True, cmap=plt.cm.OrRd)
    cbar = plt.colorbar()
    
    if show: plt.show()<commit_msg>Adding optional log-transformation (and translation) of data when mapping.<commit_after>from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
from config import ul, lr
from read_headers import variable_names
from get_data import get_dataset


def draw_map(file, map=None, show=True, title=None, log=False):
    '''Use Matplotlib's basemap to generate a map of a given BIOCLIM data 
    file.
    
    You can supply a Basemap object (in any projection) as the optional 
    keyword argument "map." If none is provided, the default Miller 
    projection will be used.'''
    
    data = get_dataset(file)
    lats = np.linspace(ul[0], lr[0], data.RasterYSize, endpoint=False)
    lons = np.linspace(ul[1], lr[1], data.RasterXSize, endpoint=False)
    
    # because missing data is entered as -9999, created a masked array so that 
    # these points will not be plotted
    values = data.ReadAsArray()
    values = np.ma.masked_where(values==-9999, values)
    
    # log transform data, if requested
    if log:
        if (values < 0).any():
            values -= min(values)
        values = np.log1p(values)
    
    plt.figure()
    if title is None: title = '%s: %s' % (file, variable_names[file])
    plt.title(title)
    if map is None:
        map = Basemap(projection='mill',lon_0=0)
        map.drawcoastlines(linewidth=1)
        map.drawcountries(linewidth=1)
        map.drawstates(linewidth=0.5)
    
    x, y = np.meshgrid(lons, lats)
    data = np.zeros(x.shape)
            
    map.pcolormesh(x, y, data=values, latlon=True, cmap=plt.cm.OrRd)
    cbar = plt.colorbar()
    
    if show: plt.show()
{'fraction_non_alphanumeric': 0.10792349726775956, 'fraction_numerical': 0.011612021857923498, 'mean_word_length': 3.190271816881259, 'pattern_counts': {'":': 0, '<': 4, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1304102', 'n_tokens_mistral': 1015, 'n_tokens_neox': 995, 'n_words': 285}