Skip to content

Commit 841ce38

Browse files
Solve issue with experiment download destination paths prints
1 parent f637ff1 commit 841ce38

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

providentia/download.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,13 @@ def run(self, **kwargs):
127127
setattr(self, k, self.provconf.parse_parameter(k, val))
128128

129129
# now all variables have been parsed, check validity of those, throwing errors where necessary
130-
self.provconf.check_validity(deactivate_warning=True)
130+
self.provconf.check_validity()
131131

132132
# from here generate control if user stopped execution
133133
signal.signal(signal.SIGINT, self.sighandler)
134134

135135
# only the local download iterates through the networks
136136
if self.machine in "local":
137-
# if networks is none and is not the non interpolated mode, raise error
138-
if not self.network and self.interpolated is True:
139-
error = "Error: No networks were passed."
140-
self.logger.error(error)
141-
sys.exit(1)
142137

143138
# networks
144139
if self.network:
@@ -799,17 +794,19 @@ def download_experiment(self, experiment, initial_check, files_to_download=None)
799794

800795
# get all the nc files in the date range
801796
for remote_dir in res_spec_dir:
802-
if not initial_check:
803-
local_path = remote_dir.split('/',7)[-1]
804-
if self.ghost_version in ["1.2", "1.3", "1.3.1"]:
805-
self.logger.info(f"\n - {join(self.exp_root,self.ghost_version,'-'.join(local_path.split('/')[1:4]),*local_path.split('/')[4:])}, source: {remote_dir} ({REMOTE_MACHINE})")
806-
else:
807-
self.logger.info(f"\n - {join(self.exp_root,local_path)}, source: {remote_dir} ({REMOTE_MACHINE})")
808-
797+
798+
# get network, species and resolution
809799
network = remote_dir.split('/')[-1]
810800
species = remote_dir.split('/')[-2]
811801
resolution = remote_dir.split('/')[-3]
812-
802+
803+
# get local directory
804+
local_dir = join(self.exp_root,self.ghost_version,experiment_new,resolution,species,network)
805+
806+
# print source and destination
807+
if not initial_check:
808+
self.logger.info(f"\n - {local_dir}, source: {remote_dir} ({REMOTE_MACHINE})")
809+
813810
# get nc files if directory is found
814811
try:
815812
nc_files = self.sftp.listdir(remote_dir)
@@ -829,8 +826,6 @@ def download_experiment(self, experiment, initial_check, files_to_download=None)
829826

830827
# download the valid resolution specie date combinations
831828
else:
832-
# create local directory (always with experiments on the new format)
833-
local_dir = join(self.exp_root,self.ghost_version,experiment_new,resolution,species,network)
834829

835830
# create directories if they don't exist
836831
if not os.path.exists(local_dir):
@@ -1024,9 +1019,6 @@ def download_non_interpolated_experiment(self, experiment, initial_check, files_
10241019

10251020
# get all the nc files in the date range
10261021
for remote_dir in res_spec_dir:
1027-
if not initial_check:
1028-
local_path = remote_dir.split('/', 6)[-1]
1029-
self.logger.info(f"\n - {join(self.exp_to_interp_root,local_path)}, source: {remote_dir} ({REMOTE_MACHINE})")
10301022

10311023
# get nc files
10321024
nc_files = self.sftp.listdir(remote_dir)
@@ -1063,8 +1055,8 @@ def download_non_interpolated_experiment(self, experiment, initial_check, files_
10631055
elif format == (0, 3):
10641056
nc_files = list(filter(lambda x:x.split("_")[0] == species, nc_files))
10651057

1058+
# unknown format
10661059
else:
1067-
# TODO delete this in the future
10681060
error = f"It is not possible to download this nc file type yet. Please, contact the developers. Files to download: {nc_files}"
10691061
self.logger.error(error)
10701062
sys.exit(1)
@@ -1078,6 +1070,16 @@ def download_non_interpolated_experiment(self, experiment, initial_check, files_
10781070
# filter the nc files to only get the ones that have the correct species and stats
10791071
nc_files = list(filter(lambda x:x.split("_")[0] == species and "_".join(x[:-3].split("_")[2:]) == ensemble, nc_files))
10801072

1073+
# add ensemble-stats directory if it is an ensemble member
1074+
if ensemble.isdigit() or ensemble in ['allmembers', 'av_an']:
1075+
local_dir = join(self.exp_to_interp_root,exp_id,domain,resolution,species)
1076+
else:
1077+
local_dir = join(self.exp_to_interp_root,exp_id,domain,resolution,"ensemble-stats",species+"_"+ensemble)
1078+
1079+
# print source and destination
1080+
if not initial_check:
1081+
self.logger.info(f"\n - {local_dir}, source: {remote_dir} ({REMOTE_MACHINE})")
1082+
10811083
# if there is no options with the ensemble, tell the user
10821084
if nc_files == []:
10831085
msg = f"There is no data available in {REMOTE_MACHINE} for the {exp_id} experiment with the {domain} domain with the {ensemble} ensemble."
@@ -1095,12 +1097,6 @@ def download_non_interpolated_experiment(self, experiment, initial_check, files_
10951097

10961098
# download the valid resolution specie date combinations
10971099
else:
1098-
# create local directory
1099-
# if it is an ensemble member
1100-
if ensemble.isdigit() or ensemble in ['allmembers', 'av_an']:
1101-
local_dir = join(self.exp_to_interp_root,exp_id,domain,resolution,species)
1102-
else:
1103-
local_dir = join(self.exp_to_interp_root,exp_id,domain,resolution,"ensemble-stats",species+"_"+ensemble)
11041100

11051101
# create directories if they don't exist
11061102
if not os.path.exists(local_dir):

0 commit comments

Comments
 (0)