Beispiel #1
0
    def test_refl_mask(self):

        inst = PyPros(self.variables_file, 'ks', self.threshold,
                      self.data_format)

        refl = numpy.ones((3, 3))

        refl_values = [0.2, 2, 6, 12, 16, 26]
        for i in range(3):
            refl[0][i] = refl_values[i]
            refl[1][i] = refl_values[i]
            refl[2][i] = refl_values[i]

        pros_masked = inst.refl_mask(refl)

        # rain
        for i in range(1, 3):
            self.assertEqual(pros_masked[0][i], i)
        # sleet
        for i in range(1, 3):
            self.assertEqual(pros_masked[1][i], 5 + i)
        # snow
        for i in range(1, 3):
            self.assertEqual(pros_masked[2][i], 10 + i)

        inst = PyPros(self.variables_file, 'static_tw', 1.5,
                      self.data_format)
        pros_masked = inst.refl_mask(refl)

        # rain
        for i in range(1, 3):
            self.assertEqual(pros_masked[0][i], i)
        # snow
        for i in range(1, 3):
            self.assertEqual(pros_masked[2][i], 10 + i)

        inst = PyPros(self.variables_file, 'static_ta', 1.0,
                      self.data_format)
        pros_masked = inst.refl_mask(refl)

        # rain
        for i in range(1, 3):
            self.assertEqual(pros_masked[0][i], i)
        # snow
        for i in range(1, 3):
            self.assertEqual(pros_masked[2][i], 10 + i)

        inst = PyPros(self.variables_file, 'linear_tr', [0, 3],
                      self.data_format)
        pros_masked = inst.refl_mask(refl)

        # rain
        for i in range(1, 3):
            self.assertEqual(pros_masked[0][i], i)
        # sleet
        for i in range(1, 3):
            self.assertEqual(pros_masked[1][i], 5 + i)
        # snow
        for i in range(1, 3):
            self.assertEqual(pros_masked[2][i], 10 + i)
Beispiel #2
0
    def test_refl_mask_wrong(self):
        variables_file = ['/tmp/tair.tif', '/tmp/tdew.tif']
        data_format = {'vars_files': ['tair', 'tdew']}

        refl = numpy.ones((1, 1))

        with self.assertRaises(IndexError) as cm:
            inst = PyPros(variables_file, 'single_ta', 1.5, data_format)
            inst.refl_mask(refl)
        self.assertEqual('Variables fields must have the same shape.',
                         str(cm.exception))
Beispiel #3
0
    print('Step 4/9 : Getting dew point temperature data')
    td_data = extract_variable(config['data_file'], config['metadata_file'],
                               date, 'td')
    print('Step 5/9 : Interpolating dew point temperature data')
    td_field = apply_mica(dict_to_file('example_data/emilia_romagna/'
                          'stations/td_data.json', td_data), config)
    td_field.save_file('out/emilia_romagna/td_' + date_str + '.tif')

    print('Step 6/9 : Getting radar field')
    radar_date = datetime.strftime(date, '%Y%m%d%H%M%S')
    radar_files = [config['radar_dir'] + 'itgat_' + radar_date + '.h5',
                   config['radar_dir'] + 'itspc_' + radar_date + '.h5']

    print('Step 7/9 : Creating radar composite')
    radar_composite = create_composite(radar_files, config)

    print('Step 8/9 : Calculating precipitation phase')
    ros = PyPros(['out/emilia_romagna/ta_' + date_str + '.tif',
                  'out/emilia_romagna/td_' + date_str + '.tif'],
                 method='ks',
                 data_format={'vars_files': ['tair', 'tdew', 'dem']})

    print('Step 9/9 : Applying reflectivity mask')
    ros.save_file(ros.refl_mask(radar_composite),
                  'out/emilia_romagna/ros_' + date_str + '.tif')

    plot_ros('out/emilia_romagna/ros_' + date_str + '.tif', date,
             config_plot=config)

    print('OK.')