Black value from the BlackBar in the calibrator. Created on Oct 10, 2010 @author: surya ''' import logging from GrayBar import GrayBar from ColorBar import ColorBar from Logging.Logger import getLog from IANASettings.Settings import ExitCode, CalibratorConstants log = getLog("Calibrator") log.setLevel(logging.ERROR) def getColorBars(qr, image, parenttags=None, level=logging.ERROR): ''' Extracts the ColorBars from the Image and represents them as ColorBar objects. Keyword Arguments: qr -- QRDetector.QR object image -- a PIL.Image object parenttags -- tag string of the calling function level -- the logging level Returns A list of Calibrator.ColorBar objects representing the three colorbars. '''
NOTE: The calibrator + filter dock = Stage Created on Oct 8, 2010 @author: surya ''' import logging from Stage import Stage from Calibrator import Calibrator from Logging.Logger import getLog from IANASettings.Settings import ExitCode, StageDetectorConstants log = getLog("StageDetector") log.setLevel(logging.ERROR) def computeBoxFromQR(qr, left, right, top, bottom, parenttags=None): """ Uses the QR coordinates to compute the coordinates of a Box subject to left, right, top, bottom params. Keyword Arguments: left -- distance from qrTopLeft to left right -- distance from qrTopLeft to right top -- distance from qrTopLeft to top bottom -- distance from qrTopLeft to bottom parenttags -- tag string of the calling function Returns: (topLeft, bottomLeft, bottomRight, topRight) coordinates
Created on Oct 8, 2010 @author: surya ''' import os import logging from subprocess import PIPE, Popen from Logging.Logger import getLog from IANASteps.Geometry.Point import Point from QR import QR from IANASettings.Settings import ExitCode log = getLog("QRFilter") log.setLevel(logging.ERROR) def detectQR(file_, parenttags=None, level=logging.ERROR): '''Call FindQRCode.jar to see whether QR code is correct. Keyword arguments: file_ -- The full file name toward the image file to be processed. parenttags -- The tag string of the calling method. level -- The logging level. Returns: QR -- an object of QRDetector.QR type. exitcode -- exit code returning from FindQRCode.jar.
''' Created on Oct 13, 2010 @author: surya ''' import logging from PIL.Image import QUAD, BICUBIC from Logging.Logger import getLog from IANASettings.Settings import ExitCode log = getLog("ImageTransformer") log.setLevel(logging.ERROR) def transform(image, stage, parenttags=None, level=logging.ERROR): ''' Performs the skew correction in the image. Keyword Arguments: image -- PIL.Image instance stage -- Absolute coordinates of the stage parentttags -- tag string of the calling function Returns: PIL.Image, The cropped image containing the stage. ''' # Set the logging level log.setLevel(level) tags = parenttags + " TRANSFORM"
from django.views.decorators.csrf import csrf_exempt from Collections.SuryaUploadData import * from Collections.SuryaDeploymentData import * from Collections.SuryaProcessingList import * from Collections.SuryaCalibrationData import * from SuryaWebPortal.utils.postparser import * from SuryaWebPortal.exceptions.UploadException import UploadException import mongoengine # Connect to MongoDB connect('SuryaDB', tz_aware=True) log = getLog('views') log.setLevel(logging.DEBUG) # The cell phone expect the following line as an OK signal in the first line CUSTOMIZED_PHONE_STATUS_OK = "upok " CUSTOMIZED_PHONE_STATUS_FAIL = "svrfail " def get_post_config(): # (required, type, db_name, default, parser) return { \ "device_id": PostParserArgs(True, "string", "device_id", "None", None), \
The CircleFilter Module uses the Hough Transform to detect circles in a given image Created on Oct 5, 2010 @author: surya ''' import opencv import logging from BCFilter import BCFilter from Logging.Logger import getLog from IANASettings.Settings import BCFilterConstants from IANASettings.Settings import ExitCode log = getLog("BCFilterDetector") log.setLevel(logging.ERROR) def splitToBands(image): ''' Split the given image into separate bands Keyword Arguments: image -- a PIL.Image object Returns: if the Image is RGB bands corresponding to R,G,B bands of the image if the Image is GrayScale then a single band containing the iage itself ''' if image.mode == 'L': bands = (image,)
import os import sys import errno import os.path import logging import StringIO import PIL import PIL.JpegImagePlugin import PIL.Image as Image import PIL.ImageDraw as ImageDraw import PIL.ImageFont as ImageFont from Logging.Logger import getLog log = getLog("ImageResize") log.setLevel(logging.ERROR) def imageRotate(imagefile, deg): '''Rotate image''' # check for string or a mongo gridfs file object log.error("imagefile type is: " + str(imagefile.__class__)) if isinstance(imagefile, str): if not os.path.isfile(imagefile): log.error('imagefile ' + imagefile + ' does not exist', extra=tags) return None, ExitCode.FileNotExists image = Image.open(imagefile) elif isinstance(imagefile, PIL.JpegImagePlugin.JpegImageFile) or isinstance(imagefile, PIL.Image.Image): image = imagefile else:
''' Created on Oct 12, 2010 @author: surya ''' import pylab import logging from BCCResult import BCCResult from Logging.Logger import getLog from IANAUtil.Rating import Rating from Scientific.Functions.LeastSquares import leastSquaresFit from IANASettings.Settings import ExitCode, BCCCalculatorConstants log = getLog("BCCCalculator") log.setLevel(logging.ERROR) def computeBCC(bcFilterRadius, bcLoading, exposedTime, flowRate): ''' Computes the black carbon concentration(ug/cm^3) according to the formula BCC(ug/L) = (bcFilterArea(cm^2) * bcLoading(ug/cm^2)) / (exposedTime(min) * flowRate(L/min)) NOTE : since cm^3 = L/1000 BCC(ug/cm^3) = BCC(ug/L) * 1000 Keyword arguments: bcFilterArea -- The Radius of the filter in cm bcLoading -- The black carbin loading value in ug/cm^2 exposedTime -- The exposure time of the bcfilter in mins
#!/usr/bin/python import logging from Logging.Logger import getLog from django import forms log = getLog('forms') log.setLevel(logging.DEBUG) class DownloadDataForm(forms.Form): startDateTime = forms.DateField(required=True, label='Start Date', widget=forms.DateInput(attrs={'class':'date_picker'}, format='%m/%d/%Y')) stopDateTime = forms.DateField(required=True, label='Stop Date', widget=forms.DateInput(attrs={'class':'date_picker'}, format='%m/%d/%Y')) def __init__(self, *args, **kwards): super(DownloadDataForm, self).__init__(*args, **kwards) #self.fields['deviceId'].choices = [ (d.deviceId, "%-10s - %s" % (str(d.deviceName), d.deviceId)) for d in DeviceData.objects ] def clean_startDateTime(self): try: d = self.cleaned_data['startDateTime'] dt = datetime(d.year, d.month, d.day) self.cleaned_data['startDateTime'] = dt print "now is " + str(self.cleaned_data) return dt except: raise forms.ValidationError("Invalid Start Date.")
from django.core.paginator import Paginator, InvalidPage, EmptyPage from Collections.SuryaUploadData import * from Collections.SuryaGroundTruth import * from Collections.SuryaDeploymentData import * from Collections.SuryaProcessingList import * from Collections.SuryaProcessResult import * from Collections.SuryaCalibrationData import * import mongoengine # Connect to MongoDB connect("SuryaDB") log = getLog("views") log.setLevel(logging.DEBUG) @login_required def debug(request): if not request.user.is_staff: return redirect("SuryaWebPortal.views.home.home") t = loader.get_template("debug/debug.html") c = RequestContext(request, {}) return HttpResponse(t.render(c)) @login_required def uploads(request, objID=None):
import PIL.ImageFont as ImageFont from optparse import OptionParser from Logging.Logger import getLog from IANASteps.Geometry.Point import Point from IANASettings.Settings import ExitCode, MainConstants, CalibratorConstants from IANASteps.QRDetector.QRDetector import detectQR from IANASteps.StageDetector.StageDetector import detectStage, detectCalibrator from IANASteps.ImageTransformer.ImageTransformer import transform from IANASteps.Calibrator.Calibrator import getGrayBars from IANASteps.BCFilterDetector.BCFilterDetector import splitToBands, detectBCFilter, select, PsycoInit from IANASteps.BCCCalculator.BCCCalculator import rateFilter from IANAUtil.Chart import plotChart from optparse import OptionParser log = getLog("Main") log.setLevel(logging.ERROR) def Main(imagefile, filterRadius, bcGradient, exposedTime, airFlowRate, imageLogLevel, debugImageFile, chartFile, parenttags=None, level=logging.ERROR,): ''' This method analyzes the imageFile, and uses the given parameters to comptute the BCC Keyword Arguments: imagefile -- The image file on which to perform the black carbon concentration analysis filterRadius -- The radius of the filter in the image bcGradient -- The gradient values to be used in the interpolation to ind the BCVol. exposedTime -- The time duration for which the filter was exposed. airFlowRate -- The flowrate of the pump. imageLogLevel-- 0, no logging, 1 log image, 2 log and show image debugImageFile -- The name of the debugImage in which to store the image processing debug info. chartFile -- The name of the chartFile in which to store the plotted results. parenttags -- The tagstring of the calling function
import psyco import traceback import PIL.Image as Image import PIL.ImageDraw as ImageDraw import PIL.ImageFont as ImageFont from Logging.Logger import getLog from IANASteps.Geometry.Point import Point from IANASteps.QRDetector.QRDetector import detectQR from IANASteps.Calibrator.Calibrator import getGrayBars from IANASteps.StageDetector.StageDetector import detectStage, detectCalibrator from IANASteps.ImageTransformer.ImageTransformer import transform from IANASettings.Settings import ExitCode, MainConstants, CalibratorConstants, BCFilterConstants from IANASteps.BCFilterDetector.BCFilterDetector import splitToBands, detectBCFilter, select, PsycoInit log = getLog("FeatureExtractor") log.setLevel(logging.ERROR) def saveDebugImage(debugImage, debugImagefile, tags): """ Saves the PIL.Image debugImage to the debugImagefile Keyword Arguments: debugImage -- a PIL.Image object debugImagefile -- a file or string tags -- tag string of the caliing function for logging """ if isinstance(debugImagefile, str): debugImage.save(debugImagefile) else: try:
Created on Nov 2, 2010 @author: surya ''' ''' Created on Oct 30, 2010 @author: surya ''' import os import logging from Logging.Logger import getLog log = getLog('AppLock') log.setLevel(logging.DEBUG) def getLock(lockFileName, programName, level=logging.DEBUG): ''' Creates a lock file given by the lockname and puts a pid of the current process in the lock file. If the lock file exists it checks if the a process given by the pid in the lock file is running. If such a process exits it returns False indicating failure to create a lock file. Returns: Boolean -- True if the process represented by programName isn't already running, False otherwise. ''' if os.path.exists(lockFileName):
''' Created on Nov 2, 2010 @author: surya ''' import logging from Logging.Logger import getLog from IANASteps.BCCCalculator.BCCCalculator import rateFilter from IANAUtil.Chart import plotChart from IANASettings.Settings import ExitCode log = getLog('BCCResultComputation') def bccResultComputation(sampledRGB, filterRadius, exposedTime, airFlowRate, bcGradient, gradient, chartFile, parenttags=None, level=logging.ERROR): ''' This method gets invoked externally with the specified params and computes the BCVol, it also plots the chart. Keyword Arguments: sampledRGB -- The sampled RGB values of the BCFilter filterRadius -- The radius of the filter in the image exposedTime -- The time duration for which the filter was exposed. airFlowRate -- The flowrate of the pump bcGradient -- The gradient values to be used in the interpolation to ind the BCVol gradient -- The gradient/grayscale list that is used in the interpolation chartFile -- The name of the chartFile in which to store the plotted results parenttags -- The tag string of the calling function level -- The logging level Returns: