def generateCdf(self, save=False): """ Generate the CDFs corresponding to PDFs of cyclone origins, then save it on a file path provided by user :param boolean save: If ``True``, save the CDF to a netcdf file called 'originCDF.nc'. If ``False``, return the CDF. """ self.cz = stats.cdf2d(self.x, self.y, self.pdf) if save: self.logger.debug("Saving origin CDF to file") grdSave(self.processPath+'originCDF.txt', self.cz, self.x, self.y, self.kdeStep) if save: outputFile = os.path.join(self.processPath, 'originCDF.nc') dimensions = { 0: { 'name': 'lat', 'values': self.y, 'dtype': 'f', 'atts': { 'long_name': 'Latitude', 'units': 'degrees_north' } }, 1: { 'name': 'lon', 'values': self.x, 'dtype': 'f', 'atts': { 'long_name': 'Longitude', 'units':'degrees_east' } } } variables = { 0: { 'name': 'gcdf', 'dims': ('lat','lon'), 'values': numpy.array(self.cz), 'dtype': 'f', 'atts': { 'long_name': ('TC Genesis cumulative ' 'distribution'), 'units': '' } } } ncSaveGrid(outputFile, dimensions, variables) else: return self.cz
def test_cdf2d(self): """Testing cdf2d""" pdf = array([[0.07383899, 0.66509486, 0.21795259, 0.349258], [0.72284544, 0.56474223, 0.16157475, 0.71899118], [0.73459315, 0.29610227, 0.94534262, 0.4801483], [0.58482537, 0.25089279, 0.40459775, 0.65046793]]) cdf = array([[0.0094408, 0.0944775, 0.12234415, 0.16699906], [0.10186128, 0.25910395, 0.30762902, 0.44421163], [0.19578378, 0.39088508, 0.5602783, 0.75825101], [0.27055752, 0.49773705, 0.71886075, 1.0]]) x = array([0, 1, 2, 3]) y = array([0, 1, 2, 3]) self.numpyAssertAlmostEqual(statutils.cdf2d(x, y, pdf), cdf)
def test_cdf2d(self): """Testing cdf2d""" pdf = array([[0.07383899, 0.66509486, 0.21795259, 0.349258], [0.72284544, 0.56474223, 0.16157475, 0.71899118], [0.73459315, 0.29610227, 0.94534262, 0.4801483 ], [0.58482537, 0.25089279, 0.40459775, 0.65046793]]) cdf = array([[0.0094408, 0.0944775, 0.12234415, 0.16699906], [0.10186128, 0.25910395, 0.30762902, 0.44421163], [0.19578378, 0.39088508, 0.5602783 , 0.75825101], [0.27055752, 0.49773705, 0.71886075, 1.0]]) x = array([0, 1, 2, 3]) y = array([0, 1, 2, 3]) self.numpyAssertAlmostEqual(statutils.cdf2d(x, y, pdf), cdf)