def getIsceExt(self, info, imagename):
     ext = None
     # try to see if the image has the property imageType
     try:
         ext = key_of_same_content('image_type', info)[1]
         #if it is not a valid extension try something else
         if (not self.isExt(ext)):
             raise Exception
     except:
         # if not try to get the ext from the filename
         try:
             nameSplit = imagename.split('.')
             if len(nameSplit) > 1:  #there was atleast one dot in the name
                 ext = nameSplit[-1]
             if (not self.isExt(ext)):
                 raise Exception
         except:
             #try to use the scheme
             try:
                 scheme = key_of_same_content('scheme', info)[1]
                 ext = scheme.lower()
                 if (not self.isExt(ext)):
                     raise Exception
             except:
                 ext = None
     return ext
Exemple #2
0
 def createBrowseImages(self):
     import math
     for name in self._listPng:
         '''
         if(name.count(self._corrections)):
             command = 'mdx.py -P ' + name + ' -cmap cmy -wrap 20'
             self.saveImage(command,name + '_20rad')
         '''
         if name.count('unw.geo'):
             command = 'mdx.py -P ' + name
             createImage(command, name)
             command = 'mdx.py -P ' + name + ' -wrap 20'
             createImage(command, name + '_20rad')
             parser = createFileParser('xml')
             #get the properties from the one of the geo files
             prop, fac, misc = parser.parse(name + '.xml')
             coordinate1 = key_of_same_content('coordinate1', prop)[1]
             width = int(key_of_same_content('size', coordinate1)[1])
             command = 'mdx -P ' + name + ' -s ' + str(
                 width) + ' -amp -r4 -rtlr ' + str(int(width) * 4) + ' -CW'
             createImage(command, self._amplitude)
         elif name.count('cor.geo'):
             command = 'mdx.py -P ' + name
             createImage(command, name)
             parser = createFileParser('xml')
             #get the properties from the one of the geo files
             prop, fac, misc = parser.parse(name + '.xml')
             coordinate1 = key_of_same_content('coordinate1', prop)[1]
             width = int(key_of_same_content('size', coordinate1)[1])
             command = 'mdx -P ' + name + ' -s ' + str(
                 width) + ' -r4 -rhdr ' + str(
                     int(width) * 4) + ' -cmap cmy -wrap 1.2'
             createImage(command,
                         name.replace('.cor.geo', '_ph_only.cor.geo'))
Exemple #3
0
    def getGeoLocation(self):
        parser = createFileParser('xml')
        #get the properties from the one of the geo files

        prop, fac, misc = parser.parse('topophase.cor.geo.xml')
        coordinate1 = key_of_same_content('coordinate1', prop)[1]
        width = float(key_of_same_content('size', coordinate1)[1])
        startLon = float(key_of_same_content('startingValue', coordinate1)[1])
        deltaLon = float(key_of_same_content('delta', coordinate1)[1])
        endLon = startLon + deltaLon * width
        coordinate2 = key_of_same_content('coordinate2', prop)[1]
        length = float(key_of_same_content('size', coordinate2)[1])
        startLat = float(key_of_same_content('startingValue', coordinate2)[1])
        deltaLat = float(key_of_same_content('delta', coordinate2)[1])
        endLat = startLat + deltaLat * length
        minLat = min(startLat, endLat)
        maxLat = max(startLat, endLat)
        minLon = min(startLon, endLon)
        maxLon = max(startLon, endLon)
        return minLat, maxLat, minLon, maxLon
Exemple #4
0
    def initProperties(self,dictProp):
        """ as for calling _facilities, if we make sure that this method is
        called in the contructure we don't have to worry about this part
        #set the defaults first and then overwrite with the values in dictProp
        if property  present
        try:
            self._parameters()
        except:# not implemented
            pass
        """
        from iscesys.Parsers.Parser import const_key
        for k,v in dictProp.items():
            if k == const_key:
                continue
            #if it is  a property than it should be in dictionary of variables
            try:
                kp, vp = key_of_same_content(k, self.dictionaryOfVariables)
                #pure property are only present in dictProp
                if(k not in self._dictionaryOfFacilities):
                    compName = vp[0]
                    compName = compName.replace('self.','') # the dictionary of variables used to contain the self.
                    setattr(self,compName,v)

            except:#if it is not try to see if it implements a the _parameter
                warnOrErr = 'Error'
                if self._ignoreMissing:
                    warnOrErr = 'Warning'
                message='%s. The attribute corresponding to the key '%warnOrErr + \
                    '"%s" is not present in the object "%s".\nPossible causes are the definition'%(str(k),str(self.__class__)) + \
                    ' in the xml file of such attribute that is no longer defined \nin the '+ \
                    'object "%s" or a spelling error'%str(self.__class__)

                if self.logger:
                    if self._ignoreMissing:
                        self.logger.warning(message)
                    else:
                        self.logger.error(message)
                else:
                    print(message)
                if not self._ignoreMissing:
                    sys.exit(1)
Exemple #5
0
    def initRecursive(self,dictProp,dictFact):
        #separate simple properties from factories.
        #first init the properties since some time they might be used by the factories

        self.initProperties(dictProp)


        for k, dFk  in dictFact.items():
            #create an instance of the object
            factorymodule = ''
            factoryname = ''
            args = ()
            kwargs = {}
            mandatory = ''

