iwfmΒΆ

Classes and methods to read, write and modify IWFM and IGSM files and associated data files.

Modules

Unbuffered(stream)

Write unbuffered output to console, for example to print progress at runtime without newline characters.

bnds2mask(bnds_d, coords)

Bounding polygon for IWFM mmodel.

bud2csv(f, loc_names, column_headers, ...[, ...])

Open an IWFM Budget HDF file and retreive all of the data.

budget_info(budget_lines)

Get the Budget file header and footer length and number of tables.

calib

Classes, methods and functions for interactions between IWFM model calibration.

cdec2monthly(input_file, output_file[, verbose])

Read a CDEC observations file, convert sub-monthly observations to the monthly average, and write to a csv file.

cfs2afd(cfs)

Convert flow in CFS to daily volume in Acre-Feet.

closest_list

Given two lists A[] and B[] of form (ID, X, Y), returns a list of len(A) with the item of B closest to each item in A.

date_index(inval, start_date)

Calculate a date inval months from start_date.

date_util

Date validation utilities for IWFM package.

dbf_open(infile[, load, verbose])

Open a DBF file (read with PyShp).

dbf_print_record(db, rec)

Print a DBF record to command line.

debug

Classes, methods and functions for debugging scripts to use IWFM and IGSM files.

detaw_2_table(dir_name, outfile_name[, verbose])

Convert DETAW files to tables and write to text files.

diagnostics

Process IWFM Simulation diagnostic output files.

dicu2table(data_file[, verbose])

Read Delta Island Consumptive Use model file and write out to text file.

dll

Classes, methods and functions to interface with the IWFM DLL.

dss_date(date)

Convert datetime object 'date' into a string in DSS format MM/DD/YYYY_HH:MM with HH in 24-hour format, midnight = 24:00.

elem_poly_coords(elem_nodes, node_coords)

Return a list of element coordinates in the form: [[x0,y0],[x1,y1],[x2,y2]<,...>].

elem_poly_coords_wkt(elem_nodes, node_coords)

Return a list ofelement coordinates in WKT form: ['POLYGON ((X0 Y0, X1 Y1, X2 Y2, X3 Y3, X0 Y0)),'<,...>].

file2dict(infile[, key_field, val_field, ...])

Read file with paired items, return dictionary.

file_2_bak(filename[, force])

Rename a file to contain .bak extension.

file_delete(filename)

Delete a file.

file_missing(filename[, context])

Raise FileNotFoundError for a file that does not exist.

file_rename(filename, newname[, force])

Rename a file.

file_test(filename)

Check that the file exists and exit if it does not.

file_type_error(filename, filetype)

Raise ValueError for an input file of the wrong type.

file_utils

IWFM File Format Conventions ----------------------------- IWFM input files follow a Fortran-style convention where:

file_validate_path(output_file)

Validate output file path and create parent directories if needed.

generate_datetime_objects(start_date, ...)

Generate datetime objects for Excel.

generate_timesteps(start_date, n_steps, ...)

Generate timestep strings matching IWFM format.

get_change_col(changes_table, in_year, ...)

When changing IWFM land use for a scenario, determine which column of the change factors table corresponds to a specific year.

get_elem_centroids(elem_ids, elem_nodes, ...)

Calculate the centroid of each element.

get_elem_list(elem_pairs_file)

Read the submodel elements and returns a dictionary of old to new elements and a dictionary of new to old elements.

get_gw_params(gw_file)

Get nodal coordinates and groundwater parameters from an IWFM simulation.

get_heads_4_date(heads_file, out_date[, start])

Read headall.out file and return heads for a specific date.

get_stream_list_40(stream_lines, line_index, ...)

Read part of the stream specification file for file type 4.0 and return stream reach and rating table info.

get_stream_list_41(stream_lines, line_index, ...)

Read part of the stream specification file for file type 4.1 and return stream reach and rating table info.

get_stream_list_42(stream_lines, line_index, ...)

Read part of the stream specification file for file type 4.2 and return stream reach and rating table info.

get_stream_list_50(stream_lines, line_index, ...)

Read part of the stream specification file for file type 5.0 and return stream reach info.

gis

Classes, methods and functions to read, write and modify gis files for IWFM and IGSM files.

gw_well_lay_elev(d_wellinfo, elem_nodes_d, ...)

Find aquifer and aquitard layer elevations at each well by inverse-distance weighting from the nodes of the element containing the well.

hdf5

Classes, methods and functions to read, write and modify IWFM HDF5 output files.

headall2csv(data, layers, dates, nodes, ...)

Write out IWFM Headall.out data as one csv file for each layer.

headall2dtw(heads_file, pre_file, output_root)

