def main(cl_param): read_input.read_input_cre(cl_param[0]) #print(aux.CLOUD_LAYERS) #print(aux.ATMOSPHERIC_GRID[1]) #exit(-1) aux.TIME_INDEX = cl_param[-1] #inp.RESOLUTION = 1.0 #with open() ''' Create all the necessary folders ''' if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) if not os.path.exists("{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1])): os.mkdir("{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1])) inp.PATH = "{}/{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1], aux.TIME_INDEX) if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) inp.FORWARD = True wn_low = np.float64(cl_param[-3]) wn_high = np.float64(cl_param[-2]) #inp.MCP = np.array([np.float64(cl_param[ii]) for ii in range(1, 5)]) inp.WINDOWS = [0] aux.MICROWINDOWS = [[wn_low, wn_high]] print(aux.MICROWINDOWS) ''' Get clear sky and cloudy sky radiances ''' [wavenumber_clear, radiance_clear] = inversion.__set_up_retrieval() [rms, wavenumber_cloudy, radiance_cloudy] = inversion.retrieve() cre = pd.DataFrame({'wavenumber_clear' : wavenumber_clear, \ 'radiance_clear': radiance_clear, \ 'wavenumber_cloudy': wavenumber_cloudy, \ 'radiance_cloudy': radiance_cloudy}) outfile = "{}/results_cre_{}_{}.csv".format(inp.PATH, wn_low, wn_high) while not os.path.exists(outfile): with open(outfile, "w") as f: f.write( "wavenumber_clear,radiance_clear,wavenumber_cloudy,radiance_cloudy\n" ) for ii in range(len(cre)): f.write("{},{},{},{}\n".format(cre['wavenumber_clear'].iloc[ii], \ cre['radiance_clear'].iloc[ii], \ cre['wavenumber_cloudy'].iloc[ii], \ cre['radiance_cloudy'].iloc[ii])) return
def main(cl_param): read_input.read_input_cre(cl_param[0]) #print(aux.CLOUD_LAYERS) #print(aux.ATMOSPHERIC_GRID[1]) #exit(-1) aux.TIME_INDEX = cl_param[-1] #inp.RESOLUTION = 1.0 #with open() ''' Create all the necessary folders ''' if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) if not os.path.exists("{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1])): os.mkdir("{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1])) inp.PATH = "{}/{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1], aux.TIME_INDEX) if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) inp.FORWARD = True wn_low = np.float64(cl_param[-3]) wn_high = np.float64(cl_param[-2]) #inp.MCP = np.array([np.float64(cl_param[ii]) for ii in range(1, 5)]) inp.WINDOWS = [0] aux.MICROWINDOWS = [[wn_low, wn_high]] print(aux.MICROWINDOWS) ''' Get clear sky and cloudy sky radiances ''' inversion.__set_up_retrieval() inversion.retrieve() return
def main(spectral_radiance_file, \ atmospheric_profiles, \ cloud_height_file, \ date_of_spec=None, sza=-1): ''' Entrance function for the retrieval. Read microwindows, creates directories, calls the retrieval loop and calls save function Parameters ---------- spectral_radiance_file: str Name of a netCDF4-file containing spectral radiances. atmospheric_profiles: str Path to directory containing atmospheric profiles (inp.FORMAT == "NC") or name of a netCDF4-file containing ERA5 profiles (inp.FORMAT == "OPUS") cloud_height_file: str Name of a netCDF4-file (inp.FORMAT == "NC") or ASCII-file (inp.FORMAT=="OPUS") containing informations of the cloud position date_of_spec: dt.datetime Date of spectrum. Only used if inp.FORMAT == "NC" sza: float Solar Zenith Angle of measurement in degrees. Only used if inp.FORMAT == "OPUS" ''' # Store initial MCP in a local variable. This prevents overwriting in case of multiple runs # in one call of TCWret (if more than one spectrum is in spectral_radiance_file) mcp = inp.MCP with open(inp.WINDOWS, "r") as file_: m_window = file_.readlines() physics.MICROWINDOWS = [[] for ii in range(int(m_window[0]))] for line in range(1, len(physics.MICROWINDOWS) + 1): physics.MICROWINDOWS[line-1] = [float(m_window[line].split(" ")[0]), \ float(m_window[line].split(" ")[1])] # Load spectrum, atmospheric profile and cloud information try: tcwret_io.read_radiances(spectral_radiance_file, date_of_spec, sza) tcwret_io.create_atmosphere(atmospheric_profiles) tcwret_io.read_cloud_position(cloud_height_file) except IndexError: print("Fatal. Loading input failed") return directory = dt.datetime.strftime(dt.datetime.now(), "%m_%d_%H_%M_%S_%f") path = inp.PATH[:] # Create all the necessary folders ftir = spectral_radiance_file.split("/")[-1].split(".nc")[0] if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) if not os.path.exists("{}/{}".format(inp.PATH, ftir)): os.mkdir("{}/{}".format(inp.PATH, ftir)) inp.PATH = "{}/{}/{}".format(inp.PATH, ftir, directory) if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) inversion.set_up_retrieval() try: # Run retrieval loop and save results success = inversion.retrieve() tcwret_io.create_nc(num_iter=success[0], \ avk_matrix=success[1], \ errors=success[2], \ covariance_matrix=success[3], \ transfer_matrix=success[4]) except FileNotFoundError: print("FileNotFoundError: {}".format(tcwret_io.DATETIME)) except MemoryError: #IndexError: print("IndexError: {}".format(tcwret_io.DATETIME)) finally: # Delete lblrtm output and restore path and mcp os.system("rm -rf {}/.lblrtm*".format(inp.PATH)) inp.PATH = path inp.MCP = mcp return
def main(cl_param): read_input.read_input(cl_param[0])#, cl_param[1], cl_param[2]) if cl_param[1] == "TIR": inp.WINDOWS = inp.TIR elif cl_param[1] == "FIR": inp.WINDOWS = inp.FIR_TIR elif cl_param[1] == "FIRo": inp.WINDOWS = inp.FIR elif cl_param[1] == "FIRs": inp.WINDOWS = inp.FIR_MCP elif cl_param[1] == "NIR": inp.WINDOWS = inp.NIR NOW = dt.datetime.now() directory = "{}_{}_{}_{}_{}_{}".format(NOW.month, NOW.day, \ NOW.hour, NOW.minute, NOW.second, NOW.microsecond) aux.TIME_INDEX = directory inp.MCP_APRIORI = inp.MCP[:] aux.MICROWINDOWS.append([aux.MICROWINDOWS[inp.WINDOWS[0]][0], \ aux.MICROWINDOWS[inp.WINDOWS[-1]][-1]]) if inp.FORWARD: inp.WINDOWS = [0] #aux.MICROWINDOWS = [[770., 1200.]] aux.MICROWINDOWS = [inp.FWD_WINDOWS] ''' Create all the necessary folders ''' if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) if not os.path.exists("{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1])): os.mkdir("{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1])) inp.PATH = "{}/{}/{}".format(inp.PATH, aux.FTIR.split("/")[-1], aux.TIME_INDEX) if not os.path.exists("{}".format(inp.PATH)): os.mkdir("{}".format(inp.PATH)) aux.SLOPE_RETR = False inversion.__set_up_retrieval() if not inp.FORWARD: ''' Start the iteration using the chosen microwindows ''' inp.FORWARD = True apr_list = [] counter = 0 fi = 0.5 rl = inp.MCP[2] ri = inp.MCP[3] for tt in [0.05, 0.1, 0.2, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0]: apr_list.append(th.Thread(target=guess_apr.guess_apr, args=(tt, fi, rl, ri, ))) apr_list[-1].start() counter = counter + 1 if (counter)%inp.NUM_OF_CPU == 0: for element in apr_list: element.join() apr_list = [] counter = 0 for element in apr_list: element.join() inp.FORWARD = False idx = guess_apr.SEARCH_APR_RMS.index(min(guess_apr.SEARCH_APR_RMS)) inp.MCP[0] = guess_apr.SEARCH_APR_MCP[idx][0] inp.MCP[1] = guess_apr.SEARCH_APR_MCP[idx][1] ''' guess_apr.SEARCH_APR_MCP = [] guess_apr.SEARCH_APR_MCP = [] inp.FORWARD = True apr_list = [] counter = 0 tt = inp.MCP[0]+inp.MCP[1] for fi in [0.0, 0.25, 0.5, 0.75, 1.0]: for rl in [5.0, 10.0, 15.0]: for ri in [20.0, 30., 40.]: apr_list.append(th.Thread(target=guess_apr.guess_apr, args=(tt, fi, rl, ri, ))) apr_list[-1].start() counter = counter + 1 if (counter)%inp.NUM_OF_CPU == 0: for element in apr_list: element.join() apr_list = [] counter = 0 for element in apr_list: element.join() idx = guess_apr.SEARCH_APR_RMS.index(min(guess_apr.SEARCH_APR_RMS)) inp.MCP[0] = guess_apr.SEARCH_APR_MCP[idx][0] inp.MCP[1] = guess_apr.SEARCH_APR_MCP[idx][1] inp.MCP[2] = guess_apr.SEARCH_APR_MCP[idx][2] inp.MCP[3] = guess_apr.SEARCH_APR_MCP[idx][3] ''' inp.FORWARD = False inp.MCP_APRIORI = inp.MCP[:] inversion.retrieve() else: ''' Calculate the spectral radiance for the entire spectral range ''' inversion.retrieve() return