#            try:
#                kp, dFk = key_of_same_content(k,dictFact)
#            except:
#                if self.logger:
#                    self.logger.error('No entry in the factory dictionary for %s. Cannot create the object.' % k)
#                else:
#                    print('No entry in the factory dictionary for %s. Cannot create the object.' % k)
#                raise Exception

            try:
                factorymodule = dFk['factorymodule']
            except:
                pass

            try:
                factoryname = dFk['factoryname']
            except:
                if self.logger:
                    self.logger.error('Cannot create object without a factory method.')
                else:
                    print('Cannot create object without a factory method.')
                raise Exception

            try:
                args = dFk['args']
            except:
                pass

            try:
                kwargs = dFk['kwargs']
            except:
                pass

            if factorymodule:
                statement= 'from ' + factorymodule + ' import ' + factoryname
#                raw_input("1:"+statement)
                if EXEC:
                    exec(statement)
                else:
                    factoryobject = getattr(
                        __import__(factorymodule, fromlist=['']),
                        factoryname
                        )
                    pass
                pass

#            raw_input("2:"+statement)
            if EXEC:
                factoryMethod = factoryname + '(*args,**kwargs)'
                statement = 'comp = ' + factoryMethod
                exec(statement)
            else:
#                raw_input("1:"+str(factoryobject))
                comp = factoryobject(*args, **kwargs)
                pass

            try:
                p, v = key_of_same_content(k,dictProp)
            except:
                v = {} # no property for this object. eventually the default will be set in initProperties

            if not isinstance(v,dict):
                # something wrong since it should be a complex object and therefore should be defined by a dict.
                if self.logger:
                    self.logger.error('Expecting a dictionary for the attribute',k,'. Instead received',v)
                else:
                    print('Expecting a dictionary for the attribute',k,'. Instead received',v)

            #now look for all the complex objects that are in dictFact and extract the factory
            nextDict = {}
            keyList = ['attrname','factorymodule','factoryname','kwargs','doc','args','mandatory']
            for k1, v1 in dFk.items():
                #check that it is not one of the reserved factory keys
                isReserved = False
                for k2check in keyList:
                    if k1 == k2check:
                        isReserved = True
                        break
                if not isReserved:
                    nextDict.update({k1:v1})

            # update with what has been set into _configureThis. Notice that some are not real Configurable, such as the runMethods
            # so they don't have catalog and _dictionaryOfFacilities
            if(hasattr(comp,'catalog') and hasattr(comp,'_dictionaryOfFacilities')):
                #configure the component first
                comp._configureThis()
                falseList =  [True]*2
                self._updateFromDicts([comp.catalog,comp._dictionaryOfFacilities],[v,nextDict],falseList)
                v = comp.catalog
                nextDict = comp._dictionaryOfFacilities
            if not (v == {} and nextDict == {}):#if they are both empty don't do anything
                comp.initRecursive(v,nextDict)

            # now the component is initialized. let's set it into the comp object giving the prescribed name
            kp, vp = key_of_same_content(k,self._dictionaryOfFacilities)
            try:
                #try the dictionaryOfFacilities to see if it is defined
                #and has the attrname. That means that it has beed passed from the command line.

                compName = vp['attrname']
                compName = compName.replace('self.','')# the dictionary of variables used to contain the self.
                setattr(self,compName,comp)

            except:
                if self.logger:
                    self.logger.error('The attribute',k,',is not present in the  _dictionaryOfFacilities.')
                else:
                    print('The attribute',k,',is not present in the _dictionaryOfFacilities.')
    def getInfoFromXml(self, imagexml, image):
        """ Determines  image name, width, image type and data type from input xml"""
        # first is alway the xml file
        ext = None
        dataType = None
        width = None
        length = None
        PA = createFileParser('xml')
        dictNow, dictFact, dictMisc = PA.parse(
            imagexml)  #get only the property dictionary
        numBands = 0

        numBands = key_of_same_content('number_bands', dictNow)[1]
        dataTypeImage = key_of_same_content('data_type', dictNow)[1]
        dataType = self._mapDataType['xml'][dataTypeImage]
        try:  #new format of image
            coordinate1 = key_of_same_content('coordinate1', dictNow)[1]
            width = key_of_same_content('size', coordinate1)[1]
            coordinate2 = key_of_same_content('coordinate2', dictNow)[1]
            length = key_of_same_content('size', coordinate2)[1]
            try:  #only for geo image to create kml
                self._width.append(float(width))
                self._startLon.append(
                    float(
                        key_of_same_content('startingValue', coordinate1)[1]))
                self._deltaLon.append(
                    float(key_of_same_content('delta', coordinate1)[1]))

                coordinate2 = key_of_same_content('coordinate2', dictNow)[1]
                self._length.append(
                    float(key_of_same_content('size', coordinate2)[1]))
                self._startLat.append(
                    float(
                        key_of_same_content('startingValue', coordinate2)[1]))
                self._deltaLat.append(
                    float(key_of_same_content('delta', coordinate2)[1]))
                self._names.append(imagexml.replace('.xml', ''))
            except Exception as e:
                pass  # not a geo image
        except:  # use old format
            try:
                width = key_of_same_content('width', dictNow)[1]
            except:
                print("Error. Cannot figure out width from input file.")
                raise Exception

        ext = self.getIsceExt(dictNow, image)

        if ext is None or dataType is None or width is None:  #nothing worked. Through exception caught next
            print("Error. Cannot figure out extension from input file.")
            raise Exception
        return {
            'image': image,
            'ext': ext,
            'width': width,
            'length': length,
            'dataType': dataType,
            'numBands': numBands
        }