Read IWFM HeadAll.out file, subtract heads from land surface elevation, and write out as a time series with one csv file for each layer.

headall2excel(node_coords, data, dates, ...)

Write out IWFM Headall.out data for selected time steps to an excel workbook, one sheet per time step.

headall2map

Read headall.out file and stratigraphy file and produce head maps.

headall2shp(heads_file, pre_file, out_date, ...)

Read headall.out file and stratigraphy file and produce head maps.

headall2surfer(node_coords, data, dates, ...)

Write out IWFM Headall.out data for one time step to a surfer-format file.

headall2table(heads_file, output_file, out_date)

Read IWFM headall.out file and write results for one date to a table.

headall2ts(input_file, output_file[, verbose])

Read an IWFM HeadAll.out file and write out as a time series with one csv file for each layer.

headall_read(input_file[, skip, verbose])

Read an IWFM HeadAll.out file and return the data as floats, with lists of dates and model nodes and the number of model layers.

hyd_dict(gwhyd_info_file)

Read hydrograph info from Groundwater.dat file and build a dictionary of groundwater hydrograph info.

hyd_diff(gwhyd_file_1, gwhyd_file_2, outname)

Subtract the values in one hydrograph file from another.

igsm_read_chars(char_file, elem_nodes)

Read an IGSM Element Characteristics file and return a list of characteristics for each element.

igsm_read_elements(elem_file)

Read an IGSM Element file, and return a list of the nodes making up each element.

igsm_read_lake(lake_file)

Read an IGSM Lake file and return (a) a list of elements and (b) a list of properties for each lake.

igsm_read_nodes(node_file)

Read the nodal coordinates from the nodes file.

igsm_read_strat(strat_file, node_coords)

Read an IGSM Stratigraphy file and return a list of stratigraphy for each node.

igsm_read_streams(stream_file)

Read an IGSM Stream Geometry file and return (a) a list of stream reaches and (b) a dictionary of stream nodes, and (c) the number of stream nodes.

in_element(e_nodes, e_nos, d_nodexy, x, y)

Return the element containing the point (x,y), or 0 if not in any element.

index_date(in_date[, start_date])

Return the number of days from start_date to in_date.

iwfm_adj_crops(in_year, in_zone_file, ...[, ...])

Use change factors to modify IWFM land use files.

iwfm_aquifer_bottom(strat)

Extract aquitard bottom altitude from IWFM stratigraphy information.

iwfm_aquifer_thickness(strat)

Extract aquifer thicknesses from IWFM stratigraphy information.

iwfm_aquifer_top(strat)

Extract aquitard top altitude from IWFM stratigraphy information.

iwfm_aquitard_bottom(strat)

Extract aquitard bottom from IWFM stratigraphy information.

iwfm_aquitard_thickness(strat)

Extract aquitard thicknesses from IWFM stratigraphy information.

iwfm_aquitard_top(strat)

Extract aquitard top altitude from IWFM stratigraphy information.

iwfm_boundary_coords(node_filename, ...)

Return (x,y) list for the nodes on the bounding polygon.

iwfm_dataclasses

Dataclass definitions for structured data containers used throughout the iwfm package.

iwfm_lse(strat)

Extract land surface elevation from IWFM stratigraphy information.

iwfm_lu2refined(in_lu_file, lu_factors[, ...])

Modify IWFM land use file for a refined model.

iwfm_lu2sub(elem_file, lu_file, out_file[, ...])

Read an IWFM Preprocessor Element File for a submodel and an IWFM Land Use File for the base model, and write a new land use file with land use for only the elements in the Elements File.

iwfm_lu4scenario(out_base_name, ...[, skip, ...])

Merge four single-date IWFM land use files (non-ponded ag, ponded ag, native/riparian, urban) into one combined scenario land use table, matched by element ID.

iwfm_model(pre_fpath, sim_file[, verbose])

Read an IWFM model's preprocessor and simulation input files.

iwfm_nearest_node(point, node_set)

Given an (x,y) location, return the nearest IWFM node.

iwfm_nearest_nodes(filename, node_set)

Read a point file, calculate the nearest node and distance for each point, and write the results to the output file.

iwfm_parametric_interp(pnode_xy, pnode_vals, ...)

Interpolate parametric-grid values to target points using finite element shape functions, matching IWFM's parametric grid method: linear (barycentric) interpolation within triangles and bilinear interpolation within quadrilaterals.

iwfm_precip_adj(precip_filename, ...[, ...])

Read an IWFM precipitation file, a list of VIC grid cells for each precipitation column, and a table of monthly adjustment factors for each VIC grid cell, and write out an IWFM precipitation file with precipitation rates adjusted by the VIC factors.

iwfm_read_bud(bud_file[, verbose])

