Example #1
0
def cmap_builder(name, name2=None, name3=None):
    """return a colormap object compatible with matplotlib

    If only parameter **name** is provided, it should be a known matplotlib 
    colormap name (e.g., jet). If **name2** is provided, then a new colormap 
    is created going from the color **name** to the color **name2** with a
    linear scale. Finally, if **name3** is provided, a linear scaled colormap
    is built from color **name** to color **name3** with the intermediate color
    being the **name2**

    Matplotlib colormap map names


    """
    c = Colormap()
    # an R colormap
    if name and name2 and name3:
        return c.cmap_linear(name, name2, name3)
    elif name and name2:
        return c.cmap_bicolor(name, name2)
    elif name == 'heat':
        return c.get_cmap_heat()
    elif name == 'heat_r':
        return c.get_cmap_heat_r()
    # matplotlic colormaps
    elif name in c.colormaps:
        return c.cmap(name)
    # some custom diverging colormaps with black in the middle.
    elif name in c.diverging_black:
        return c.cmap(name)
    else:
        #valid = c.colormaps + c.diverging_black
        txt = "name provided {0} is not recognised. ".format(name)
        txt += "\n valid name can be found in colormap.colormap_names"
        raise ValueError(txt)
Example #2
0
    def get_html(self):

        # We have 3 colors but sometimes you may have only one or 2.
        # This may be an issue with canvasXpress. It seems essential
        # to sort the color column so that names are sorted alphabetically
        # and to include colors that are present in the sale order
        """try:
            self.data.sort_values(by='color', inplace=True)
        except:
            self.data.sort("color", inplace=True)
        """
        # Jinja related
        from easydev import get_package_location
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
            get_package_location("gdsctools") + "/gdsctools/data/templates/")
        template = env.get_template("scatter.html")

        # We need to cireate 20 different colors
        from colormap import Colormap
        c = Colormap()
        cmap = c.cmap_linear("red", "blue", "yellow", N=20)

        colors = self.data[self._colname_color]
        colors = ["red" for x in self.data[self._colname_color]]

        jinja = {}
        jinja["colors"] = ["rgba(205,0,0,0.5)"]
        jinja["Group"] = colors
        jinja['xlabel'] = '"%s"' % self.xlabel
        jinja['ylabel'] = '"%s"' % self.ylabel

        selection = [self._colname_x, self._colname_y]

        text = []
        for index in zip(self.data.index):
            text.append("<pre>%s</pre>" %
                        self.data.ix[index][selection].to_string())
        jinja['vars'] = text

        #self.data.markersize /= (self.data.markersize.max()/3.)
        self.data['markersize'] = 20
        selection = [self._colname_x, self._colname_y, self._colname_size]
        #First value is Y, second is X, following will be used in the
        try:  # introduced in pandas > 0.16.2
            jinja['data'] = self.data[selection].round(3).values.tolist()
        except:  #for py3.3 on travis
            jinja['data'] = np.around(self.data[selection]).values.tolist()

        jinja[
            'title'] = '"Regression coefficient vs Bayes factor for all drugs"'

        jinja['minX'] = self.minX
        jinja['minY'] = self.minY
        jinja['maxX'] = self.maxX
        jinja['maxY'] = self.maxY

        self.html = template.render(jinja)
        return self.html
