Commit 54fe7c7a authored by ph290's avatar ph290
Browse files

minor improvements

parent 1b1dba04
"""
import os
import subprocess
import shutil
......@@ -16,12 +17,12 @@ base_directory = '/gpfs/ts0/home/ph290/s2p3_rv2.0/'
num_procs = mp.cpu_count() # this will use all available processors. Note that on a multi-node machine it can only use the processors on one node
# num_procs = 1
output_directory = '/gpfs/ts0/projects/Research_Project-148395/s2p3_rv2.0/output/' #where you want the output to go
output_file_name = 'global_tropics'
output_file_name = 'sw_uk_lw_res'
meterological_file_name = 'meterological_data'
domain_file_name = 's12_m2_s2_n2_h_map_global.dat'
domain_file_name = 's12_m2_s2_n2_h_map.dat'
nutrient_file_name = 'initial_nitrate.dat'
executable_file_name = 's2p3_rv2.0'
met_data_location = '/gpfs/ts0/projects/Research_Project-148395/s2p3_rv2.0/met_data_global_tropics/' # The location containing the tar.gz met files (in the format met_data_year.tar.gz)
met_data_location = '/gpfs/ts0/projects/Research_Project-148395/s2p3_rv2.0/test/' # The location containing the tar.gz met files (in the format met_data_year.tar.gz)
met_data_temporary_location = base_directory+'met/spatial_data/' # The location that met data for each year will be un tar.gziped into
start_year = 2006
end_year = 2006 # same as start year resuls in a 1 year run
......@@ -86,18 +87,26 @@ for i,line in enumerate(lines[1::]):
woa_nutrient.append(lines2[i][16:22])
"""
def run_model(domain_file_name,lats_lons,year,start_year,unique_job_id,met_data_temporary_location,lon_domain,lat_domain,smaj1,smin1,smaj2,smin2,smaj3,smin3,smaj4,smin4,smaj5,smin5,woa_nutrient,alldepth,i):
#modifying so that the fortran code looks for the correct met file, rather than us having to copy it into the working dorectory
# lon,lat = return_domain_lon(base_directory+'domain/'+domain_file_name,i)
forcing_lat_lon = closest(lats_lons, float(lat_domain[i]),float(lon_domain[i]))
lon_domain_tmp = float(lon_domain[i])
if lon_domain_tmp < 0.0:
lon_domain_tmp = 360.0+lon_domain_tmp
# forcing_lat_lon = closest(lats_lons, float(lat_domain[i]),float(lon_domain[i]))
print i
# print str(forcing_lat_lon[0])
# print str(forcing_lat_lon[1])
# print str(float(lat_domain[i]))
# print str(lon_domain_tmp)
run_command = """./"""+executable_file_name+""" << EOF
"""+str(start_year)+"""
"""+str(year)+"""
"""+str(forcing_lat_lon[0])+"""
"""+str(forcing_lat_lon[1])+"""
"""+str(float(lat_domain[i]))+"""
"""+str(lon_domain_tmp)+"""
../domain/"""+domain_file_name+"""
../domain/"""+nutrient_file_name+"""
"""+unique_job_id+"""
......@@ -118,8 +127,8 @@ map
"""+str(alldepth[i])+"""
"""+str(start_year)+"""
"""+str(year)+"""
"""+str(forcing_lat_lon[0])+"""
"""+str(forcing_lat_lon[1])+"""
"""+str(float(lat_domain[i]))+"""
"""+str(lon_domain_tmp)+"""
../domain/"""+domain_file_name+"""
../domain/"""+nutrient_file_name+"""
"""+unique_job_id+"""
......@@ -167,7 +176,15 @@ for i,file in enumerate(files):
lats_lons[i][1] = float(tmp[1].split('_')[0])
year=2006
pool = mp.Pool(processes=num_procs)
func = partial(run_model, domain_file_name, lats_lons, year, start_year, unique_job_id, met_data_temporary_location,lon_domain,lat_domain,smaj1,smin1,smaj2,smin2,smaj3,smin3,smaj4,smin4,smaj5,smin5,woa_nutrient,alldepth)
results, errors = zip(*pool.map(func, range(1)))
print results[0].split('\n')[0]
print errors[0].split('\n')[0]
pool.close()
"""
for year in range(start_year,end_year+1):
#clean up and prexisting met files
......@@ -185,6 +202,7 @@ for year in range(start_year,end_year+1):
func = partial(run_model, domain_file_name, lats_lons, year, start_year, unique_job_id, met_data_temporary_location,lon_domain,lat_domain,smaj1,smin1,smaj2,smin2,smaj3,smin3,smaj4,smin4,smaj5,smin5,woa_nutrient,alldepth)
# results,errors = pool.map(func, range(num_lines))
results, errors = zip(*pool.map(func, range(len(lat_domain))))
# results = pool.map(func, range(num_lines))
with open(output_directory+output_file_name+'_'+str(year),'w') as fout:
for result in results:
......@@ -218,3 +236,5 @@ for remove_file in remove_files:
# with open(output_directory+output_file_name+'_'+str(year)+'_error','w') as fout:
# for result in results:
# fout.write(result)
"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment