Ejemplo n.º 1
0
def get_sofa(url: str) -> SOFAFile:
    import requests
    from tempfile import NamedTemporaryFile

    if url.startswith(('http://', 'https://')):
        r = requests.get(url)
        r.raise_for_status()

        with NamedTemporaryFile() as f:
            f.write(r.content)
            return SOFAFile(f.name, 'r')
    elif url.startswith('file://'):
        url = url[7:]
    return SOFAFile(url, 'r')
Ejemplo n.º 2
0
    def isValid(self):
        """
        Check for convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'TF'
        - 'SOFAConventions' == 'GeneralTF'

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention

        # # Attributes
        if not self.isTFDataType():
            warnings.warn(
                'DataType is not "TF", got: "{}"'.format(
                    self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('SOFAConventions') == 'GeneralTF':
            warnings.warn(
                'SOFAConventions is not "GeneralTF", got: "{}"'.format(
                    self.getGlobalAttributeValue('SOFAConventions')),
                SOFAWarning)
            return False

        return True
    def isValid(self):
        """
        Check for convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'FIRE'
        - 'SOFAConventions' == 'MultiSpeakerBRIR'
        - Mandatory attribute 'DatabaseName'

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention

        # # Attributes
        if not self.isFIREDataType():
            warnings.warn('DataType is not "FIRE", got: "{}"'.format(
                self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('SOFAConventions') == 'MultiSpeakerBRIR':
            warnings.warn('SOFAConventions is not "MultiSpeakerBRIR", got: "{}"'.format(
                self.getGlobalAttributeValue('SOFAConventions')), SOFAWarning)
            return False

        if not self.hasGlobalAttribute('DatabaseName'):
            warnings.warn('Missing required Global Attribute "DatabaseName"', SOFAWarning)
            return False

        return True
Ejemplo n.º 4
0
    def isValid(self):
        """
        Check for convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'FIR'
        - 'SOFAConventions' == 'SingleRoomDRIR'
        - 'RoomType' == 'reverberant'
        - Mandatory attribute 'RoomDescription'
        - ListenerUp and ListenerView are mandatory
        - E == 1

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention
        # # Attributes
        if not self.isFIRDataType():
            warnings.warn('DataType is not "FIR", got: "{}"'.format(
                self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('SOFAConventions') == 'SingleRoomDRIR':
            warnings.warn('SOFAConventions is not "SingleRoomDRIR", got: "{}"'.format(
                self.getGlobalAttributeValue('SOFAConventions')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('RoomType') == 'reverberant':
            warnings.warn('RoomType is not "reverberant", got: "{}"'.format(self.getGlobalAttributeValue('RoomType')),
                          SOFAWarning)
            return False

        if not self.hasGlobalAttribute('RoomDescription'):
            warnings.warn('Missing required Global Attribute "RoomDescription"', SOFAWarning)
            return False

        # # Variables
        if not self.hasListenerUp() or not self.hasListenerView():
            warnings.warn('Missing required Variables "ListenerUp" and "ListenerView"', SOFAWarning)
            return False

        # # Dimensions
        if not self.getDimensionSize('E') == 1:
            warnings.warn('Number of emitters (E) is not "1", got "{}"'.format(self.getDimensionSize('E')),
                          SOFAWarning)
            return False

        return True
    def isValid(self):
        """
        Check for convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'SOS'
        - 'SOFAConventions' == 'SimpleFreeFieldSOS'
        - 'RoomType' == 'free field'
        - Mandatory attribute 'DatabaseName'
        - E == 1
        - N must be multiple of 6

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention

        # # Attributes
        if not self.isSOSDataType():
            warnings.warn(
                'DataType is not "SOS", got: "{}"'.format(
                    self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue(
                'SOFAConventions') == 'SimpleFreeFieldSOS':
            warnings.warn(
                'SOFAConventions is not "SimpleFreeFieldSOS", got: "{}"'.
                format(self.getGlobalAttributeValue('SOFAConventions')),
                SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('RoomType') == 'free field':
            warnings.warn(
                'RoomType is not "free field", got: "{}"'.format(
                    self.getGlobalAttributeValue('RoomType')), SOFAWarning)
            return False

        if not self.hasGlobalAttribute('DatabaseName'):
            warnings.warn('Missing required Global Attribute "DatabaseName"',
                          SOFAWarning)
            return False

        # # Dimensions
        if not self.getDimensionSize('E') == 1:
            warnings.warn(
                'Number of emitters (E) is not "1", got "{}"'.format(
                    self.getDimensionSize('E')), SOFAWarning)
            return False

        if not (self.getDimensionSize('N') % 6 == 0):
            warnings.warn(
                'Number of coefficients (N) is not multiple of "6", got "{}"'.
                format(self.getDimensionSize('N')), SOFAWarning)
            return False

        return True
    def isValid(self):
        """
        Check for GeneralFIR convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'FIR'
        - 'SOFAConventions' == 'SimpleFreeFieldHRIR'
        - 'RoomType' == 'free field'
        - Mandatory attribute 'ListenerShortName'
        - Mandatory attribute 'DatabaseName'
        - E == 1 (single emitter)
        - R == 2 (two ears)

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention

        # # Attributes
        if not self.isFIRDataType():
            warnings.warn(
                'DataType is not "FIR", got: "{}"'.format(
                    self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue(
                'SOFAConventions') == 'SimpleFreeFieldHRIR':
            warnings.warn(
                'SOFAConventions is not "SimpleFreeFieldHRIR", got: "{}"'.
                format(self.getGlobalAttributeValue('SOFAConventions')),
                SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('RoomType') == 'free field':
            warnings.warn(
                'RoomType is not "free field", got: "{}"'.format(
                    self.getGlobalAttributeValue('RoomType')), SOFAWarning)
            return False

        if not self.hasGlobalAttribute('ListenerShortName'):
            warnings.warn(
                'Missing required Global Attribute "ListenerShortName"',
                SOFAWarning)
            return False

        if not self.hasGlobalAttribute('DatabaseName'):
            warnings.warn('Missing required Global Attribute "DatabaseName"',
                          SOFAWarning)
            return False

        # # Dimensions
        if not self.getDimensionSize('E') == 1:
            warnings.warn(
                'Number of emitters (E) is not "1", got "{}"'.format(
                    self.getDimensionSize('E')), SOFAWarning)
            return False

        if not self.getDimensionSize('R') == 2:
            warnings.warn(
                'Number of receivers (R) is not "2", got "{}"'.format(
                    self.getDimensionSize('R')), SOFAWarning)
            return False

        return True
Ejemplo n.º 7
0
    def isValid(self):
        """
        Check for convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'FIRE'
        - 'SOFAConventions' == 'AmbisonicsDRIR'
        - Mandatory global attribute 'AmbisonicsOrder'
        - Mandatory Data.IR attributes 'ChannelOrdering' and 'Normalization'
        - ListenerUp and ListenerView are mandatory
        - SourceUp and SourceView are mandatory

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention

        # # Attributes
        if not self.isFIREDataType():
            warnings.warn(
                'DataType is not "FIRE", got: "{}"'.format(
                    self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue(
                'SOFAConventions') == 'AmbisonicsDRIR':
            warnings.warn(
                'SOFAConventions is not "AmbisonicsDRIR", got: "{}"'.format(
                    self.getGlobalAttributeValue('SOFAConventions')),
                SOFAWarning)
            return False

        if 'AmbisonicsOrder' not in self.getGlobalAttributesAsDict():
            warnings.warn(
                'Missing required Global Attribute "AmbisonicsOrder"',
                SOFAWarning)
            return False

        if self.getVariableAttributeValue('Data.IR',
                                          'ChannelOrdering') is None:
            warnings.warn(
                'Missing required Data.IR Attribute "ChannelOrdering"',
                SOFAWarning)
            return False

        if self.getVariableAttributeValue('Data.IR', 'Normalization') is None:
            warnings.warn('Missing required Data.IR Attribute "Normalization"',
                          SOFAWarning)
            return False

        # #  Variables
        if not self.hasListenerUp() or not self.hasListenerView():
            warnings.warn(
                'Missing required Variables "ListenerUp" and "ListenerView"',
                SOFAWarning)
            return False

        if not self.hasSourceUp() or not self.hasSourceView():
            warnings.warn(
                'Missing required Variables "SourceUp" and "SourceView"',
                SOFAWarning)
            return False

        return True
Ejemplo n.º 8
0
    def isValid(self):
        """
        Check for convention consistency
        It ensures general file consistency, and also specifics for this convention.
        - 'DataType' == 'FIR'
        - 'SOFAConventions' == 'SimpleHeadphoneIR'
        - 'RoomType' == 'free field'
        - Mandatory attribute 'ListenerShortName'
        - Mandatory attribute 'ListenerDescription'
        - Mandatory attribute 'SourceDescription'
        - Mandatory attribute 'EmitterDescription'
        - Mandatory attribute 'DatabaseName'
        - Mandatory attribute 'SourceModel'
        - Mandatory attribute 'SourceManufacturer'
        - Mandatory attribute 'SourceURI'
        - E == R

        :return:    Boolean
        :raises:    SOFAWarning with error description, in case
        """

        # Check general file validity
        if not SOFAFile.isValid(self):
            return False

        # Ensure specifics of this convention

        # # Attributes
        if not self.isFIRDataType():
            warnings.warn(
                'DataType is not "FIR", got: "{}"'.format(
                    self.getGlobalAttributeValue('DataType')), SOFAWarning)
            return False

        if not self.getGlobalAttributeValue(
                'SOFAConventions') == 'SimpleHeadphoneIR':
            warnings.warn(
                'SOFAConventions is not "SimpleHeadphoneIR", got: "{}"'.format(
                    self.getGlobalAttributeValue('SOFAConventions')),
                SOFAWarning)
            return False

        if not self.getGlobalAttributeValue('RoomType') == 'free field':
            warnings.warn(
                'RoomType is not "free field", got: "{}"'.format(
                    self.getGlobalAttributeValue('RoomType')), SOFAWarning)
            return False

        if not self.hasGlobalAttribute('ListenerShortName'):
            warnings.warn(
                'Missing required Global Attribute "ListenerShortName"',
                SOFAWarning)
            return False

        if not self.hasGlobalAttribute('ListenerDescription'):
            warnings.warn(
                'Missing required Global Attribute "ListenerDescription"',
                SOFAWarning)
            return False

        if not self.hasGlobalAttribute('SourceDescription'):
            warnings.warn(
                'Missing required Global Attribute "SourceDescription"',
                SOFAWarning)
            return False

        if not self.hasGlobalAttribute('EmitterDescription'):
            warnings.warn(
                'Missing required Global Attribute "EmitterDescription"',
                SOFAWarning)
            return False

        if not self.hasGlobalAttribute('DatabaseName'):
            warnings.warn('Missing required Global Attribute "DatabaseName"',
                          SOFAWarning)
            return False

        if not self.hasGlobalAttribute('SourceModel'):
            warnings.warn('Missing required Global Attribute "SourceModel"',
                          SOFAWarning)
            return False

        if not self.hasGlobalAttribute('SourceManufacturer'):
            warnings.warn(
                'Missing required Global Attribute "SourceManufacturer"',
                SOFAWarning)
            return False

        if not self.hasGlobalAttribute('SourceURI'):
            warnings.warn('Missing required Global Attribute "SourceURI"',
                          SOFAWarning)
            return False

        # # Dimensions
        if not self.getDimensionSize('E') == self.getDimensionSize('R'):
            warnings.warn(
                'Number of emitters (E) and number of receivers (R) do not match, got "{}" and "{}"'
                .format(self.getDimensionSize('E'),
                        self.getDimensionSize('R')), SOFAWarning)
            return False

        return True