def test_profiles_means(): """ Test adding means to pre-collected profiles """ init_logger('reV.handlers.collection') h5_file = os.path.join(TEMP_DIR, 'cf.h5') Collector.collect(h5_file, H5_DIR, POINTS_PATH, 'cf_profile', dset_out=None, file_prefix='peregrine_2012') Collector.add_dataset(h5_file, H5_DIR, 'cf_mean', dset_out=None, file_prefix='peregrine_2012') with h5py.File(h5_file, 'r') as f: assert 'cf_profile' in f assert 'cf_mean' in f data = f['cf_profile'][...] node_file = os.path.join(H5_DIR, 'peregrine_2012_node01_x001.h5') with h5py.File(node_file, 'r') as f: source_data = f['cf_profile'][...] assert np.allclose(source_data, data[:, -1 * source_data.shape[1]:]) if PURGE_OUT: os.remove(h5_file)
def test_means_lcoe(): """ Test adding means to pre-collected profiles """ init_logger('reV.handlers.collection') h5_file = os.path.join(TEMP_DIR, 'cf_lcoe.h5') Collector.collect(h5_file, H5_DIR, POINTS_PATH, 'cf_mean', dset_out=None, file_prefix='peregrine_2012') Collector.add_dataset(h5_file, H5_DIR, 'lcoe_fcr', dset_out=None, file_prefix='peregrine_2012') with h5py.File(h5_file, 'r') as f: assert 'cf_mean' in f assert 'lcoe_fcr' in f if PURGE_OUT: os.remove(h5_file)
def collect(ctx, verbose): """Run collection on local worker.""" name = ctx.obj['NAME'] h5_file = ctx.obj['H5_FILE'] h5_dir = ctx.obj['H5_DIR'] project_points = ctx.obj['PROJECT_POINTS'] dsets = ctx.obj['DSETS'] file_prefix = ctx.obj['FILE_PREFIX'] log_dir = ctx.obj['LOG_DIR'] purge_chunks = ctx.obj['PURGE_CHUNKS'] verbose = any([verbose, ctx.obj['VERBOSE']]) # initialize loggers for multiple modules init_mult(name, log_dir, modules=[__name__, 'reV.handlers.collection'], verbose=verbose, node=True) for key, val in ctx.obj.items(): logger.debug('ctx var passed to collection method: "{}" : "{}" ' 'with type "{}"'.format(key, val, type(val))) logger.info('Collection is being run for "{}" with job name "{}" ' 'and collection dir: {}. Target output path is: {}'.format( dsets, name, h5_dir, h5_file)) t0 = time.time() Collector.collect(h5_file, h5_dir, project_points, dsets[0], file_prefix=file_prefix) if len(dsets) > 1: for dset_name in dsets[1:]: Collector.add_dataset(h5_file, h5_dir, dset_name, file_prefix=file_prefix) if purge_chunks: Collector.purge_chunks(h5_file, h5_dir, project_points, file_prefix=file_prefix) else: Collector.move_chunks(h5_file, h5_dir, project_points, file_prefix=file_prefix) runtime = (time.time() - t0) / 60 logger.info('Collection completed in: {:.2f} min.'.format(runtime)) # add job to reV status file. status = { 'dirout': os.path.dirname(h5_file), 'fout': os.path.basename(h5_file), 'job_status': 'successful', 'runtime': runtime, 'finput': os.path.join(h5_dir, '{}*.h5'.format(file_prefix)) } Status.make_job_file(os.path.dirname(h5_file), 'collect', name, status)