def get_bandDOYs(self, numberofbands, startDOY, imageryinterval, force=None): if self.bandDOYs is None or force == True: self.bandDOYs = [] for bandnumber in range(1, numberofbands + 1): self.bandDOYs.append(band_number_to_doy(bandnumber, startDOY, imageryinterval)) else: warnings.warn("Band DOYs already exist. Use force=True to overwrite.")
def write_mean_ref_to_txt(cropname, referencevalues, startdoy, doyinterval, outdir, comment="", postfix=""): #TODO docstring print "Writing mean reference curve to output file:" print referencevalues #output mean pixel values to file with open(os.path.join(outdir, cropname + postfix + "_mean.ref"), "w") as f: if comment: f.write("//" + comment + "\n\n") meanvals = get_mean_values(referencevalues) imgnumber = 1 for val in meanvals: doy = band_number_to_doy(imgnumber, startdoy, doyinterval) f.write("{0} {1}\n".format(doy, val)) imgnumber += 1
def write_refs_to_txt(cropname, referencevalues, startdoy, doyinterval, outdir, comment="", postfix=""): print "Writing pixel curves to output file:" print referencevalues #TODO: Rewrite this and next function with append on open, and integrate together to reduce redundant code #output individual pixel curves to file with open(os.path.join(outdir, cropname + postfix + "_points.ref"), "w") as f: if comment: f.write("//" + comment + "\n\n") point = 1 for points in referencevalues: f.write("\nPoint {0}:\n".format(point)) point += 1 imgnumber = 1 for val in points: doy = band_number_to_doy(imgnumber, startdoy, doyinterval) f.write("{0} {1}\n".format(doy, val)) imgnumber += 1
def process_pixel(bestguess, col, cropname, doyinterval, fitmthd, array, interpolatedCurve, outarray, row, startDOY, ndvalue, bounds, meantype=None, thresh=None, logging=None): #TODO docstrings logf = print if logging: try: logf = logging.log except: pass valsf = {} hasdata = True pixel = array[row, col] for i in range(pixel.size): measured = pixel[i] if measured == ndvalue: hasdata = False doy = band_number_to_doy(i+1, startDOY, doyinterval) valsf[doy] = measured if hasdata: res, transforms, message = find_fit(valsf, interpolatedCurve, bestguess, fitmthd, bounds=bounds, mean=meantype, threshold=thresh) logf("\tPixel r{0}, c{1}: {2}: {3}, {4}, {5}".format(row, col, cropname, res, transforms, message)) else: logf("\tPixel r{0}, c{1}: {2}: NO DATA.".format(row, col, cropname)) res = ndvalue outarray[row, col] = res return outarray