def generate_input(N): """Generate a PISM bootstrapping file for a neighborhood number N.""" output_filename = options.output_file_prefix + "_%08d.nc" % N pism_output_filename = options.output_file_prefix + "_o_%08d.nc" % N nc = NC(output_filename, 'w') format_string = "{0:0%db}" % (M * M) string = format_string.format(N) x = np.linspace(-options.L * 1000, options.L * 1000, M) zeros = np.zeros((M, M)) thk = np.zeros(M * M) topg = zeros.copy() - 0.1 * options.H topg[1, 1] = -options.H for j in range(M * M): if string[j] == '1': thk[j] = options.H nc.create_dimensions(x, x) nc.write("topg", topg, attrs={"units": "m", "long_name": "bed_topography"}) nc.write("climatic_mass_balance", zeros, attrs={"units": "kg m-2 year-1"}) nc.write("ice_surface_temp", zeros, attrs={"units": "Celsius"}) nc.write("thk", thk.reshape(M, M), attrs={"units": "m", "long_name": "land_ice_thickness"}) nc.close() return output_filename, pism_output_filename
def generate_input(N): """Generate a PISM bootstrapping file for a neighborhood number N.""" output_filename = options.output_file_prefix + "_%08d.nc" % N pism_output_filename = options.output_file_prefix + "_o_%08d.nc" % N nc = NC(output_filename, 'w') format_string = "{0:0%db}" % (M * M) string = format_string.format(N) x = np.linspace(-options.L * 1000, options.L * 1000, M) zeros = np.zeros((M, M)) thk = np.zeros(M * M) topg = zeros.copy() - 0.1 * options.H topg[1, 1] = -options.H for j in range(M * M): if string[j] == '1': thk[j] = options.H nc.create_dimensions(x, x) nc.write("topg", topg, attrs={"units": "m", "long_name": "bed_topography"}) nc.write("climatic_mass_balance", zeros, attrs={"units": "kg m-2 year-1"}) nc.write("ice_surface_temp", zeros, attrs={"units": "Celsius"}) nc.write("thk", thk.reshape(M, M), attrs={ "units": "m", "long_name": "land_ice_thickness" }) nc.close() return output_filename, pism_output_filename
def generate_pism_input(x, y, xx, yy): stderr.write("calling exactP_list() ...\n") EPS_ABS = 1.0e-12 EPS_REL = 1.0e-15 # Wrapping r[:]['r'] in np.array() forces NumPy to make a C-contiguous copy. h_r, magvb_r, _, W_r, P_r = exactP_list(np.array(r[:]['r']), EPS_ABS, EPS_REL, 1) stderr.write("creating gridded variables ...\n") # put on grid h = np.zeros_like(xx) W = np.zeros_like(xx) P = np.zeros_like(xx) magvb = np.zeros_like(xx) ussa = np.zeros_like(xx) vssa = np.zeros_like(xx) for n, pt in enumerate(r): j = pt['j'] k = pt['k'] h[j, k] = h_r[n] # ice thickness in m magvb[j, k] = magvb_r[n] # sliding speed in m s-1 ussa[j, k], vssa[j, k] = radially_outward(magvb[j, k], xx[j, k], yy[j, k]) W[j, k] = W_r[n] # water thickness in m P[j, k] = P_r[n] # water pressure in Pa stderr.write("creating inputforP.nc ...\n") nc = PISMDataset("inputforP.nc", 'w') nc.create_dimensions(x, y, time_dependent=True, use_time_bounds=True) nc.define_2d_field("thk", time_dependent=False, attrs={"long_name": "ice thickness", "units": "m", "valid_min": 0.0, "standard_name": "land_ice_thickness"}) nc.define_2d_field("topg", time_dependent=False, attrs={"long_name": "bedrock topography", "units": "m", "standard_name": "bedrock_altitude"}) nc.define_2d_field("climatic_mass_balance", time_dependent=False, attrs={"long_name": "climatic mass balance for -surface given", "units": "kg m-2 year-1", "standard_name": "land_ice_surface_specific_mass_balance"}) nc.define_2d_field("ice_surface_temp", time_dependent=False, attrs={"long_name": "ice surface temp (K) for -surface given", "units": "Kelvin", "valid_min": 0.0}) nc.define_2d_field("bmelt", time_dependent=False, attrs={"long_name": "basal melt rate", "units": "m year-1", "standard_name": "land_ice_basal_melt_rate"}) nc.define_2d_field("bwat", time_dependent=False, attrs={"long_name": "thickness of basal water layer", "units": "m", "valid_min": 0.0}) nc.define_2d_field("bwp", time_dependent=False, attrs={"long_name": "water pressure in basal water layer", "units": "Pa", "valid_min": 0.0}) nc.define_2d_field("bc_mask", time_dependent=False, attrs={"long_name": "if =1, apply u_ssa_bc and v_ssa_bc as sliding velocity"}) nc.define_2d_field("u_ssa_bc", time_dependent=False, attrs={"long_name": "x-component of prescribed sliding velocity", "units": "m s-1"}) nc.define_2d_field("v_ssa_bc", time_dependent=False, attrs={"long_name": "y-component of prescribed sliding velocity", "units": "m s-1"}) Phi0 = 0.20 # 20 cm/year basal melt rate T_surface = 260 # ice surface temperature, K variables = {"topg": np.zeros_like(xx), "climatic_mass_balance": np.zeros_like(xx), "ice_surface_temp": np.ones_like(xx) + T_surface, "bmelt": np.zeros_like(xx) + Phi0, "thk": h, "bwat": W, "bwp": P, "bc_mask": np.ones_like(xx), "u_ssa_bc": ussa, "v_ssa_bc": vssa} for name in variables.keys(): nc.write(name, variables[name]) nc.history = subprocess.list2cmdline(argv) nc.close() stderr.write("NetCDF file %s written\n" % "inputforP.nc")
nc.define_2d_field("topg", attrs={ "units": "m", "long_name": "bedrock topography" }) nc.define_2d_field("thk", attrs={ "units": "m", "long_name": "ice thickness" }) nc.define_2d_field("climatic_mass_balance", attrs={"units": "kg m-2 year-1"}) nc.define_2d_field("ice_surface_temp", attrs={"units": "Celsius"}) nc.define_2d_field("u_ssa_bc", attrs={"units": "m/year"}) nc.define_2d_field("v_ssa_bc", attrs={"units": "m/year"}) except: nc = NC(options.output, 'a') nc.write("topg", z) nc.write("thk", thk) nc.write("climatic_mass_balance", np.zeros_like(xx)) nc.write("ice_surface_temp", np.zeros_like(xx) - 30.0) # irrelevant nc.write("u_ssa_bc", ubar) nc.write("v_ssa_bc", vbar) nc.write("bc_mask", bc_mask) nc.close()
vbar = np.zeros_like(thk) vbar[bc_mask == 1] = 100.0 try: nc = NC(options.output, 'w') nc.create_dimensions(x, y, time_dependent=False) nc.define_2d_field("topg", attrs={"units": "m", "long_name": "bedrock topography"}) nc.define_2d_field("thk", attrs={"units": "m", "long_name": "ice thickness"}) nc.define_2d_field("climatic_mass_balance", attrs={"units": "kg m-2 year-1"}) nc.define_2d_field("ice_surface_temp", attrs={"units": "Celsius"}) nc.define_2d_field("u_ssa_bc", attrs={"units": "m/year"}) nc.define_2d_field("v_ssa_bc", attrs={"units": "m/year"}) except: nc = NC(options.output, 'a') nc.write("topg", z) nc.write("thk", thk) nc.write("climatic_mass_balance", np.zeros_like(xx)) nc.write("ice_surface_temp", np.zeros_like(xx) - 30.0) # irrelevant nc.write("u_ssa_bc", ubar) nc.write("v_ssa_bc", vbar) nc.write("bc_mask", bc_mask) nc.close()
x = get('x') y = get('y') bmelt = get('basal_melt_rate_grounded') Mx = len(x) My = len(y) zero = np.zeros((My, Mx)) nc.create_dimensions(x, y, time_dependent=True, use_time_bounds=True) def drainage(t): """time-dependence of bogus summer runoff event in m/a: a positive wavepacket""" return np.exp(-(t - 180.0) ** 2 / 80.0) * 20.0 * (np.cos(0.2 * t * 2 * 3.14159) + 1.0) year = 2012 nc.variables['time'].units = "days since %d-1-1" % (year) # generate space-time bogus summer runoff event; mask where bmelt > 0 for a in range(1, 366): nc.append_time(a, (a, a + 1)) inputthisday = (zero + drainage(np.double(a))) * (bmelt > 0) nc.write("inputtobed", inputthisday, True) # Set attributes inputtobed = nc.variables["inputtobed"] inputtobed.units = "m / year" nc.close() innc.close()
y = get('y') bmelt = get('basal_melt_rate_grounded') Mx = len(x) My = len(y) zero = np.zeros((My, Mx)) nc.create_dimensions(x, y, time_dependent=True, use_time_bounds=True) def drainage(t): """time-dependence of bogus summer runoff event in m/a: a positive wavepacket""" return np.exp( -(t - 180.0)**2 / 80.0) * 20.0 * (np.cos(0.2 * t * 2 * 3.14159) + 1.0) year = 2012 nc.variables['time'].units = "days since %d-1-1" % (year) # generate space-time bogus summer runoff event; mask where bmelt > 0 for a in range(1, 366): nc.append_time(a, (a, a + 1)) inputthisday = (zero + drainage(np.double(a))) * (bmelt > 0) nc.write("inputtobed", inputthisday, True) # Set attributes inputtobed = nc.variables["inputtobed"] inputtobed.units = "m / year" nc.close() innc.close()
"units": "m", "long_name": "bedrock topography" }) nc.define_2d_field("thk", attrs={ "units": "m", "long_name": "ice thickness" }) nc.define_2d_field("climatic_mass_balance", attrs={"units": "kg m-2 year-1"}) nc.define_2d_field("ice_surface_temp", attrs={"units": "Kelvin"}) except: pass nc.write("topg", z) nc.write("thk", thk) nc.write("climatic_mass_balance", np.zeros_like(xx)) nc.write("ice_surface_temp", np.zeros_like(xx) + 273.15 - 30.0) # generate sea level data time = np.linspace(0, 1000, 1001) sea_level = np.linspace(0, 700, 1001) nc.createDimension("time") nc.define_timeseries("time", attrs={"units": "years since 1-1-1"}) nc.write_timeseries("time", time) nc.define_timeseries("delta_SL", attrs={"units": "meters"}) nc.write_timeseries("delta_SL", sea_level)
x = np.linspace(0, options.length, options.Mx) y = x[0:3] - x[1] xx, yy = np.meshgrid(x, y) zeros = np.zeros((My, options.Mx)) topg = (0.5 * options.length - xx) * bed_slope thk = zeros.copy() thk[topg > 200] = ice_thickness v = zeros.copy() u = zeros.copy() + U nc.create_dimensions(x, y) nc.write("topg", topg, attrs={"units": "m", "long_name": "bed_topography"}) nc.write("climatic_mass_balance", zeros, attrs={"units": "kg m-2 year-1"}) nc.write("ice_surface_temp", zeros, attrs={"units": "Celsius"}) nc.write("thk", thk, attrs={ "units": "m", "standard_name": "land_ice_thickness" }) nc.write("ubar", u, attrs={ "units": "m/year", "long_name": "x-component of velocity" }) nc.write("vbar",
x = get('x') y = get('y') bmelt = get('basal_melt_rate_grounded') zero = np.zeros_like(bmelt) nc.create_dimensions(x, y, time_dependent=True, use_time_bounds=True) def drainage(t): """time-dependence of bogus summer runoff event in m/a: a positive wavepacket""" C = np.cos(0.2 * t * 2 * 3.14159) + 1.0 return np.exp(-(t - 180.0)**2 / 80.0) * 20.0 * C year = 2012 nc.variables['time'].units = "days since {}-1-1".format(year) water_density = 1000.0 # generate space-time bogus summer runoff event; mask where bmelt > 0 for a in range(1, 366): nc.append_time(a, (a, a + 1)) inputthisday = (zero + drainage(np.double(a))) * (bmelt > 0) * water_density nc.write("water_input_rate", inputthisday, True) # Set attributes nc.variables["water_input_rate"].units = "kg m-2 year-1" nc.close() innc.close()
U = 100.0 nc = NC(options.output_file_name, 'w') x = np.linspace(0, options.length, options.Mx) y = x[0:3] - x[1] xx, yy = np.meshgrid(x, y) zeros = np.zeros((My, options.Mx)) topg = (0.5 * options.length - xx) * bed_slope thk = zeros.copy() thk[topg > 200] = ice_thickness v = zeros.copy() u = zeros.copy() + U nc.create_dimensions(x, y) nc.write("topg", topg, attrs={"units": "m", "long_name": "bed_topography"}) nc.write("climatic_mass_balance", zeros, attrs={"units": "kg m-2 year-1"}) nc.write("ice_surface_temp", zeros, attrs={"units": "Celsius"}) nc.write("thk", thk, attrs={"units": "m", "standard_name": "land_ice_thickness"}) nc.write("ubar", u, attrs={"units": "m/year", "long_name": "x-component of velocity"}) nc.write("vbar", v, attrs={"units": "m/year", "long_name": "y-component of velocity"}) nc.close()
time = np.linspace(start_time, end_time, N) time_bounds = np.zeros((N-1, 2)) for i in range(N-1): time_bounds[i,:] = [time[i], time[i+1]] nc = PISMDataset(options.output[0], 'w') nc.create_time(True, N-1, units="years since 1-1-1") nc.variables['time'][:] = time_bounds[:,0] nc.variables['time_bounds'][:] = time_bounds if options.precip: delta = nc.write("delta_P", -0.5 + 0.5 * time_bounds[:,0]) delta.units = "kg m-2 year-1" delta.long_name = "precipitation offset" elif options.precip_scaling: delta = nc.write("frac_P", 0.5 + 0.5 * np.sin(time_bounds[:,0] / options.length * 4 * np.pi + 0.5*np.pi)) delta.units = "1" delta.long_name = "precipitation scaling" elif options.frac_SMB: delta = nc.write("frac_mass_flux", 0.5 + 0.5 * np.sin(time_bounds[:,0] / options.length * 4 * np.pi + 0.5*np.pi)) delta.units = "1" delta.long_name = "sub-shelf mass balance scaling" elif options.temp: delta = nc.write("delta_T", -0.5 + 0.5 * time_bounds[:,0]) delta.units = "Kelvin" delta.long_name = "temperature offset" elif options.weather_station:
nc = NC(options.output, 'a') try: nc.create_dimensions(x, y, time_dependent=False) nc.define_2d_field("topg", attrs={"units": "m", "long_name": "bedrock topography"}) nc.define_2d_field("thk", attrs={"units": "m", "long_name": "ice thickness"}) nc.define_2d_field("climatic_mass_balance", attrs={"units": "kg m-2 year-1"}) nc.define_2d_field("ice_surface_temp", attrs={"units": "Kelvin"}) except: pass nc.write("topg", z) nc.write("thk", thk) nc.write("climatic_mass_balance", np.zeros_like(xx)) nc.write("ice_surface_temp", np.zeros_like(xx) + 273.15 - 30.0) # generate sea level data time = np.linspace(0, 1000, 1001) sea_level = np.linspace(0, 700, 1001) nc.createDimension("time") nc.define_timeseries("time", attrs={"units": "years since 1-1-1"}) nc.write_timeseries("time", time) nc.define_timeseries("delta_SL", attrs={"units": "meters"}) nc.write_timeseries("delta_SL", sea_level)
lon,lat = p(ee, nn, inverse=True) nc = NC(options.output[0], 'w') nc.create_dimensions(x, y, time_dependent = False) nc.define_2d_field("lon", attrs={"long_name" : "longitude", "standard_name" : "longitude", "units" : "degreesE"}) nc.define_2d_field("lat", attrs={"long_name" : "latitude", "standard_name" : "latitude", "units" : "degreesN"}) nc.write("lon", lon) nc.write("lat", lat) topg = nc.write("topg", np.zeros_like(lon)) topg.standard_name = "bedrock_altitude" topg.units = "m" thk = nc.write("thk", np.zeros_like(lon) + 2000) thk.standard_name = "land_ice_thickness" thk.units = "m" precip = nc.write("precipitation", np.zeros_like(lon)) precip.units = "kg m-2 year-1" smb = nc.write("climatic_mass_balance", np.zeros_like(lon)) smb.units = "kg m-2 year-1"