Exemple #1
0
def generate_config():
    """Generates the config file with custom ice softness and hydraulic conductivity."""

    stderr.write("generating testPconfig.nc ...\n")

    nc = PISMDataset("testPconfig.nc", 'w')
    pism_overrides = nc.createVariable("pism_overrides", 'b')

    attrs = {
        "flow_law.isothermal_Glen.ice_softness": 3.1689e-24,
        "flow_law.isothermal_Glen.ice_softness_doc": "Pa-3 s-1; ice softness; NOT DEFAULT",

        "hydrology.hydraulic_conductivity": 1.0e-2 / (1000.0 * 9.81),
        "hydrology.hydraulic_conductivity_doc": "= k; NOT DEFAULT",

        "hydrology.regularizing_porosity": 0.01,
        "hydrology.regularizing_porosity_doc": "[pure]; phi_0 in notes",

        "hydrology.tillwat_max": 0.0,
        "hydrology.tillwat_max_doc": "m; turn off till water mechanism",

        "hydrology.thickness_power_in_flux": 1.0,
        "hydrology.thickness_power_in_flux_doc": "; = alpha in notes",

        "hydrology.gradient_power_in_flux": 2.0,
        "hydrology.gradient_power_in_flux_doc": "; = beta in notes",

        "hydrology.roughness_scale": 1.0,
        "hydrology.roughness_scale_doc": "m; W_r in notes; roughness scale",

        "basal_yield_stress.model": "constant",
        "basal_yield_stress.model_doc": "only the constant yield stress model works without till",

        "basal_yield_stress.constant.value": 1e6,
        "basal_yield_stress.constant.value_doc": "set default to 'high tauc'",
    }
    keys = list(attrs.keys())
    keys.sort()
    for k in keys:
        pism_overrides.setncattr(k, attrs[k])

    nc.close()
Exemple #2
0
def generate_config():
    """Generates the config file with custom ice softness and hydraulic conductivity."""

    stderr.write("generating testPconfig.nc ...\n")

    nc = PISMDataset("testPconfig.nc", 'w')
    pism_overrides = nc.createVariable("pism_overrides", 'b')

    attrs = {
        "flow_law.isothermal_Glen.ice_softness": 3.1689e-24,
        "flow_law.isothermal_Glen.ice_softness_doc": "Pa-3 s-1; ice softness; NOT DEFAULT",

        "hydrology.hydraulic_conductivity": 1.0e-2 / (1000.0 * 9.81),
        "hydrology.hydraulic_conductivity_doc": "= k; NOT DEFAULT",

        "hydrology.regularizing_porosity": 0.01,
        "hydrology.regularizing_porosity_doc": "[pure]; phi_0 in notes",

        "hydrology.tillwat_max": 0.0,
        "hydrology.tillwat_max_doc": "m; turn off till water mechanism",

        "hydrology.thickness_power_in_flux": 1.0,
        "hydrology.thickness_power_in_flux_doc": "; = alpha in notes",

        "hydrology.gradient_power_in_flux": 2.0,
        "hydrology.gradient_power_in_flux_doc": "; = beta in notes",

        "hydrology.roughness_scale": 1.0,
        "hydrology.roughness_scale_doc": "m; W_r in notes; roughness scale",

        "basal_yield_stress.model": "constant",
        "basal_yield_stress.model_doc": "only the constant yield stress model works without till",

        "basal_yield_stress.constant.value": 1e6,
        "basal_yield_stress.constant.value_doc": "set default to 'high tauc'",
    }
    keys = list(attrs.keys())
    keys.sort()
    for k in keys:
        pism_overrides.setncattr(k, attrs[k])

    nc.close()