Read an IWFM Budget main input file, and return a list of lists with the file information and some settings.

iwfm_read_div_areas(divspec_file_name)

Read diversion areas from IWFM divirsion specification file.

iwfm_read_elements(elem_file[, verbose])

Read an IWFM Element file, and return a list of the nodes making up each element.

iwfm_read_elempump(elempump_file_name, elem_ids)

Read an IWFM Element Pumping file, and return lists for ICOLSK, FRACSK, IOPTSK, FRACSKL[Layer], TYPDSTSK, DSTSK, ICFIRIGSK, ICACJSK, ICSKMAX and FSKMAX for Ag and for Urban for each model element.

iwfm_read_et_vals(et_file[, verbose])

Read evapotranspiration values from a file and organize them into lists.

iwfm_read_gw(gw_file[, verbose, node_coords])

Read an IWFM Simulation Groundwater file and return a dictionary of sub-process file names, and arrays of parameters.

iwfm_read_gw_params(gw_file[, node_coords])

Read an IWFM Simulation Groundwater file and return a list of parameters.

iwfm_read_lake(lake_file)

Read an IWFM Lake file and return (a) a list of elements and (b) a list of properties for each lake.

iwfm_read_nodes(node_file[, factor])

Read an IWFM Node file and return a list of the nodes and their coordinates.

iwfm_read_param_table_floats(file_lines, ...)

Read a table of integer parameters from a file and organize them into lists and return a numpy array of floats.

iwfm_read_param_table_ints(file_lines, ...)

Read a table of integer parameters from a file and organize them into lists and return a numpy array.

iwfm_read_precip_vals(precip_file[, verbose])

Read precipitation values from a file and organize them into lists.

iwfm_read_preproc(pre_file)

Read an IWFM Preprocessor main input file, and return a PreprocessorFiles dataclass with file names and some settings.

iwfm_read_rz(rz_file[, verbose])

Read an IWFM Rootzone main input file and return a list of the files called.

iwfm_read_rz_file_names(rz_file_name[, verbose])

Read rootzone file names from the main rootzone file.

iwfm_read_rz_npc(file[, verbose])

Read non-ponded crop data from a file and organize them into lists.

iwfm_read_rz_nr(file[, verbose])

Read native and riparian data from a file and organize them into lists.

iwfm_read_rz_params(rz_file[, verbose])

Read root zone parameters from a file and organize them into lists.

iwfm_read_rz_pc(file[, verbose])

Read ponded crop data from a file and organize them into lists.

iwfm_read_rz_urban(file[, verbose])

Read urban land use data from a file and organize them into lists.

iwfm_read_sim(sim_file[, verbose])

Read an IWFM Simulation main input file, and return a SimulationFiles dataclass with the files called and some settings.

iwfm_read_sim_file(sim_file[, verbose])

Read an IWFM Simulation main input file and return a list of the files called and some settings.

iwfm_read_strat(strat_file, node_coords[, ...])

Read an IWFM Stratigraphy file and return a list of stratigraphy for each node.

iwfm_read_stream_reaches(reach_file)

Read group definitions of stream reaches.

iwfm_read_streams(stream_file[, verbose])

Read an IWFM Stream Geometry file and return a list of stream reaches, a dictionary of stream nodes, and the number of stream nodes.

iwfm_read_uz(file[, verbose])

Read unsaturated zone data from a file and organize them into lists.

iwfm_read_uz_params(uz_file[, verbose])

Read an IWFM Simulation Unsaturated Zone file and return a list of parameters.

iwfm_strat_arrays(strat)

Read IWFM nodal stratigraphy information into individual arrays.

iwfm_sub_preproc(in_pp_file, ...[, verbose])

Read in the Preprocessor main file of a model and a list of element pairs for a submodel.

iwfm_sub_sim(in_sim_file, elem_pairs_file, ...)

Read in a list of element pairs for a submodel.

logtrans(q[, zero_offset, neg_val, roundoff])

Log-transform a number, accounting for non-zero and negative values.

lu2csv(inFileName[, skip, verbose])

Read an IWFM land use file and write to a csv file.

lu2tables(land_use_file, output_file_type[, ...])

Read an IWFM land use file and write contents to a separate file for each land use type.

meas_bounds(gwhyd_obs)

Determine the earliest and latest measurement dates in a SMP-format groundwater head observation file.

multiproc(function, inputlist)

Spread a function across multiple cpu cores.

nearest(d_nodes, x, y)

Find the nearest node to a point from a node dictionary.

nearest_node(point, node_set)

Find the nearest node to a point from the node array.

new_pp_files(out_base_name)

Create and return a PreprocessorFiles dataclass of preprocessor file names from a basename.