Example #3
0
    def get_html(self):

        # We have 3 colors but sometimes you may have only one or 2.
        # This may be an issue with canvasXpress. It seems essential
        # to sort the color column so that names are sorted alphabetically
        # and to include colors that are present in the sale order
        """try:
            self.data.sort_values(by='color', inplace=True)
        except:
            self.data.sort("color", inplace=True)
        """
        # Jinja related
        from easydev import get_package_location
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
                        get_package_location("gdsctools")
                        + "/gdsctools/data/templates/")
        template = env.get_template("scatter.html")

        # We need to cireate 20 different colors
        from colormap import Colormap
        c = Colormap()
        cmap = c.cmap_linear("red", "blue", "yellow", N=20)

        colors = self.data[self._colname_color]
        colors = ["red" for x in self.data[self._colname_color]]

        jinja = {}
        jinja["colors"] = ["rgba(205,0,0,0.5)"]
        jinja["Group"] = colors
        jinja['xlabel'] = '"%s"' % self.xlabel
        jinja['ylabel'] = '"%s"' % self.ylabel

        text = []
        for index in zip(self.data.index):
            text.append("<pre>%s</pre>" % self.data.ix[index].to_string())
        jinja['vars'] = text

        #self.data.markersize /= (self.data.markersize.max()/3.)
        self.data['markersize'] = 20
        selection = [self._colname_x, self._colname_y, self._colname_size]
        #First value is Y, second is X, following will be used in the
        try: # introduced in pandas > 0.16.2
            jinja['data'] = self.data[selection].round(3).values.tolist()
        except: #for py3.3 on travis
            jinja['data'] = np.around(self.data[selection]).values.tolist()

        jinja['title'] = '"Regression coefficient/ttest/bayes factor for all drugs"' 

        jinja['minX'] = 0
        jinja['minY'] = 0
        jinja['maxX'] = 1
        jinja['maxY'] = self.data[self._colname_y].max() * 1.1

        self.html = template.render(jinja)
        return self.html
Example #4
0
def cmap_builder(name, name2=None, name3=None):
    """return a colormap object compatible with matplotlib

    If only parameter **name** is provided, it should be a known matplotlib 
    colormap name (e.g., jet). If **name2** is provided, then a new colormap 
    is created going from the color **name** to the color **name2** with a
    linear scale. Finally, if **name3** is provided, a linear scaled colormap
    is built from color **name** to color **name3** with the intermediate color
    being the **name2**

    Matplotlib colormap map names

    """
    c = Colormap()
    # an R colormap
    if name and name2 and name3:
        return c.cmap_linear(name, name2, name3)
    elif name and name2:
        return c.cmap_bicolor(name, name2)
    elif name == 'heat':
        return c.get_cmap_heat()
    elif name == 'heat_r':
        return c.get_cmap_heat_r()
    # matplotlic colormaps
    elif name in c.colormaps:
        return c.cmap(name)
    # some custom diverging colormaps with black in the middle.
    elif name in c.diverging_black:
        return c.cmap(name)
    elif name.count("_") == 2:
        name1, name2, name3 = name.split("_")
        return c.cmap_linear(name1, name2, name3)
    else:
        #valid = c.colormaps + c.diverging_black
        txt = "name provided {0} is not recognised. ".format(name)
        txt += "\n valid name can be found in colormap.colormap_names"
        raise ValueError(txt)