Exemple #3
0
def generate_config():
    """Generates the config file with custom ice softness and hydraulic conductivity."""

    stderr.write("generating testPconfig.nc ...\n")

    nc = PISMDataset("testPconfig.nc", 'w')
    pism_overrides = nc.createVariable("pism_overrides", 'b')

    pism_overrides.ice_softness = 3.1689e-24
    pism_overrides.ice_softness_doc = "Pa-3 s-1; ice softness; NOT DEFAULT"

    pism_overrides.hydrology_hydraulic_conductivity = 1.0e-2 / (1000.0 * 9.81)
    pism_overrides.hydrology_hydraulic_conductivity_doc = "= k; NOT DEFAULT"

    pism_overrides.hydrology_regularizing_porosity = 0.01
    pism_overrides.hydrology_regularizing_porosity_doc = "[pure]; phi_0 in notes"

    pism_overrides.hydrology_tillwat_max = 0.0
    pism_overrides.hydrology_tillwat_max_doc = "m; turn off till water mechanism"

    pism_overrides.hydrology_thickness_power_in_flux = 1.0
    pism_overrides.hydrology_thickness_power_in_flux_doc = "; = alpha in notes"

    pism_overrides.hydrology_gradient_power_in_flux = 2.0
    pism_overrides.hydrology_gradient_power_in_flux_doc = "; = beta in notes"

    pism_overrides.hydrology_roughness_scale = 1.0
    pism_overrides.hydrology_roughness_scale_doc = "m; W_r in notes; roughness scale"

    pism_overrides.yield_stress_model = "constant"
    pism_overrides.yield_stress_model_doc = "only the constant yield stress model works without till"

    pism_overrides.default_tauc = 1e6
    pism_overrides.default_tauc_doc = "set default to 'high tauc'"

    nc.close()
Exemple #4
0
                            "comment"     : "Downloaded from %s" % (ftp_url),
                            "units"       : "cm",
                            "valid_min"   : 0.0,
                            "mapping"     : "mapping",
                            "_FillValue"   : -1})
nc.write_2d_field("usurf", usurf)

nc.define_2d_field("dist", time_dependent = False, nc_type='i',
                   attrs = {"long_name"   : "Mean distance from contributing GLAS data for each grid cell",
                            "comment"     : "Downloaded from %s" % (ftp_url),
                            "units"       : "mm",
                            "valid_min"   : 0.0,
                            "mapping"     : "mapping"})
nc.write_2d_field("dist", dist)

mapping = nc.createVariable("mapping", 'c')
mapping.grid_mapping_name = "polar_stereographic"
mapping.standard_parallel = 70.0
mapping.latitude_of_projection_origin = 90.0
mapping.straight_vertical_longitude_from_pole = -45.0
mapping.ellipsoid = "WGS84"

nc.Conventions = "CF-1.4"
nc.projection = "+proj=stere +ellps=WGS84 +datum=WGS84 +lon_0=-45 +lat_0=90 +lat_ts=70 +units=m"

from time import asctime
import sys
separator = ' '
historystr = "%s: %s\n" % (asctime(), separator.join(sys.argv))
nc.history = historystr
Exemple #5
0
def vel_mosaic2netcdf(filename_base, output_filename):
    files = []
    for (short_name, long_name) in [("vx", "ice surface velocity in the X direction"),
                                    ("vy", "ice surface velocity in the Y direction"),
                                    ("ex",
                                     "error estimates for the X-component of the ice surface velocity"),
                                    ("ey",
                                     "error estimates for the Y-component of the ice surface velocity"),
                                    ]:

        try:
            os.stat(filename_base + "." + short_name)
            entry = ("%s.%s" %(filename_base,short_name), short_name, long_name)
            files.append(entry)
        except:
            print "Missing %s.%s. If this file ends with ex or ey the script will work just fine" %(filename_base, short_name)

    grid = np.loadtxt(filename_base + ".vx.geodat", skiprows=1, comments="&")
    
    shape = (int(grid[0,1]), int(grid[0,0]))
    x0 = grid[2,0] * 1e3
    y0 = grid[2,1] * 1e3
    dx = grid[1,0]
    dy = grid[1,1]
    x1 = x0 + (shape[1] - 1) * dx
    y1 = y0 + (shape[0] - 1) * dx
    x = np.linspace(x0, x1, shape[1])
    y = np.linspace(y0, y1, shape[0])
    
    nc = NC("%s.nc" % output_filename, 'w')
    nc.create_dimensions(x, y)
    
    for (filename, short_name, long_name) in files:
        
        nc.define_2d_field(short_name, time_dependent = False, nc_type='f4',
                           attrs = {"long_name"   : long_name,
                                    "comment"     : "Downloaded from %s" % (ftp_url + filename),
                                    "units"       : "m / year",
                                    "mapping"     : "mapping",
                                    "_FillValue"  : -2e+9})
        
        var = np.fromfile(filename, dtype=">f4", count=-1)
        
        nc.write_2d_field(short_name, var)
        
    # Add a mask that shows where observations are present 
    if options.add_mask == True:
        nc.define_2d_field("vel_surface_mask", time_dependent = False, nc_type='i',
                           attrs = {"long_name"   : "Mask observations; 1 where surface vel. available",
                                    "comment"     : "Used as vel_misfit_weight in inversion for tauc",
                                    "units"       : "",
                                    "mapping"     : "mapping",
                                    "_FillValue"  : 0})
        var = np.fromfile(filename_base + ".vx", dtype=">f4", count=-1)
        mask = var/var
        mask[var == -2e9] = 0.
        nc.write_2d_field("vel_surface_mask", mask)

    mapping = nc.createVariable("mapping", 'c')
    mapping.grid_mapping_name = "polar_stereographic"
    mapping.standard_parallel = 70.0
    mapping.latitude_of_projection_origin = 90.0
    mapping.straight_vertical_longitude_from_pole = -45.0
    mapping.ellipsoid = "WGS84"
    
    nc.Conventions = "CF-1.4"
    nc.projection = "+proj=stere +ellps=WGS84 +datum=WGS84 +lon_0=-45 +lat_0=90 +lat_ts=70 +units=m"
    nc.reference  = "Joughin, I., B. Smith, I. Howat, and T. Scambos. 2010. MEaSUREs Greenland Ice Velocity Map from InSAR Data. Boulder, Colorado, USA: National Snow and Ice Data Center. Digital media."
    nc.title      = "MEaSUREs Greenland Ice Velocity Map from InSAR Data"
    
    from time import asctime
    import sys
    separator = ' '
    historystr = "%s: %s\n" % (asctime(), separator.join(sys.argv))
    nc.history = historystr
    
    nc.close()
