modelingrealm.py 2.24 KB
Newer Older
class ModelingRealm(object):

    @staticmethod
    def parse(domain_name):
        if isinstance(domain_name, ModelingRealm):
        return ModelingRealm(domain_name)

    def __init__(self, domain_name):
        domain_name = domain_name.lower()
        if domain_name == 'seaice':
            self.name = 'seaIce'
        elif domain_name == 'landice':
            self.name = 'landIce'
        elif domain_name == 'atmoschem':
            self.name = 'atmosChem'
        elif domain_name == 'ocnbgchem':
            self.name = 'ocnBgchem'
        elif domain_name in ['ocean', 'atmos', 'land', 'aerosol']:
            self.name = domain_name
        else:
            raise ValueError('Domain {0} not recognized!'.format(domain_name))

    def __eq__(self, other):
        return other.__class__ == ModelingRealm and self.name == other.name
    def get_table_name(self, variable, frequency, data_convention):
        """
        Returns the table name for a domain-frequency pair
        :param data_convention: Data convention in use
        :type data_convention: str
        :param frequency: variable's frequency
        :type frequency: str
        :return: variable's table name
        :rtype: str
        """
        for table in variable.tables():
            if table.frequency == frequency:
                return table

        if frequency in ('mon', 'clim'):
            if self.name == 'seaIce':
                if data_convention == 'specs':
                    prefix = 'OI'
                else:
                    prefix = 'SI'
            elif self.name == 'landIce':
                prefix = 'LI'
            else:
                prefix = self.name[0].upper()
            table_name = prefix + frequency
        elif frequency == '6hr':
            table_name = '6hrPlev'
        else:
            table_name = 'day'
        return table_name


class ModelingRealms(object):
    seaIce = ModelingRealm('seaice')
    ocean = ModelingRealm('ocean')
    landIce = ModelingRealm('landIce')
    atmos = ModelingRealm('atmos')
    land = ModelingRealm('land')
    aerosol = ModelingRealm('aerosol')
    atmosChem = ModelingRealm('atmosChem')
    ocnBgchem = ModelingRealm('ocnBgchem')