for task in task_list: execute_entity_task(task, gdirs) if RUN_CLIMATE_PREPRO: for gdir in gdirs: gdir.inversion_calving_rate = 0 execute_entity_task(tasks.process_cru_data, gdirs) execute_entity_task(tasks.local_t_star, gdirs) execute_entity_task(tasks.mu_star_calibration, gdirs) if RUN_INVERSION: # Inversion tasks execute_entity_task(tasks.prepare_for_inversion, gdirs, add_debug_var=True) execute_entity_task(tasks.mass_conservation_inversion, gdirs, filesuffix='_without_calving_') # Log m, s = divmod(time.time() - start, 60) h, m = divmod(m, 60) log.info("OGGM no_calving is done! Time needed: %02d:%02d:%02d" % (h, m, s)) suf = 'config_10_' # Compute calving per k factor for gdir in gdirs: forwrite = [] # Find a calving flux. inversion.find_inversion_calving(gdir)
if RUN_INVERSION: # Inversion tasks execute_entity_task(tasks.prepare_for_inversion, gdirs, add_debug_var=True) execute_entity_task(tasks.mass_conservation_inversion, gdirs) # Log m, s = divmod(time.time() - start, 60) h, m = divmod(m, 60) log.info("OGGM without calving is done! Time needed: %02d:%02d:%02d" % (h, m, s)) suf = '_cfgk_cfgA_cfgFS_with_correction' # Compute a calving flux for gdir in gdirs: forwrite = [] # Find a calving flux. if gdir.rgi_id in dfmac.index: w_depth = dfmac.loc[gdir.rgi_id]['depth'] import math if math.isnan(w_depth): inversion.find_inversion_calving(gdir) else: inversion.find_inversion_calving(gdir, fixed_water_depth= w_depth) else: inversion.find_inversion_calving(gdir) # Compile output utils.compile_glacier_statistics(gdirs, filesuffix='_with_calving_' + suf)
# Read calibration results calibration_results_measures = os.path.join(MAIN_PATH, config['linear_fit_to_data']) path_to_file = os.path.join(calibration_results_measures, 'velocity_fit_calibration_results_measures.csv') dc = pd.read_csv(path_to_file, index_col='RGIId') # Compute a calving flux for gdir in gdirs: sel = dc[dc.index == gdir.rgi_id] k_value = sel.k_for_lw_bound.values cfg.PARAMS['continue_on_error'] = False cfg.PARAMS['k_calving'] = float(k_value) out = inversion.find_inversion_calving(gdir) if out is None: cfg.PARAMS['inversion_fs'] = 0.0 out = inversion.find_inversion_calving(gdir) cfg.PARAMS['inversion_fs'] = 5.7e-20 if out is None: continue # Compile output file_suffix_two = 'calving_k_measures_lowbound' utils.compile_glacier_statistics(gdirs, filesuffix=file_suffix_two, inversion_only=True)
def single_flowline_glacier_directory_with_calving(rgi_id, reset=False, prepro_border=10, k_calving=2): """Prepare a GlacierDirectory for PyGEM (single flowline to start with) k_calving is free variable! Parameters ---------- rgi_id : str the rgi id of the glacier reset : bool set to true to delete any pre-existing files. If false (the default), the directory won't be re-downloaded if already available locally in order to spare time. prepro_border : int the size of the glacier map: 10, 80, 160, 250 Returns ------- a GlacierDirectory object """ assert 1 == 0, 'UPDATE LATEST GLACIER DIRECTORY OPTIONS FROM NON-CALVING' if type(rgi_id) != str: raise ValueError('We expect rgi_id to be a string') if rgi_id.startswith('RGI60-') == False: rgi_id = 'RGI60-' + rgi_id.split('.')[0].zfill(2) + '.' + rgi_id.split( '.')[1] else: raise ValueError('Check RGIId is correct') cfg.initialize() wd = '/Users/davidrounce/Documents/Dave_Rounce/HiMAT/Output/oggm-pygem-{}-b{}-k{}'.format( rgi_id, prepro_border, k_calving) cfg.PATHS['working_dir'] = wd cfg.PARAMS['use_multiple_flowlines'] = False cfg.PARAMS['use_multiprocessing'] = False # Check if folder is already processed try: gdir = utils.GlacierDirectory(rgi_id) gdir.read_pickle('model_flowlines') # If the above works the directory is already processed, return return gdir except: pass # If not ready, we download the preprocessed data for this glacier gdirs = workflow.init_glacier_regions([rgi_id], from_prepro_level=2, prepro_border=prepro_border) if not gdirs[0].is_tidewater: raise ValueError('This glacier is not tidewater!') # Compute all the stuff list_tasks = [ tasks.glacier_masks, tasks.compute_centerlines, tasks.initialize_flowlines, tasks.compute_downstream_line, tasks.compute_downstream_bedshape, tasks.catchment_area, tasks.catchment_intersections, # added 10/20/2020 tasks.catchment_width_geom, tasks.catchment_width_correction, # Consensus ice thickness icethickness.consensus_gridded, icethickness.consensus_binned, # Mass balance data # mbdata.mb_bins_to_glacierwide mbdata.mb_df_to_gdir ] # Debris tasks if pygem_prms.include_debris: list_tasks.append(debris.debris_to_gdir) list_tasks.append(debris.debris_binned) for task in list_tasks: # The order matters! workflow.execute_entity_task(task, gdirs) # Calving according to Recinos et al. 2019 # solves equality between ice derformation and Oerleman's calving law # reduces temperature sensitivity from oggm.core.inversion import find_inversion_calving cfg.PARAMS['k_calving'] = k_calving df = find_inversion_calving(gdirs[0]) print('Calving results:') print('k calving:', k_calving) for k, v in df.items(): print(k + ':', v) list_tasks = [ # THIS WILL NOW FAIL BECAUSE OF USING HUSS tasks.init_present_time_glacier, ] for task in list_tasks: # The order matters! workflow.execute_entity_task(task, gdirs) return gdirs[0]