def grid2netcdf(filename_base, output_filename):
    print "Reading txt files with data ..."
    x, y, topg, fill_value = readComposite("%sbottom.txt" % filename_base)
    x, y, thk, fill_value = readComposite("%sthickness.txt" % filename_base)
    x, y, usurf, fill_value = readComposite("%ssurface.txt" % filename_base)

    nc = NC("%s.nc" % output_filename, "w")
    nc.create_dimensions(x, y)

    names = []
    for (short_name, long_name) in [
        ("topg", "bedrock surface elevation"),
        ("thk", "land ice thickness"),
        ("usurf", "ice upper surface elevation"),
    ]:
        entry = (short_name, long_name)
        names.append(entry)

    var = [topg, thk, usurf]
    for i, (short_name, long_name) in enumerate(names):
        nc.define_2d_field(
            short_name,
            time_dependent=False,
            nc_type="f4",
            attrs={
                "long_name": long_name,
                "comment": "Downloaded from ftp://data.cresis.ku.edu/data/grids/Jakobshavn_2006_2012_Composite.zip",
                "units": "m",
                "mapping": "mapping",
                "_FillValue": fill_value,
            },
        )

        nc.write_2d_field(short_name, var[i])

    # Add a mask that shows where observations are present
    nc.define_2d_field(
        "obs_mask",
        time_dependent=False,
        nc_type="i",
        attrs={
            "long_name": "Mask observations; 1 where observations available",
            "units": "",
            "mapping": "mapping",
            "_FillValue": 0,
        },
    )
    mask = np.ones(thk.shape)
    mask[thk == fill_value] = 0.0
    nc.write_2d_field("obs_mask", mask)

    mapping = nc.createVariable("mapping", "c")
    mapping.grid_mapping_name = "polar_stereographic"
    mapping.standard_parallel = 70.0
    mapping.latitude_of_projection_origin = 90.0
    mapping.straight_vertical_longitude_from_pole = -45.0
    mapping.ellipsoid = "WGS84"

    nc.Conventions = "CF-1.4"
    nc.projection = "+proj=stere +ellps=WGS84 +datum=WGS84 +lon_0=-45 +lat_0=90 +lat_ts=70 +units=m"
    nc.reference = "Gogineni, Prasad. 2012. CReSIS Radar Depth Sounder Data, Lawrence, Kansas, USA. Digital Media. http://data.cresis.ku.edu"
    nc.title = "CReSIS Gridded Depth Sounder Data for Jakobshavn, Greenland"
    nc.acknowledgement = "We acknowledge the use of data and/or data products from CReSIS generated with support from NSF grant ANT-0424589 and NASA grant NNX10AT68G"

    from time import asctime
    import sys

    separator = " "
    historystr = "%s: %s\n" % (asctime(), separator.join(sys.argv))
    nc.history = historystr
    print "Done writing %s.nc ..." % output_filename

    nc.close()

    # Run nc2cdo to add lat/lon
    print "Adding lat/lon by running nc2cdo.py ..."
    os.system("nc2cdo.py %s.nc" % output_filename)