def ftp_publications(self, cascade=False): """ Return product generator. """ if isinstance(self.datetimes, (list, tuple)): datetimes = self.datetimes else: # Generate datetimes from rangetext string. datetimes = utils.MultiDateRange(self.datetimes).iterdatetimes() combinations = utils.get_product_combinations( datetimes=datetimes, prodcodes=self.prodcodes, timeframes=self.timeframes, ) for combination in combinations: nowcast = combination.pop('nowcast') if nowcast != self.nowcast: continue if nowcast: yield products.CopiedProduct(datetime=combination['datetime']) continue consistent = utils.consistent_product_expected( prodcode=combination['prodcode'], timeframe=combination['timeframe'], ) product = products.CalibratedProduct(**combination) if not consistent: yield product if cascade: rps = products.Consistifier.get_rescaled_products(product) for rescaled_product in rps: yield rescaled_product
def get_path_helper(timeframe, prodcode): """ Return pathhelper for combination. """ consistent = utils.consistent_product_expected(prodcode=prodcode, timeframe=timeframe) basedir = config.CONSISTENT_DIR if consistent else config.CALIBRATE_DIR code = config.PRODUCT_CODE[timeframe][prodcode] template = config.PRODUCT_TEMPLATE return utils.PathHelper(basedir=basedir, code=code, template=template)
def get_path_helper(timeframe, prodcode): """ Return pathhelper for combination. """ consistent = utils.consistent_product_expected(prodcode=prodcode, timeframe=timeframe) basedir = config.CONSISTENT_DIR if consistent else config.CALIBRATE_DIR code = config.PRODUCT_CODE[timeframe][prodcode] template = config.PRODUCT_TEMPLATE return utils.PathHelper(basedir=basedir, code=code, template=template)
def sandbox(**kwargs): """ Print a value from various datafiles. """ i, j = map(int, kwargs['indices'].split(',')) datetimes = utils.MultiDateRange(kwargs['range']).iterdatetimes() combinations = utils.get_product_combinations( datetimes=datetimes, prodcodes=kwargs['prodcodes'], timeframes=kwargs['timeframes'], ) for combination in combinations: # The calibrate calibrate = products.CalibratedProduct(**combination) with calibrate.get() as calibrate_h5: print('Calibrate: {}'.format(calibrate_h5['precipitation'][i, j])) # The rescaled if utils.consistent_product_expected(combination['prodcode'], combination['timeframe']): rescaled = products.ConsistentProduct(**combination) print(rescaled.path) with rescaled.get() as rescaled_h5: print('Rescaled: {}'.format( rescaled_h5['precipitation'][i, j], )) # The thredds thredds = products.ThreddsFile.get_for_product(calibrate) t = thredds._index(calibrate) with thredds.get() as thredds_h5: print('Thredds: {}'.format( thredds_h5['precipitation'][i, j, t], )) # The merged threddsfile thredds_m = products.ThreddsFile.get_for_product(calibrate, merge=True) t = thredds_m._index(calibrate) with thredds_m.get() as thredds_m_h5: print('Thredds(m): {} ({})'.format( thredds_m_h5['precipitation'][i, j, t], thredds_m_h5['available'][t] )) # Opendap values = products.get_values_from_opendap( x=i, y=j, start_date=combination['datetime'], end_date=combination['datetime'], ) print('Opendap: {}'.format(values))
def test_consistent_product_expected(self): data = [ ('r', 'f', False), ('r', 'h', False), ('r', 'd', False), ('n', 'f', True), ('n', 'h', False), ('n', 'd', False), ('a', 'f', True), ('a', 'h', True), ('a', 'd', False), ] for prodcode, timeframe, expected in data: self.assertEqual( utils.consistent_product_expected(prodcode=prodcode, timeframe=timeframe), expected, )
def test_consistent_product_expected(self): data = [ ('r', 'f', False), ('r', 'h', False), ('r', 'd', False), ('n', 'f', True), ('n', 'h', False), ('n', 'd', False), ('a', 'f', True), ('a', 'h', True), ('a', 'd', False), ] for prodcode, timeframe, expected in data: self.assertEqual( utils.consistent_product_expected(prodcode=prodcode, timeframe=timeframe), expected, )
def sandbox(**kwargs): """ Print a value from various datafiles. """ i, j = map(int, kwargs['indices'].split(',')) datetimes = utils.MultiDateRange(kwargs['range']).iterdatetimes() combinations = utils.get_product_combinations( datetimes=datetimes, prodcodes=kwargs['prodcodes'], timeframes=kwargs['timeframes'], ) for combination in combinations: # The calibrate calibrate = products.CalibratedProduct(**combination) with calibrate.get() as calibrate_h5: print('Calibrate: {}'.format(calibrate_h5['precipitation'][i, j])) # The rescaled if utils.consistent_product_expected(combination['prodcode'], combination['timeframe']): rescaled = products.ConsistentProduct(**combination) print(rescaled.path) with rescaled.get() as rescaled_h5: print('Rescaled: {}'.format(rescaled_h5['precipitation'][i, j], )) # The thredds thredds = products.ThreddsFile.get_for_product(calibrate) t = thredds._index(calibrate) with thredds.get() as thredds_h5: print('Thredds: {}'.format(thredds_h5['precipitation'][i, j, t], )) # The merged threddsfile thredds_m = products.ThreddsFile.get_for_product(calibrate, merge=True) t = thredds_m._index(calibrate) with thredds_m.get() as thredds_m_h5: print('Thredds(m): {} ({})'.format( thredds_m_h5['precipitation'][i, j, t], thredds_m_h5['available'][t])) # Opendap values = products.get_values_from_opendap( x=i, y=j, start_date=combination['datetime'], end_date=combination['datetime'], ) print('Opendap: {}'.format(values))