new_sim_files(out_base_name)

Create and return a SimulationFiles dataclass of simulation file names from a basename.

parse_iwfm_date(date_str)

Parse IWFM date string format (e.g., '10/31/1973_24:00').

pdf2csv(input_file, output_file[, verbose, ...])

Read a PDF file and write tables to a csv file.

pdf_addimage(pdf, image[, ux, uy, width, height])

Create a cell in a PDF instance.

pdf_addpages(pdf[, pages])

Add pages to a PDF instance.

pdf_cell(pdf[, h, w, t, b, a])

Create a cell in a PDF instance.

pdf_combine(start_dir, save_dir, save_name)

Combine all of the PDF files in a folder into one PDF file modified from https://geektechstuff.com/2018/02/17/python-3-merge-multiple-pdfs-into-one-pdf/.

pdf_create([layout, units, pagesize])

Create a PDF object.

pdf_save(pdf, filename)

Save a PDF instance to a PDF file.

pdf_setfont(pdf[, font, style, size])

Set the font for a PDF instance.

plot

Classes, methods and functions for plotting IWFM parameters, results, etc.

read_elements_csv(elem_file_name)

Read elements from csv file.

read_hyd_dict(gw_dat_file[, verbose])

Read hydrograph info from Groundwater.dat file and build a dictionary of groundwater hydrograph info.

read_lu_change_factors(in_chg_file)

Read the change factors for changing IWFM land use for a scenario.

read_lu_change_zones(in_zone_file)

When changing IWFM land use for a scenario, determine the model elements for each change zone.

read_lu_file(filename[, skip])

Read an IWFM land use file and return a list of acrage data.

read_nodes(node_file[, factor, verbose])

Read an IWFM Node file and return a list of the nodes and their coordinates.

read_nodes_csv(node_file_name)

Read nodes from csv file.

read_obs_smp(smp_file)

Read the contents of an observed values smp file (PEST observation file) and return as a polars DataFrame or dict.

read_sim_hyd(gwhyd_file)

Read simulated values from one IWFM output hydrograph file into a numpy array.

read_sim_hyds(gwhyd_files)

Read simulated values from multiple IWFM output hydrograph files into numpy arrays.

read_sim_wells(gw_file[, verbose])

Read Groundwater.dat file and return a dictionary of groundwater hydrograph info and gwhyd_sim columns.

read_wells

Read IWFM Groundwater.dat file and return a dictionary of groundwater hydrograph info and gwhyd_sim columns.

refined_lu_factors(orig_areas_file, ...)

Calculate land use factors for refined model elements.

sim_info(in_file[, verbose])

Read simulation input file and return the starting date, ending date and time step of the simulation.

simhyd_obs(gwhyd_file)

Read simulated groundwater hydrographs from IWFM file.

simhyds(filename)

Simulated hydrograph values read from an IWFM hydrograph output file.

skip_ahead(line_index, all_lines[, skip])

Increment line_index by skipping (a) every line that begins with 'C', 'c' '*' or '#' and (b) 'skip' additional lines.

sub

Submodel extraction functions for IWFM models.

tables2lu(header, template_lines, ...)

Read an IWFM land use file and write contents to a separate file for each land use type.

util

Download external data (CDEC, NWIS, USACE, USBR).

vic_2_table(factorsFileName, outFileName, col)

Extract one column from a file of VIC gridded climate change factors and write to a table, with one column for each VIC grid ID and one row for each date.

wdl_meas_stats(input_file[, verbose])

Calculate water level statistics and write out to a file.

wdl_ts_4_wells(station_file, waterlevel_file)

Write well data as time series.

write_2_csv(file_base_name, data, crop_list, ...)

Write a 3D array as 2D tables (row=elements x col=time_steps) to (crops) # of comma-separated text files with filename extension 'csv'.

write_2_dat(file_base_name, data, crop_list, ...)

Write a 3D array as 2D tables (row=elements x col=time_steps) to (crops) # of text files with filename extension 'dat'.

write_2_surfer(outfile_name, x_y_locs, data, ...)

Write node (x,y) locations and nodal data to a surfer file.

write_flows(data_file_base, file_type, ...)

Write flow data from a table to a csv file.

write_lu2file(out_table, out_file, in_years)

Write IWFM land use to file.

write_results(name, date, meas, sim, start_date)

Write simulated and observed values for one observation well to a text file.

write_smp(output_filename, lines)

Write observations to a PEST smp file smp format:' OBSLOCATIONID MM/DD/YYYY HH:MM:SS 123.456'.

xls

Excel file operations for IWFM.

zbudget2csv(outfile, zone_names, ...)

Write info from an IWFM ZBudget HDF file to an output file.