diff --git a/src/diffpy/srxplanar/srxplanarconfig.py b/src/diffpy/srxplanar/srxplanarconfig.py index 669eeee..400ff17 100644 --- a/src/diffpy/srxplanar/srxplanarconfig.py +++ b/src/diffpy/srxplanar/srxplanarconfig.py @@ -13,24 +13,14 @@ # ############################################################################## -import argparse -import os -import re -import sys -from configparser import ConfigParser -from functools import partial - import numpy as np from diffpy.confutils.config import ConfigBase -from diffpy.confutils.tools import ( - _configPropertyR, - _configPropertyRad, - _configPropertyRW, -) +from diffpy.confutils.tools import _configPropertyRad _description = """ -SrXplanar -- integrate 2D powder diffraction image to 1D with unceratinty propagation +SrXplanar -- integrate 2D powder diffraction image to 1D +with unceratinty propagation """ # Text to display after the argument help _epilog = """ @@ -56,7 +46,10 @@ "config": "n", "header": "n", "f": "filename", - "h": "filename or list of filenames or filename pattern or list of filename pattern", + "h": ( + "filename or list of filenames or filename pattern" + " or list of filename pattern" + ), "n": "*", "d": [], }, @@ -85,7 +78,7 @@ "d": False, }, ], - # Expeiment gropu + # Experiment group [ "opendirectory", { @@ -113,7 +106,10 @@ { "sec": "Experiment", "s": "mask", - "h": "the mask file (support numpy .npy array, and tiff image, >0 stands for masked pixel)", + "h": ( + "the mask file (support numpy .npy array, and tiff image," + " >0 stands for masked pixel)" + ), "d": "", "tt": "file", }, @@ -124,7 +120,10 @@ "sec": "Control", "config": "n", "header": "n", - "h": "create a mask file according to current image file and value of addmask", + "h": ( + "create a mask file according to" + " current image file and value of addmask" + ), "d": "", }, ], @@ -237,7 +236,7 @@ "fliphorizontal", { "sec": "Beamline", - "h": "filp the image horizontally", + "h": "flip the image horizontally", "n": "?", "co": True, "d": False, @@ -247,7 +246,7 @@ "flipvertical", { "sec": "Beamline", - "h": "filp the image vertically", + "h": "flip the image vertically", "n": "?", "co": True, "d": True, @@ -356,7 +355,11 @@ "avgmask", { "sec": "Others", - "h": "create a dynamic averaging mask that mask pixel with too high or too low intensity compare to the pixels which have similar twotheta value", + "h": ( + "create a dynamic averaging mask that mask pixel with" + " too high or too low intensity compare to the pixels" + " which have similar twotheta value" + ), "n": "?", "co": True, "d": True, @@ -385,7 +388,10 @@ "cropedges", { "sec": "Others", - "h": "crop the image, maske pixels around the image edge (left, right, top, bottom), must larger than 0", + "h": ( + "crop the image, maske pixels around the image edge" + " (left, right, top, bottom), must larger than 0" + ), "n": 4, "tt": "array", "t": "intlist", @@ -399,9 +405,13 @@ "args": "n", "config": "n", "header": "n", - "h": "crop the edge pixels, first four means the number of pixels masked in each edge \ + "h": ( + "crop the edge pixels, first four means" + " the number of pixels masked in each edge \ (left, right, top, bottom), this crop is after all prepare calculation, \ -so change this value does not require a config update, value must larger than 0", +so change this value does not require a config update," + " value must larger than 0" + ), "n": 4, "tt": "array", "t": "intlist", @@ -414,7 +424,10 @@ "sec": "Others", "config": "n", "header": "n", - "h": "set True to disable all calculation, will automaticly set True if createconfig or createmask", + "h": ( + "set True to disable all calculation," + " will automatically set True if createconfig or createmask" + ), "n": "?", "co": True, "d": False, @@ -461,7 +474,11 @@ "args": "n", "config": "n", "header": "n", - "h": "a threshold for masked pixels in average masking, pixels with (self_int > avg_int * avgmaskhigh) will be masked", + "h": ( + "a threshold for masked pixels in average masking," + " pixels with (self_int > avg_int * avgmaskhigh)" + " will be masked" + ), "d": 2.0, }, ], @@ -472,7 +489,10 @@ "args": "n", "config": "n", "header": "n", - "h": "a threshold for masked pixels in average masking, pixels with (self_int < avg_int * avgmasklow) will be masked", + "h": ( + "a threshold for masked pixels in average masking," + " pixels with (self_int < avg_int * avgmasklow) will be masked" + ), "d": 0.5, }, ], @@ -480,7 +500,7 @@ _defaultdata = { "configfile": ["srxplanar.cfg", "SrXplanar.cfg"], - "headertitle": "SrXplanar configration", + "headertitle": "SrXplanar configuration", } @@ -508,7 +528,12 @@ def _preInit(self, **kwargs): for name in ["rotation", "tilt", "tthstep", "tthmax"]: setattr(self.__class__, name, _configPropertyRad(name + "d")) - # cls._configlist['Experiment'].extend(['rotation', 'tilt', 'tthstep', 'tthmax']) + # cls._configlist['Experiment'].extend([ + # 'rotation', + # 'tilt', + # 'tthstep', + # 'tthmax', + # ]) return def _preUpdateSelf(self, **kwargs): @@ -543,9 +568,11 @@ def _postUpdateConfig(self, **kwargs): :param kwargs: optional kwargs """ - if (self.createconfig != "") and (self.createconfig != None): + if (self.createconfig != "") and (self.createconfig is not None): self.nocalculation = True - if (self.createconfigfull != "") and (self.createconfigfull != None): + if (self.createconfigfull != "") and ( + self.createconfigfull is not None + ): self.nocalculation = True if self.createmask != "": self.nocalculation = True diff --git a/src/diffpy/srxplanar/tifffile.py b/src/diffpy/srxplanar/tifffile.py index 33329ed..3a42f13 100644 --- a/src/diffpy/srxplanar/tifffile.py +++ b/src/diffpy/srxplanar/tifffile.py @@ -854,7 +854,7 @@ def series(self): page.axes, page.compression in TIFF_DECOMPESSORS, ) - if not shape in pages: + if shape not in pages: shapes.append(shape) pages[shape] = [page] else: @@ -954,8 +954,8 @@ def _omeseries(self): ): continue for value in annot: - for modul in value: - for along in modul: + for modulo in value: + for along in modulo: if not along.tag[:-1].endswith("Along"): continue axis = along.tag[-1] @@ -1215,14 +1215,14 @@ def _fromfile(self): if tagcode > tag.code: warnings.warn("tags are not ordered by code") tagcode = tag.code - if not tag.name in tags: + if tag.name not in tags: tags[tag.name] = tag else: # some files contain multiple IFD with same code # e.g. MicroManager files contain two image_description for ext in ("_1", "_2", "_3"): name = tag.name + ext - if not name in tags: + if name not in tags: tags[name] = tag break @@ -1292,7 +1292,7 @@ def _process_tags(self): else: self.sample_format = TIFF_SAMPLE_FORMATS[value[0]] - if not "photometric" in tags: + if "photometric" not in tags: self.photometric = None if "image_length" in tags: @@ -1327,7 +1327,7 @@ def _process_tags(self): warnings.warn(str(e)) self.imagej_tags = Record(adict) - if not "image_length" in self.tags or not "image_width" in self.tags: + if "image_length" not in self.tags or "image_width" not in self.tags: # some GEL file pages are missing image data self.image_length = 0 self.image_width = 0 @@ -1453,7 +1453,7 @@ def _process_tags(self): self.shape = self._shape[2:4] self.axes = "YX" - if not self.compression and not "strip_byte_counts" in tags: + if not self.compression and "strip_byte_counts" not in tags: self.strip_byte_counts = numpy.prod(self.shape) * ( self.bits_per_sample // 8 ) @@ -1900,7 +1900,7 @@ def _fromfile(self, parent): else: value = struct.unpack(fmt, value[:size]) - if not code in CUSTOM_TAGS: + if code not in CUSTOM_TAGS: if len(value) == 1: value = value[0] @@ -1938,7 +1938,7 @@ class TiffSequence(object): (2, 100, 256, 256) """ - _axes_pattern = """ + _axes_pattern = r""" # matches Olympus OIF and Leica TIFF series _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4})) _?(?:(q|l|p|a|c|t|x|y|z|ch|tp)(\d{1,4}))? @@ -2115,12 +2115,12 @@ def __str__(self): .rstrip() ) for k, v in lists: - l = [] + parse_list = [] for i, w in enumerate(v): - l.append( + parse_list.append( "* %s[%i]\n %s" % (k, i, str(w).replace("\n", "\n ")) ) - s.append("\n".join(l)) + s.append("\n".join(parse_list)) return "\n".join(s) @@ -2615,8 +2615,8 @@ def unpackints(data, dtype, itemsize, runlen=0): dtypestr = ">" + dtype.char # dtype always big endian? unpack = struct.unpack - l = runlen * (len(data) * 8 // (runlen * itemsize + skipbits)) - result = numpy.empty((l,), dtype) + length = runlen * (len(data) * 8 // (runlen * itemsize + skipbits)) + result = numpy.empty((length,), dtype) bitcount = 0 for i in range(len(result)): start = bitcount // 8 @@ -2760,7 +2760,7 @@ def natural_sorted(iterable): def sortkey(x): return [(int(c) if c.isdigit() else c) for c in re.split(numbers, x)] - numbers = re.compile("(\d+)") + numbers = re.compile(r"(\d+)") return sorted(iterable, key=sortkey) @@ -3421,7 +3421,7 @@ def __getitem__(self, key): 0x90000001: "name", 0x90000002: "power", 0x90000003: "wavelength", - 0x90000004: "aquire", + 0x90000004: "acquire", 0x90000005: "detchannel_name", 0x90000006: "power_bc1", 0x90000007: "power_bc2", @@ -3850,7 +3850,9 @@ def main(argv=None): import optparse - search_doc = lambda r, d: re.search(r, __doc__).group(1) if __doc__ else d + def search_doc(r, d): + return re.search(r, __doc__).group(1) if __doc__ else d + parser = optparse.OptionParser( usage="usage: %prog [options] path", description=search_doc("\n\n([^|]*?)\n\n", ""),