<commit_before>#!/usr/bin/python
import argparse
import sys, os
import sqlite3 as sq
import plantcv as pcv
import math

### Parse command-line arguments
def options():
  parser = argparse.ArgumentParser(description="Extract and Normalize Tillering data from an SQLite database")
  parser.add_argument("-d", "--database", help="SQLite database file from plantcv.", required=True)
  parser.add_argument("-o", "--outfile", help="Output text file.", required=True)
  parser.add_argument("-p", "--height", help="Height of images in pixels", required=True, type=int)
  parser.add_argument("-D", "--debug", help="Turn on debugging mode", action="store_true")
  args = parser.parse_args()
  return args

### Dictionary factory for SQLite query results
def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

### Top-view center of mass correction
def tv_centroid_correction(area, centroid_height):
  correction_factor = 0.9015 * math.exp(0.0007 * centroid_height)
  area /= correction_factor
  return area

### Zoom correction
def zoom_correction(area, zoom):
  correction_factor = 0.9015 * math.exp(0.0007 * zoom)
  area /= correction_factor
  return area

### Length conversion
def px_to_cm(px, zoom):
  pxcm = (0.000002171 * (zoom ** 2)) + (0.002073 * zoom) + 14.27
  cm = px / pxcm
  return cm

### Main pipeline
def main():
  # Get options
  args = options()
  
  # Does the database exist?
  if not os.path.exists(args.database):
    pcv.fatal_error("The database file " + str(args.database) + " does not exist");
  
  # Open a connection
  try:
    connect=sq.connect(args.database)
  except sq.Error, e:
    print("Error %s:" % e.args[0])
  
  # Open output file
  try:
    out = open(args.outfile, 'w')
  except IOError:
    print("IO error")
  
  # Header
  out.write(','.join(map(str, ('plant_id', 'datetime', 'tillering_line', 'raw_tillering_count', 'raw_tillering_widths', 'average_tillering_width', 'median_tillering_width', 'std_tillering_width'))) + '\n')
  
  # Replace the row_factory result constructor with a dictionary constructor
  connect.row_factory = dict_factory
  # Change the text output format from unicode to UTF-8
  connect.text_factory=str
  
  # Database handler
  db = connect.cursor()
  
  # Retrieve snapshot IDs from the database
  snapshots = []
  for row in (db.execute('SELECT DISTINCT(`datetime`) FROM `snapshots` WHERE `camera`="vis_sv"')):
    snapshots.append(row['datetime'])
  if (args.debug):
    print('Found ' + str(len(snapshots)) + ' snapshots')
  
  # Retrieve snapshots and process data
  for snapshot in snapshots:
    sv_image_count = 0
    outlier = False
    plant_id = ''
    tillering_line=0
    raw_tillering_count=0
    raw_tillering_width=[]
    average_tillering_width=0
    median_tillering_width=0
    std_tillering_width=0
    print raw_tillering_width
    
    ## Measure plant height
    
    #image_count = 0
    #tillering_line = 0<commit_msg>permissions change<commit_after>#!/usr/bin/python
import argparse
import sys, os
import sqlite3 as sq
import plantcv as pcv
import math

### Parse command-line arguments
def options():
  parser = argparse.ArgumentParser(description="Extract and Normalize Tillering data from an SQLite database")
  parser.add_argument("-d", "--database", help="SQLite database file from plantcv.", required=True)
  parser.add_argument("-o", "--outfile", help="Output text file.", required=True)
  parser.add_argument("-p", "--height", help="Height of images in pixels", required=True, type=int)
  parser.add_argument("-t", "--tiller", help="Optional manual input of zoom-corrected tiller width in pixels", required=False, type=int)
  parser.add_argument("-g", "--genotype",help="choose 'on' or 'off' to seperate widths by genotype", required=True)
  parser.add_argument("-e", "--treatment", help="choose 'on' or 'off' to sepearte widths by treatment", required=True)
  parser.add_argument("-D", "--debug", help="Turn on debugging mode", action="store_true")
  args = parser.parse_args()
  return args

### Dictionary factory for SQLite query results
def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

### Top-view center of mass correction
def tv_centroid_correction(area, centroid_height):
  correction_factor = 0.9015 * math.exp(0.0007 * centroid_height)
  area /= correction_factor
  return area

### Zoom correction
def zoom_correction(area, zoom):
  correction_factor = 0.9015 * math.exp(0.0007 * zoom)
  area /= correction_factor
  return area

### Length conversion
def px_to_cm(px, zoom):
  pxcm = (0.000002171 * (zoom ** 2)) + (0.002073 * zoom) + 14.27
  cm = px / pxcm
  return cm

### Main pipeline
def main():
  # Get options
  args = options()
  
  # Does the database exist?
  if not os.path.exists(args.database):
    pcv.fatal_error("The database file " + str(args.database) + " does not exist");
  
  # Open a connection
  try:
    connect=sq.connect(args.database)
  except sq.Error, e:
    print("Error %s:" % e.args[0])
  
  # Open output file
  try:
    out = open(args.outfile, 'w')
  except IOError:
    print("IO error")
  
  # Header
  out.write(','.join(map(str, ('plant_id', 'datetime', 'image_path', 'raw_tillering_count', 'raw_tillering_widths', 'zoom_corrected_tiller_widths','manual_input_single_tiller','estimated_single_tiller','new_tiller_count'))) + '\n')
  
  # Replace the row_factory result constructor with a dictionary constructor
  connect.row_factory = dict_factory
  # Change the text output format from unicode to UTF-8
  connect.text_factory=str
  
  # Database handler
  db = connect.cursor()
  
  # Retrieve snapshot IDs from the database
  snapshots = []
  for row in (db.execute('SELECT DISTINCT(`datetime`) FROM `snapshots` WHERE `camera`="vis_sv"')):
    snapshots.append(row['datetime'])
  if (args.debug):
    print('Found ' + str(len(snapshots)) + ' snapshots')
    
  print snapshots  
  
  
  # Retrieve snapshots and process data
  #for snapshot in snapshots:
  #  sv_image_count = 0
  #  outlier = False
  #  plant_id = ''
  #  tillering_line=0
  #  raw_tillering_count=0
  #  raw_tillering_width=[]
  #  average_tillering_width=0
  #  median_tillering_width=0
  #  std_tillering_width=0
  #  print raw_tillering_width
  #  
    ## Measure plant height
    
    #image_count = 0
    #tillering_line = 0
{'fraction_non_alphanumeric': 0.1270856073600499, 'fraction_numerical': 0.016840792140963668, 'mean_word_length': 4.0703557312252965, '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': '4978751', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2101, 'n_words': 558}