<commit_before>#!/usr/bin/env python
from pyvc import *
from pyvc import vcutils
from pyvc import vcexceptions
import matplotlib.pyplot as mplt
import matplotlib.font_manager as mfont
import matplotlib.colors as mcolor
import matplotlib.colorbar as mcolorbar
import matplotlib.lines as mlines
import matplotlib.patches as mpatches
import numpy as np
import math
import multiprocessing
import Queue
import cPickle
import networkx as nx
from operator import itemgetter
from mpl_toolkits.basemap import Basemap, maskoceans, interp
import quakelib
import time
from PIL import Image

class DisplacementGridProcessor(multiprocessing.Process):
    def __init__(self, work_queue, result_queue, field_1d, event_element_data, event_element_slips, lat_size, lon_size, cutoff, event_center, event_radius):#, min_lat, min_lon, max_lat, max_lon):
        
        # base class initialization
        multiprocessing.Process.__init__(self)
 
        # job management stuff
        self.work_queue = work_queue
        self.result_queue = result_queue
        self.kill_received = False
        
        self.field_1d = field_1d
        self.event_element_data = event_element_data
        self.event_element_slips = event_element_slips
        self.lat_size = lat_size
        self.lon_size = lon_size
        self.cutoff = cutoff
        self.event_center = event_center
        self.event_radius = event_radius
    
        #self.counter = counter
        #self.total_tasks = total_tasks
    
    def run(self):
        while not self.kill_received:
            # get a task
            try:
                start, end = self.work_queue.get_nowait()
            except Queue.Empty:
                break
            
            print 'processing elements {} - {}'.format(start, end)
            
            # empty arrays to store the results
            dX = np.empty((self.lat_size, self.lon_size))
            dY = np.empty((self.lat_size, self.lon_size))
            dZ = np.empty((self.lat_size, self.lon_size))
            
            # create a element list
            elements = quakelib.EventElementList()
            
            # create elements and add them to the element list
            for element in self.event_element_data[start:end]:
                #print element
                ele = quakelib.EventElement4()
                ele.set_rake(element['rake_rad'])
                ele.set_slip(self.event_element_slips[element['block_id']])
                ele.set_vert(0, element['m_x_pt1'], element['m_y_pt1'], element['m_z_pt1'])
                ele.set_vert(1, element['m_x_pt2'], element['m_y_pt2'], element['m_z_pt2'])
                ele.set_vert(2, element['m_x_pt3'], element['m_y_pt3'], element['m_z_pt3'])
                ele.set_vert(3, element['m_x_pt4'], element['m_y_pt4'], element['m_z_pt4'])
                elements.append(ele)
            
            # create an event
            event = quakelib.Event()
            
            # add the elements to the event
            event.add_elements(elements)
            
            # set the event center and radius
            event.set_event_center(self.event_center)
            event.set_event_radius(self.event_radius)
            
            #calculate the displacements
            lame_lambda = 3.2e10
            lame_mu = 3.0e10
            
            if self.cutoff is None:
                disp_1d = event.event_displacements(self.field_1d, lame_lambda, lame_lambda)
            else:
                disp_1d = event.event_displacements(self.field_1d, lame_lambda, lame_lambda, self.cutoff)
            disp = np.array(disp_1d).reshape((self.lat_size,self.lon_size))
        
            it = np.nditer(dX, flags=['multi_index'])
            while not it.finished:
                dX[it.multi_index] = disp[it.multi_index][0]
                dY[it.multi_index] = disp[it.multi_index][1]
                dZ[it.multi_index] = disp[it.multi_index][2]
                it.iternext()
            
            # store the result
            processed_displacements = {}
            processed_displacements['dX'] = dX
            processed_displacements['dY'] = dY
            processed_displacements['dZ'] = dZ
            self.result_queue.put(processed_displacements)

#-------------------------------------------------------------------------------
# A class to handle the plotting of event displacements
#-------------------------------------------------------------------------------
class VCDisplacementMapPlotter:
    #---------------------------------------------------------------------------
    # If outut_file is none returns an instance for further plotting
    #---------------------------------------------------------------------------
    def __init__(self, min_lat, max_lat, min_lon, max_lon, base_lat, base_lon, fault_traces, padding=0.01, map_res='i', map_proj='cyl'):
        self.look_azimuth = None
        self.look_elevation = None
        self.wavelength = 0.03
        
        # Define how the cutoff value scales if it is not explitly set
        self.cutoff_min_size = 20.0
        self.cutoff_min = 46.5
        self.cutoff_p2_size = 65.0
        self.cutoff_p2 = 80.0
        #self.output_file = None
        #self.min_lon = min_lon
        #self.max_lon = max_lon<commit_msg>Displacement map tweaks<commit_after>#!/usr/bin/env python
from pyvc import *
from pyvc import vcutils
from pyvc import vcexceptions
import matplotlib.pyplot as mplt
import matplotlib.font_manager as mfont
import matplotlib.colors as mcolor
import matplotlib.colorbar as mcolorbar
import matplotlib.lines as mlines
import matplotlib.patches as mpatches
import numpy as np
import math
import multiprocessing
import Queue
import cPickle
import networkx as nx
from operator import itemgetter
from mpl_toolkits.basemap import Basemap, maskoceans, interp
import quakelib
import time
from PIL import Image

class DisplacementGridProcessor(multiprocessing.Process):
    def __init__(self, work_queue, result_queue, field_1d, event_element_data, event_element_slips, lat_size, lon_size, cutoff, event_center, event_radius):#, min_lat, min_lon, max_lat, max_lon):
        
        # base class initialization
        multiprocessing.Process.__init__(self)
 
        # job management stuff
        self.work_queue = work_queue
        self.result_queue = result_queue
        self.kill_received = False
        
        self.field_1d = field_1d
        self.event_element_data = event_element_data
        self.event_element_slips = event_element_slips
        self.lat_size = lat_size
        self.lon_size = lon_size
        self.cutoff = cutoff
        self.event_center = event_center
        self.event_radius = event_radius
    
        #self.counter = counter
        #self.total_tasks = total_tasks
    
    def run(self):
        while not self.kill_received:
            # get a task
            try:
                start, end = self.work_queue.get_nowait()
            except Queue.Empty:
                break
            
            print 'processing elements {} - {}'.format(start, end)
            
            # empty arrays to store the results
            dX = np.empty((self.lat_size, self.lon_size))
            dY = np.empty((self.lat_size, self.lon_size))
            dZ = np.empty((self.lat_size, self.lon_size))
            
            # create a element list
            elements = quakelib.EventElementList()
            
            # create elements and add them to the element list
            for element in self.event_element_data[start:end]:
                #print element
                ele = quakelib.EventElement4()
                ele.set_rake(element['rake_rad'])
                ele.set_slip(self.event_element_slips[element['block_id']])
                ele.set_vert(0, element['m_x_pt1'], element['m_y_pt1'], element['m_z_pt1'])
                ele.set_vert(1, element['m_x_pt2'], element['m_y_pt2'], element['m_z_pt2'])
                ele.set_vert(2, element['m_x_pt3'], element['m_y_pt3'], element['m_z_pt3'])
                ele.set_vert(3, element['m_x_pt4'], element['m_y_pt4'], element['m_z_pt4'])
                elements.append(ele)
            
            # create an event
            event = quakelib.Event()
            
            # add the elements to the event
            event.add_elements(elements)
            
            # set the event center and radius
            event.set_event_center(self.event_center)
            event.set_event_radius(self.event_radius)
            
            #calculate the displacements
            lame_lambda = 3.2e10
            lame_mu = 3.0e10
            
            if self.cutoff is None:
                disp_1d = event.event_displacements(self.field_1d, lame_lambda, lame_lambda)
            else:
                disp_1d = event.event_displacements(self.field_1d, lame_lambda, lame_lambda, self.cutoff)
            disp = np.array(disp_1d).reshape((self.lat_size,self.lon_size))
        
            it = np.nditer(dX, flags=['multi_index'])
            while not it.finished:
                dX[it.multi_index] = disp[it.multi_index][0]
                dY[it.multi_index] = disp[it.multi_index][1]
                dZ[it.multi_index] = disp[it.multi_index][2]
                it.iternext()
            
            # store the result
            processed_displacements = {}
            processed_displacements['dX'] = dX
            processed_displacements['dY'] = dY
            processed_displacements['dZ'] = dZ
            self.result_queue.put(processed_displacements)

#-------------------------------------------------------------------------------
# A class to handle the plotting of event displacements
#-------------------------------------------------------------------------------
class VCDisplacementMapPlotter:
    #---------------------------------------------------------------------------
    # If outut_file is none returns an instance for further plotting
    #---------------------------------------------------------------------------
    def __init__(self, min_lat, max_lat, min_lon, max_lon, base_lat, base_lon, fault_traces, padding=0.01, map_res='i', map_proj='cyl'):
        self.look_azimuth = None
        self.look_elevation = None
        self.wavelength = 0.03
        
        # Define how the cutoff value scales if it is not explitly set
        self.cutoff_min_size = 20.0
        self.cutoff_min = 46.5
        self.cutoff_p2_size = 65.0
        self.cutoff_p2 = 90.0
        #self.output_file = None
        #self.min_lon = min_lon
        #self.max_lon = max_lon
{'fraction_non_alphanumeric': 0.13632930513595165, 'fraction_numerical': 0.010574018126888218, 'mean_word_length': 1.792776166622726, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6109659', 'n_tokens_mistral': 3135, 'n_tokens_neox': 3016, 'n_words': 663}