#!/usr/bin/env python """ CERN@school pixel filter mask maker (from calibration information) """ # Import the code needed to manage files. import os, inspect, glob, argparse def readfile(filename): print("* Analysing file '%s'" % (filename)) vals = [] f = open(filename, "r") ls = f.readlines() print("*--> Number of lines = %d" % len(ls)) f.close() numzeroes = 0 for i, l in enumerate(ls): arow = l.strip().split("\t") #print("*----> Row %3d: %10d pixels." % (i, len(arow))) for j, val in enumerate(arow): #vals.append(int(p)) X = 256*i + j #print("*-------> Pixel [%3d,%3d] <-> [%5d] = %d" % (j,i,X,int(val))) if int(val) == 0: numzeroes += 1 vals.append(X) print("* Number of zeroes = %d" % (numzeroes)) return vals # # The main program. # if __name__=="__main__": print("==========================================") print(" CERN@school Filter File Maker (Python) ") print("==========================================") # Get the datafile path from the command line parser = argparse.ArgumentParser() parser.add_argument("datapath", \ help="Path to the folder containing your data." ) args = parser.parse_args() # Set the data file path. datapath = args.datapath maskvals = readfile(datapath + "/mask.txt") mf = open(datapath + "/filter-001.txt", "w") # Loop over the pixels to be masked and write them to the file. for X in maskvals: x = X%256 y = X/256 mf.write("%d\t%d\t1\n" % (x, y)) mf.close()