Example #5
0
imnum = 1
vidnum = 1
exposure = float(10000.0)  # value in microseconds
avg = 0
t0 = time.time()
t, avg1, avg2, avg3, oldt, oldavg1, oldavg2, oldavg3, oldert, olderavg1, olderavg2, olderavg3 = [], [], [], [], [], [], [], [], [], [], [], []
x1, y1, x2, y2 = 0, 0, 640, 480
a1, b1, a2, b2 = 0, 0, 640, 480
c1, d1, c2, d2 = 0, 0, 640, 480
i = 1
red, green, blue = True, False, False
path = 'C:/Users/Palmstrom Lab/Desktop/FRHEED/'
filename = 'default'
#### Define colormap ####
cmp = Colormap()
FRHEEDcmap = cmp.cmap_linear('black', 'green', 'white')
cm.register_cmap(name='RHEEDgreen', cmap=FRHEEDcmap)
cmap = cm.gray
#cmp.test_colormap(FRHEEDcmap)
#### Loading UI file from qt designer ####
form_class = uic.loadUiType("FRHEED backup.ui")[0]
#### Define "shortcut" for queue ####
q = queue.Queue()
#### Define video recording codec ####
fourcc = cv2.VideoWriter_fourcc(*'MP4V')
#### Set default appearance of plots ####
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 0.0)
#### Connect to RHEED camera ####
system = PySpin.System.GetInstance()
cam_list = system.GetCameras()
Example #6
0
def make_u_plot(u_fname,
                make_single,
                make_with_metric,
                label_p,
                u_zonal=None,
                u_zonal_NH=None,
                Method=None,
                Method_NH=None,
                lat_elem_SH=None,
                lat_elem_NH=None,
                STJ_lat=None,
                method_choice=None,
                time=None,
                file_out_syntax=None):

    open_data = False
    if open_data:
        #open jet data from file
        filename = '{0}/STJ_data_{1}.nc'.format(data_out_dir, file_out_syntax)
        assert os.path.isfile(
            filename
        ), 'File ' + filename + ' does not exist. Need jet latitude for plotting.'
        var_jet = openNetCDF4_get_data(filename)
        jet_NH = var_jet['STJ_lat'][:, 0]
        jet_SH = var_jet['STJ_lat'][:, 1]
    else:
        #use data just calculated
        jet_NH = STJ_lat[0]
        jet_SH = STJ_lat[1]

    #open u wind data - on pressure levels
    assert os.path.isfile(u_fname), 'File ' + u_fname + ' does not exist.'
    var = openNetCDF4_get_data(u_fname)

    # check that input pressure is in pascal
    if var[label_p].max() < 90000.0:
        var[label_p] = var[label_p] * 100.0

    lev250 = FindClosestElem(25000, var[label_p], 0)[0]

    if 'var131' in var:
        uwnd = var['var131'][time, lev250, :, :]
    else:
        uwnd = var['u'][time, lev250, :, :]

    if make_single:
        fname_out = '{}/uwind_{}_with_wind_{}.eps'.format(
            plot_dir, t_elem[t], file_out_syntax)

        fig = plt.figure(figsize=(10, 5))

        # wind plot
        ax1 = plt.subplot2grid((10, 20), (0, 0), colspan=16, rowspan=9)
        # zonal mean
        ax2 = plt.subplot2grid((10, 20), (0, 16), colspan=5, rowspan=9)
        # colour bar
        ax_cb = plt.subplot2grid((10, 20), (9, 0), colspan=20)

        save_plot = True
        plot_u(plt,
               ax1,
               ax2,
               ax_cb,
               jet_NH,
               jet_SH,
               uwnd,
               var,
               t,
               t_elem,
               fname_out,
               save_plot,
               make_single=make_single)

    if make_with_metric:

        fname_out = '{}/validation_uwind_{}_{}.eps'.format(
            plot_dir, time, file_out_syntax)

        fig = plt.figure(figsize=(10, 12))
        #SH
        ax1 = plt.subplot2grid(
            (37, 26), (0, 0), rowspan=22,
            colspan=12)  #half across/gap/half accross. 18 deep
        #NH
        ax2 = plt.subplot2grid((37, 26), (0, 12), rowspan=22, colspan=12)
        # wind plot
        ax3 = plt.subplot2grid((37, 26), (22, 0), rowspan=13, colspan=20)
        # zonal mean
        ax4 = plt.subplot2grid((37, 26), (22, 20), rowspan=13, colspan=5)
        # colour bar
        ax_cb = plt.subplot2grid((37, 26), (35, 0), rowspan=2, colspan=37)

        bounds = np.arange(-50, 60, 5.0)
        cm = Colormap()
        cmap = cm.cmap_linear('#0033ff', '#FFFFFF', '#990000')  #blue/red
        #cmap = pylab.cm.get_cmap('RdBu_r')

        PlottingObject = Plotting(Method, 'cby')
        plot_cbar = False

        #u_zonal = MeanOverDim(data=uwnd, dim=1)

        PlottingObject.poly_2PV_line('SH',
                                     u_zonal,
                                     lat_elem_SH,
                                     time,
                                     fig,
                                     ax1,
                                     plot_cbar,
                                     ax_cb,
                                     bounds,
                                     cmap,
                                     plot_type='subplot_all',
                                     pause=False,
                                     click=False,
                                     save_plot=False)
        # NH
        PlottingObject2 = Plotting(Method_NH, method_choice)
        PlottingObject2.poly_2PV_line('NH',
                                      u_zonal_NH,
                                      lat_elem_NH,
                                      time,
                                      fig,
                                      ax2,
                                      plot_cbar,
                                      None,
                                      bounds,
                                      cmap,
                                      plot_type='subplot_all',
                                      pause=False,
                                      click=False,
                                      save_plot=False)

        save_plot = True
        plot_u(plt,
               ax3,
               ax4,
               ax_cb,
               jet_NH,
               jet_SH,
               uwnd,
               var,
               bounds,
               cmap,
               time,
               fname_out,
               save_plot,
               make_single=False)