Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@entity_task(log, writes=['gridded_data', 'geometries'])
def glacier_masks(gdir):
"""Makes a gridded mask of the glacier outlines that can be used by OGGM.
For a more robust solution (not OGGM compatible) see simple_glacier_masks.
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
where to write the data
"""
# In case nominal, just raise
if gdir.is_nominal:
raise GeometryError('{} is a nominal glacier.'.format(gdir.rgi_id))
if not os.path.exists(gdir.get_filepath('gridded_data')):
@entity_task(log, writes=['inversion_flowlines'])
def terminus_width_correction(gdir, new_width=None):
"""Sets a new value for the terminus width.
This can be useful for e.g. tiddewater glaciers where we know the width
and don't like the OGGM one.
This task preserves the glacier area but will change the fit of the
altitude-area distribution slightly.
Parameters
----------
gdir : oggm.GlacierDirectory
new_width : float
the new width of the terminus (in meters)
"""
@entity_task(log, writes=['downstream_line'])
def compute_downstream_bedshape(gdir):
"""The bedshape obtained by fitting a parabola to the line's normals.
Also computes the downstream's altitude.
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
where to write the data
"""
# For tidewater glaciers no need for all this
if gdir.is_tidewater:
return
# We make a flowline out of the downstream for simplicity
@entity_task(log, writes=['geometries'])
def catchment_area(gdir):
"""Compute the catchment areas of each tributary line.
The idea is to compute the route of lowest cost for any point on the
glacier to rejoin a centerline. These routes are then put together if
they belong to the same centerline, thus creating "catchment areas" for
each centerline.
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
where to write the data
"""
# Variables
cls = gdir.read_pickle('centerlines')
@entity_task(log, writes=['inversion_flowlines'])
@divide_task(log, add_0=True)
def initialize_flowlines(gdir, div_id=None):
""" Transforms the geometrical Centerlines in the more "physical"
"Inversion Flowlines".
This interpolates the centerlines on a regular spacing (i.e. not the
grid's (i, j) indices. Cuts out the tail of the tributaries to make more
realistic junctions. Also checks for low and negative slopes and corrects
them by interpolation.
Parameters
----------
gdir : oggm.GlacierDirectory
"""
# variables
@entity_task(log, writes=['inversion_output'])
def mass_conservation_inversion(gdir, glen_a=None, fs=None, write=True,
filesuffix=''):
""" Compute the glacier thickness along the flowlines
More or less following Farinotti et al., (2009).
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
the glacier directory to process
glen_a : float
glen's creep parameter A
fs : float
sliding parameter
write: bool
default behavior is to compute the thickness and write the
@entity_task(log, writes=['climate_monthly', 'climate_info'])
def process_cru_data(gdir):
"""Processes and writes the CRU baseline climate data for this glacier.
Interpolates the CRU TS data to the high-resolution CL2 climatologies
(provided with OGGM) and writes everything to a NetCDF file.
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
the glacier directory to process
"""
if cfg.PATHS.get('climate_file', None):
warnings.warn("You seem to have set a custom climate file for this "
"run, but are using the default CRU climate "
"file instead.")
@entity_task(log)
def find_start_area(gdir, year_start=1851):
"""This task find the start area for the given glacier, which results in
the best results after the model integration (i.e., modeled glacier surface
closest to measured RGI surface in 2003).
All necessary prepro task (gis, centerline, climate) must be executed
beforehand, as well as the local_t_star() task.
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
year_start : int, optional
year at the beginning of the model integration, default = 1851
(best choice for working with HISTALP data)
Returns
@entity_task(log, writes=['flowline_catchments', 'catchments_intersects'])
def catchment_intersections(gdir):
"""Computes the intersections between the catchments.
A glacier usually consists of several flowlines and each flowline has a
distinct catchment area. This function calculates the intersections between
these areas.
Parameters
----------
gdir : :py:class:`oggm.GlacierDirectory`
where to write the data
"""
catchment_indices = gdir.read_pickle('geometries')['catchment_indices']
# Loop over the lines
@entity_task(log)
def run_constant_climate(gdir, nyears=1000, y0=None, halfsize=15,
bias=None, temperature_bias=None,
store_monthly_step=False,
output_filesuffix='',
climate_filename='climate_monthly',
climate_input_filesuffix='',
init_model_fls=None,
zero_initial_glacier=False,
**kwargs):
"""Runs the constant mass-balance model for a given number of years.
This will initialize a
:py:class:`oggm.core.massbalance.MultipleFlowlineMassBalance`,
and run a :py:func:`oggm.core.flowline.robust_model_run`.
Parameters