After the use of the duplicate.py script for a while, an amendment has been decided upon and implemented this week. This is to simply duplicate the sidecars where there is no change of pixel size involved. For example it may be just a case of the prefix being changed.
To implement these changes the following alterations were made in the script:
# set up command line argument parser
parser = argparse.ArgumentParser(prog='duplicate')
parser.add_argument('-s', '--source', required=True)
parser.add_argument('-d', '--dest', required=True)
parser.add_argument('-m', '--multisuffix', type=str, default="")
parser.add_argument('-p', '--pixelsize', type=float, default=None)
parser = argparse.ArgumentParser(prog='duplicate')
parser.add_argument('-s', '--source', required=True)
parser.add_argument('-d', '--dest', required=True)
parser.add_argument('-m', '--multisuffix', type=str, default="")
parser.add_argument('-p', '--pixelsize', type=float, default=None)
The main change in the above is to allow the multiplier suffix parameter -m to default to an empty string if omitted (instead of "x2") and the pixel size parameter -p to default to the special value None (which is essentially a Null) if omitted, instead of a fixed value size. Having an empty string default for multiSuffix allows no suffix on the filename if none is specified at input. The original code that adds this string on to filenames didn't need to be changed because an empty string is still a string and processed accordingly.
The other change is in the part that copies the original world file and specifically relates to the pixelSize parameter.
# write new world file
worldFile = open(WFPNew, "w+")
if pixelSize is None:
worldFile.write(worldFileLines[0] + "\n")
else:
worldFile.write(str(pixelSize) + "\n")
worldFile.write(worldFileLines[1] + "\n")
worldFile.write(worldFileLines[2] + "\n")
if pixelSize is None:
worldFile.write(worldFileLines[3] + "\n")
else:
worldFile.write("-" + str(pixelSize) + "\n")
worldFile.write(worldFileLines[4] + "\n")
worldFile.write(worldFileLines[5] + "\n")
worldFile.close()
worldFile = open(WFPNew, "w+")
if pixelSize is None:
worldFile.write(worldFileLines[0] + "\n")
else:
worldFile.write(str(pixelSize) + "\n")
worldFile.write(worldFileLines[1] + "\n")
worldFile.write(worldFileLines[2] + "\n")
if pixelSize is None:
worldFile.write(worldFileLines[3] + "\n")
else:
worldFile.write("-" + str(pixelSize) + "\n")
worldFile.write(worldFileLines[4] + "\n")
worldFile.write(worldFileLines[5] + "\n")
worldFile.close()
The changes here are a couple of if..else statements relating to pixelSize. If pixelSize is set to the None value, as will be the case if no value was passed on the command line, then the original value is passed through from the source file. Otherwise, the pixelSize value is assumed to be a valid value to be written into the new world file.
This allows this duplicate.py script to be used for more things than was originally planned, since there are a number of cases where the base layers are not resized and still need their sidecar files to be duplicated for exported derivative layers from the mosaics, which this script will speed up the work of doing.