def test_lons(self): self.assertEqual(qc.mds_lon_to_xindex(-180.0), 0) self.assertEqual(qc.mds_lon_to_xindex(-179.0), 0) self.assertEqual(qc.mds_lon_to_xindex(-178.0), 1) self.assertEqual(qc.mds_lon_to_xindex(180.0), 359) self.assertEqual(qc.mds_lon_to_xindex(179.0), 359) self.assertEqual(qc.mds_lon_to_xindex(178.0), 358) self.assertEqual(qc.mds_lon_to_xindex(-1.0), 178) self.assertEqual(qc.mds_lon_to_xindex(0.0), 179) self.assertEqual(qc.mds_lon_to_xindex(1.0), 181)
def get_value_ostia(self, lat, lon): """ :param lat: latitude of location to extract value from in degrees of arc :param lon: longitude of location to extract value from in degrees of arc :return: SST at that location or None :type lat: float :type lon: float :rtype: float """ yindex = qc.mds_lat_to_yindex(lat, res=0.05) xindex = qc.mds_lon_to_xindex(lon, res=0.05) tindex = 0 result = self.field[tindex, yindex, xindex] if type(result) is np.float64 or type(result) is np.float32: pass else: if result.mask: result = None else: result = result.data[0] return result
def test_lons_with_res(self): self.assertEqual(qc.mds_lon_to_xindex(-180.0, 5.0), 0) self.assertEqual(qc.mds_lon_to_xindex(-178.0, 5.0), 0) self.assertEqual(qc.mds_lon_to_xindex(-175.0, 5.0), 0) self.assertEqual(qc.mds_lon_to_xindex(175.0, 5.0), 71) self.assertEqual(qc.mds_lon_to_xindex(178.4, 5.0), 71) self.assertEqual(qc.mds_lon_to_xindex(180.0, 5.0), 71) self.assertEqual(qc.mds_lon_to_xindex(0.0, 5.0), 35)
def get_value_ostia(self, lat, lon): yindex = qc.mds_lat_to_yindex(lat, res=0.05) xindex = qc.mds_lon_to_xindex(lon, res=0.05) tindex = 0 result = self.field[tindex, yindex, xindex] if type(result) is np.float64 or type(result) is np.float32: pass else: if result.mask: result = None else: result = result.data[0] return result
def get_value_mds_style(self, lat, lon, month, day): ''' Get the value from the climatology at the give position and time using the MDS method for deciding which grid cell borderline cases fall into :param lat: latitude of location to extract value from in degrees :param lon: longitude of location to extract value from in degrees :param month: month for which the value is required :param day: day for which the value is required :type lat: float :type lon: float :type month: integer :type day: integer :return: climatology value at specified location and time. :rtype: float ''' if month < 1 or month > 12: return None ml = qc.month_lengths(2004) if day < 1 or day > ml[month - 1]: return None yindex = qc.mds_lat_to_yindex(lat) xindex = qc.mds_lon_to_xindex(lon) tindex = self.get_tindex(month, day) result = self.field[tindex, yindex, xindex] if type(result) is np.float64 or type(result) is np.float32: pass else: if result.mask: result = None else: result = result.data[0] return result