Exemplo n.º 1
0
class TestNCIO(unittest.TestCase):
    """Test the ncio module (netCDF input/output)."""

    args = [
        '-x', 'climpact2.sampledata.gridded.1991-2010.nc', '-n',
        'climpact2.sampledata.gridded.1991-2010.nc', '--vnamex=tmax',
        '--vnamen=tmin', '--base=1991-2010', '-v'
    ]
    options = getoptions.parse_arguments(args)
    timedata = ncio.get_time_data(options)

    def testTimeData(self):
        """Should return a TimeData class"""
        self.assertIs(type(ncio.get_time_data(self.options)), ncio.TimeData)
        timedata = ncio.get_time_data(self.options)
        print(timedata.calendar)
        self.assertTrue(timedata.calendar in [
            'standard', '360_day', 'gregorian', 'proleptic_gregorian',
            '365_day'
        ])
        self.assertIs(type(timedata.dayone), dt.datetime)
        self.assertIs(type(timedata.daylast), dt.datetime)

    #def testLoadBPData(self):
    #    """Should return a numpy array"""
    #    self.assertIs(type(ncio.load_bp_data(self.options, self.timedata)), np.ndarray)

    def testGetAllData(self):
        """Should return two numpy arrays"""
        data, lats = ncio.get_all_data(self.options.tmaxfile,
                                       self.options.tmaxvname, self.options)
Exemplo n.º 2
0
 def testOnlyTmin(self):
     """Should work with only tmin or only tmax."""
     args = [
         '-n', 'tests/climpact2.sampledata.gridded.1991-2010.nc',
         '--base=1960-2010'
     ]
     self.assertIs(type(getoptions.parse_arguments(args)), optparse.Values)
Exemplo n.º 3
0
 def testConstructsOptions(self):
     """The parse_arguments function should return an options object"""
     self.assertIs(type(getoptions.parse_arguments(self.args)),
                   optparse.Values)
Exemplo n.º 4
0
        HWD = HWD_n
        HWT = HWT_n
    elif south:
        HWA = HWA_s
        HWM = HWM_s
        HWN = HWN_s
        HWF = HWF_s
        HWD = HWD_s
        HWT = HWT_s
    return HWA, HWM, HWN, HWF, HWD, HWT


if __name__ == '__main__':

    # Get the options and variables
    options = getoptions.parse_arguments(sys.argv[1:])

    # Load time data
    if options.verbose: print("Loading data")
    timedata = ncio.get_time_data(options)

    # Load land-sea mask
    if options.maskfile: mask = ncio.get_mask(options)
    else: mask = None

    # Load the temperature data over the base period
    if options.keeptave or options.keeptmax:
        tmax = ncio.load_bp_data(options, timedata, variable='tmax', mask=mask)
    if options.keeptave or options.keeptmin:
        tmin = ncio.load_bp_data(options, timedata, variable='tmin', mask=mask)
    if options.keeptave: