def __init__(self, main_screen): # Get data data = d.get_markt_data() # Loop through the neighborhoods for wijk in data: # Get the current neighborhood a = wijk[0] # Enter a error handling block try: # Try the conversions result = wijk[2] / wijk[1] # Change a block on the map canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill=c.rgb_to_hex(result, (0, 0, 255), 760, True)) # When an error occurs, execute this code except (ZeroDivisionError): # Change a block on the map canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill=str_to_code(main_screen, str(a)).color) # Change a block on the map canvas.itemconfig(main_screen.Overschie.shape, fill=c.rgb_to_hex(1, (0, 0, 255), 1, False))
def __init__(self, main_screen): data = d.get_markt_data() for wijk in data: a = wijk[0] try: result = wijk[2]/wijk[1] canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill = c.rgb_to_hex(result, (0, 0, 255), 760, True)) except(ZeroDivisionError): canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill = str_to_code(main_screen, str(a)).color) canvas.itemconfig(main_screen.Overschie.shape, fill = c.rgb_to_hex(1, (0, 0, 255), 1, False))
def __init__(self, main_screen): for wijk in d.get_areas("metro"): a = wijk[0] info = d.get_metro_info(("'" + a + "'"))[0] if info[1] != None: result = info[1]/info[0] canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill = c.rgb_to_hex(result, (0, 255, 0), 2, False)) else: canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill = str_to_code(main_screen, str(a)).color)
def load_image(self,path): """Loads an image and puts pixel data into self.pixels.""" try: self.image = PIL.Image.open(path) if self.image.mode != "RGB": self.image = self.image.convert("RGB") except IOError: raise IOError, "IMAGE_NOT_LOADED" (self.width, self.height) = self.image.size rawpixels = self.image.getdata() self.pixels = [[Pixel(x,y,colors.rgb_to_hex(rawpixels[y*(self.width)+x])) for y in xrange(self.height)] for x in xrange(self.width)] self.current_pixel = self.pixels[0][0]
def __init__(self, main_screen, jaar, soort, cap): # Loop through the neighborhoods for wijk in d.get_areas("criminaliteit"): # Get the current neighborhood a = wijk[0] # Save the result result = d.get_crime_data(soort, jaar, ("'" + a + "'")) # Add the current information to the map canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill=c.rgb_to_hex(result, (255, 0, 0), cap, False))
def load_image(self,path): """Loads an image and puts pixel data into self.pixels""" try: self.image = PIL.Image.open(path) if self.image.mode != "RGB": self.image = self.image.convert("RGB") except IOError: raise IOError, "IMAGE_NOT_LOADED" (self.width, self.height) = self.image.size rawpixels = self.image.getdata() self.pixels = dict([((x,y),colors.rgb_to_hex(rawpixels[y*(self.width)+x])) for x in range(self.width) for y in range(self.height)]) #for x in range(self.width): # for y in range(self.height): # print "Pixel: (%s,%s) - %s" % (x,y,self.pixels[(x,y)]) self.current_pixel_coords = (0,0)
def load_image(self, path): """Loads an image and puts pixel data into self.pixels.""" try: self.image = PIL.Image.open(path) if self.image.mode != "RGB": self.image = self.image.convert("RGB") except IOError: raise IOError, "IMAGE_NOT_LOADED" (self.width, self.height) = self.image.size rawpixels = self.image.getdata() self.pixels = [[ Pixel(x, y, colors.rgb_to_hex(rawpixels[y * (self.width) + x])) for y in xrange(self.height) ] for x in xrange(self.width)] self.current_pixel = self.pixels[0][0]
def load_image(self, path): """Loads an image and puts pixel data into self.pixels""" try: self.image = PIL.Image.open(path) if self.image.mode != "RGB": self.image = self.image.convert("RGB") except IOError: raise IOError, "IMAGE_NOT_LOADED" (self.width, self.height) = self.image.size rawpixels = self.image.getdata() self.pixels = dict([ ((x, y), colors.rgb_to_hex(rawpixels[y * (self.width) + x])) for x in range(self.width) for y in range(self.height) ]) #for x in range(self.width): # for y in range(self.height): # print "Pixel: (%s,%s) - %s" % (x,y,self.pixels[(x,y)]) self.current_pixel_coords = (0, 0)
def __init__(self, main_screen): # Loop through the neighborhoods for data for wijk in d.get_areas("metro"): # Get the current neighborhood a = wijk[0] # Save the data info = d.get_metro_info(("'" + a + "'"))[0] # If the ammount of stations is not zero if info[1] != None: # Perform calculations result = info[1] / info[0] # Change an item on the map canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill=c.rgb_to_hex(result, (0, 255, 0), 2, False)) else: # Change an item on the map canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill=str_to_code(main_screen, str(a)).color)
def plot_range(self, outFile, title="Spectrum", printPeaks=True, printComponents=True, printPlanck=False): fig = plt.figure() ax = fig.add_subplot(111) #ax.plot(self.CalibratedWavelength[Mask], self.LaserRelMag[Mask] / np.max(self.LaserRelMag[Mask]), label = "Laser"); #ax.plot(self.CalibratedWavelength[Mask], self.SourceRelMag[Mask] / np.max(self.SourceRelMag[Mask]), label = "Source"); SourceMinusLaser = self.SourceRelMag / np.max( self.SourceRelMag) - self.LaserRelMag / np.max(self.LaserRelMag) MaskedSourceMinusLaser = SourceMinusLaser[self.LaserMask] ax.fill_between(self.CalibratedWavelength, 0, SourceMinusLaser / np.max(MaskedSourceMinusLaser), label="Source - Laser", zorder=0) ax.set_xlabel("Wavelength [nm]") ax.set_xlim([ np.min(self.CalibratedWavelength), np.max(self.CalibratedWavelength) ]) ax.set_ylim([0, 1.1]) ax.set_ylabel("Relative Intensity") #ax.set_yscale('log') ax.grid(b=True, which='minor') ax.grid(b=True, which='major') ax.minorticks_on() #Print PLANCK if (printPlanck): print "Plancking..." PeakWL = self.CalibratedWavelength[np.where( SourceMinusLaser == np.max(SourceMinusLaser))[0][0]] Temp = 2.8977 * 10**(6) / PeakWL ax.axvline(PeakWL, label="$\lambda_{max} \Rightarrow T=" + str(round(Temp, 0)) + "K$", c='red') RelIntsPlanck = self.planckspectrum(Temp) ax.plot(self.CalibratedWavelength, RelIntsPlanck / np.max(RelIntsPlanck), label="Planck curve", zorder=0.5) #title = title + " Temp = " + str(Temp) + "K"; #Now calculate a sensitivity spectrum Sensitivities = (SourceMinusLaser * np.max(RelIntsPlanck)) / ( np.max(MaskedSourceMinusLaser) / RelIntsPlanck) fig2 = plt.figure() ax2 = fig2.add_subplot(111) ax2.plot(self.CalibratedWavelength, Sensitivities / np.max(Sensitivities), label="Derived Sensitivity") #ax2.plot(self.CalibratedWavelength, 1 / Sensitivities, label = "Derived Correction"); ax2.set_xlabel("Wavelength [nm]") ax2.set_ylabel("Relative Sensitivity") ax2.set_xlim([ np.min(self.CalibratedWavelength), np.max(self.CalibratedWavelength) ]) ax2.set_ylim([0, 1.1]) ax2.grid(b=True, which='minor') ax2.grid(b=True, which='major') ax2.minorticks_on() ax2.legend(loc=0) fig2.savefig(outFile[:-4] + "-sensitivity.png") ax.set_title(title) #Print the peaks? if (printPeaks): PeakIndices = self.NIST.Peaks( self.CalibratedWavelength, SourceMinusLaser / np.max(SourceMinusLaser[self.LaserMask])) Heights = np.zeros(len(PeakIndices)) Peaks = np.zeros(len(PeakIndices)) SMLaserNorm = SourceMinusLaser / np.max( SourceMinusLaser[self.LaserMask]) for i in np.arange(0, len(PeakIndices), 1): Heights[i] = SourceMinusLaser[PeakIndices[i]] / np.max( SourceMinusLaser[self.LaserMask]) Peaks[i] = self.CalibratedWavelength[PeakIndices[i]] ax.scatter(Peaks, Heights, label="Peaks", c="green", zorder=1) if (printComponents): Components = self.analyse_spectrum() for Component in Components.items(): Name = Component[0] Fraction = Component[1][1] if (Fraction < self.Component_Frac_Min): continue #Not enough present #Now get the DATA C_WLs = self.NIST.Candidate_Components_Data[Name]["WLs"] C_WLs_Mask = np.logical_and( C_WLs > np.min(self.CalibratedWavelength), C_WLs < np.max(self.CalibratedWavelength)) C_WLs = C_WLs[C_WLs_Mask] C_RelInt = self.NIST.Candidate_Components_Data[Name]["RelInt"][ C_WLs_Mask] if (np.max(C_RelInt) == 0): break #Nope, invalid data C_RelInt /= np.max(C_RelInt) MaxWLIndex = np.where(C_RelInt == np.max(C_RelInt)) MaxWL = C_WLs[MaxWLIndex[0][0]] r, g, b = col.compute_rgb(MaxWL) c = col.rgb_to_hex(r * 255, g * 255, b * 255) percentage = Component[1][1] * 100 ax.scatter(C_WLs, C_RelInt, label="NIST " + Name, c=c, zorder=2) ax.legend(loc=0) fig.savefig(outFile)
def __init__(self, main_screen, jaar, soort): for wijk in d.get_areas("criminaliteit"): a = wijk[0] result = d.get_crime_data(soort, jaar, ("'" + a + "'")) canvas.itemconfig(str_to_code(main_screen, str(a)).shape, fill = c.rgb_to_hex(result, (255, 0 ,0), 35, True))
def set_brightness(self, l): h, s, _ = colors.rgb_to_hsl(self.rgb) self.hsl = (h, s, l) self.rgb = colors.hsl_to_rgb(self.hsl) self.hex = colors.rgb_to_hex(self.rgb) self.force_refresh()