Skip to content

Commit 57427dc

Browse files
committed
simplify the copying results files around and adding results_suffix to them.
1 parent ddbcbae commit 57427dc

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

src/natcap/invest/recreation/recmodel_client.py

+8-31
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,7 @@ def execute(args):
554554
func=_retrieve_user_days,
555555
args=(file_registry['local_aoi_path'],
556556
file_registry['compressed_aoi_path'],
557-
args['start_year'], args['end_year'],
558-
os.path.basename(file_registry['pud_results_path']),
559-
os.path.basename(file_registry['tud_results_path']),
560-
os.path.basename(file_registry['pud_monthly_table_path']),
561-
os.path.basename(file_registry['tud_monthly_table_path']),
557+
args['start_year'], args['end_year'],file_suffix,
562558
output_dir, server_url, file_registry['server_version']),
563559
target_path_list=[file_registry['compressed_aoi_path'],
564560
file_registry['pud_results_path'],
@@ -650,9 +646,7 @@ def _copy_aoi_no_grid(source_aoi_path, dest_aoi_path):
650646

651647
def _retrieve_user_days(
652648
local_aoi_path, compressed_aoi_path, start_year, end_year,
653-
pud_results_filename, tud_results_filename,
654-
pud_monthly_table_filename, tud_monthly_table_filename,
655-
output_dir, server_url, server_version_pickle):
649+
file_suffix, output_dir, server_url, server_version_pickle):
656650
"""Calculate photo-user-days (PUD) on the server and send back results.
657651
658652
All of the client-server communication happens in this scope. The local AOI
@@ -664,10 +658,7 @@ def _retrieve_user_days(
664658
compressed_aoi_path (string): path to zip file storing compressed AOI
665659
start_year (int/string): lower limit of date-range for PUD queries
666660
end_year (int/string): upper limit of date-range for PUD queries
667-
pud_results_filename (string): filename for a vector with PUD results
668-
tud_results_filename (string): filename for a vector with TUD results
669-
pud_monthly_table_filename (string): filename for monthly PUD results CSV
670-
tud_monthly_table_filename (string): filename for monthly TUD results CSV
661+
file_suffix (string): to append to filenames of files created by server
671662
output_dir (string): path to output workspace where results are
672663
unpacked.
673664
server_url (string): URL for connecting to the server
@@ -761,27 +752,13 @@ def _retrieve_user_days(
761752
temporary_output_dir)
762753

763754
for filename in os.listdir(temporary_output_dir):
764-
shutil.copy(os.path.join(temporary_output_dir, filename), output_dir)
755+
# Results are returned from the server without a results_suffix.
756+
pre, post = os.path.splitext(filename)
757+
shutil.copy(
758+
os.path.join(temporary_output_dir, filename),
759+
os.path.join(output_dir, f'{pre}{file_suffix}{post}'))
765760
shutil.rmtree(temporary_output_dir)
766761

767-
# Results are returned from the server without a results_suffix.
768-
if dataset == 'flickr':
769-
renamed_table = pud_monthly_table_filename
770-
renamed_vector = pud_results_filename
771-
else:
772-
renamed_table = tud_monthly_table_filename
773-
renamed_vector = tud_results_filename
774-
shutil.move(
775-
os.path.join(output_dir, f'{acronym_lookup[dataset]}_monthly_table.csv'),
776-
os.path.join(output_dir, renamed_table))
777-
driver = gdal.GetDriverByName('ESRI Shapefile')
778-
source_path = os.path.join(
779-
output_dir, f'{acronym_lookup[dataset]}_results.shp')
780-
source = gdal.OpenEx(source_path, gdal.OF_VECTOR)
781-
driver.CreateCopy(
782-
os.path.join(output_dir, renamed_vector), source)
783-
driver.Delete(source_path)
784-
785762
LOGGER.info('connection release')
786763
recmodel_manager._pyroRelease()
787764

0 commit comments

Comments
 (0)