예제 #1
0
    def test_only_lat_lon(self):
        """
        Test creating sites at runtime. Here only latitude and longitude are
        provided.

        """
        for site in self.site_data:
            site.pop('gmtoffset')
            site.pop('wmo_id')
            site.pop('altitude')

        result = Plugin(self.method).process(self.site_data)
        expected_altitudes = [np.nan] * 5
        expected_utc_offsets = [-4, -5, -1, 1, 10]
        # unset, so none can be flagged as wmo_sites
        expected_wmo_sites = np.zeros(len(result))

        self.assertArrayEqual(
            self.latitudes,
            np.array([result[index]['latitude'] for index in result]))
        self.assertArrayEqual(
            self.longitudes,
            np.array([result[index]['longitude'] for index in result]))
        self.assertArrayEqual(
            expected_altitudes,
            np.array([result[index]['altitude'] for index in result]))
        self.assertArrayEqual(
            expected_utc_offsets,
            np.array([result[index]['utc_offset'] for index in result]))
        self.assertArrayEqual(
            expected_wmo_sites,
            np.array([result[index]['wmo_site'] for index in result]))
예제 #2
0
    def test_complete(self):
        """
        Test creating sites at runtime. Here latitude, longitude, and altitude
        are provided.

        """
        # These are not currently a CLI option, so remove them.
        for site in self.site_data:
            site.pop('gmtoffset')
            site.pop('wmo_id')

        result = Plugin(self.method).process(site_properties=self.site_data)
        # set from longitude.
        expected_utc_offsets = [-4, -5, -1, 1, 10]
        # unset, so none can be flagged as wmo_sites
        expected_wmo_sites = np.zeros(len(result))

        self.assertArrayEqual(
            self.latitudes,
            np.array([result[index]['latitude'] for index in result]))
        self.assertArrayEqual(
            self.longitudes,
            np.array([result[index]['longitude'] for index in result]))
        self.assertArrayEqual(
            self.altitudes,
            np.array([result[index]['altitude'] for index in result]))
        self.assertArrayEqual(
            expected_wmo_sites,
            np.array([result[index]['wmo_site'] for index in result]))
        self.assertArrayEqual(
            expected_utc_offsets,
            np.array([result[index]['utc_offset'] for index in result]))
예제 #3
0
    def test_unequal_lat_lon(self):
        """
        Test loading a valid json file containing site details,
        but missing compulsary longitude data for some sites.

        """
        self.site_data[0].pop('longitude')
        self.save_json(self.site_data)
        msg = 'Unequal no. of latitudes (.*) and longitudes'
        with self.assertRaisesRegexp(ValueError, msg):
            Plugin(self.method).process(self.site_path)
예제 #4
0
    def test_no_longitude(self):
        """
        Test loading a valid json file containing site details,
        but missing compulsary longitude data.

        """
        for site in self.site_data:
            site.pop('longitude')
        self.save_json(self.site_data)

        msg = 'longitude and latitude must be defined'
        with self.assertRaisesRegexp(KeyError, msg):
            Plugin(self.method).process(self.site_path)
예제 #5
0
    def test_complete(self):
        """
        Test loading a valid json file containing site details.
        File formatted to represent current BestData input.

        """
        expected = self.site_data
        self.save_json(self.site_data)

        self.change_key(expected, 'gmtoffset', 'utc_offset')
        result = Plugin(self.method).process(self.site_path)

        for key in self.variables:
            expected_vals = np.array([site[key] for site in expected])
            result_vals = np.array([result[index][key] for index in result])
            self.assertArrayEqual(expected_vals, result_vals)

        # check that wmo sites are correctly flagged.
        self.assertArrayEqual(self.wmo_sites,
                              [result[index]['wmo_site'] for index in result])
예제 #6
0
    def test_only_lat_lon(self):
        """
        Test loading a valid json file containing site details, only containing
        lat/lon. Altitudes set to fill value of np.nan, and utc_offset
        calculated from longitude.

        """
        for site in self.site_data:
            site.pop('wmo_id')
            site.pop('altitude')
            site.pop('gmtoffset')

        self.save_json(self.site_data)
        result = Plugin(self.method).process(self.site_path)
        expected_altitudes = [np.nan] * 5
        expected_utc_offsets = [-4, -5, -1, 1, 10]

        self.assertArrayEqual(
            expected_altitudes,
            np.array([result[index]['altitude'] for index in result]))
        self.assertArrayEqual(
            expected_utc_offsets,
            np.array([result[index]['utc_offset'] for index in result]))