Cleanup before release

develop
Joseph D Hughes 2017-11-30 15:50:32 -05:00
parent 5b6920304b
commit 944b57aee1
11 changed files with 239 additions and 104 deletions

View File

@ -4,7 +4,6 @@
### Version 3.2.6 develop — build 396
[![Build Status](https://travis-ci.org/modflowpy/flopy.svg?branch=develop)](https://travis-ci.org/modflowpy/flopy)
[![PyPI Version](https://img.shields.io/pypi/v/flopy.png)](https://pypi.python.org/pypi/flopy)
[![PyPI Downloads](https://img.shields.io/pypi/dm/flopy.png)](https://pypi.python.org/pypi/flopy)
[![Coverage Status](https://coveralls.io/repos/github/modflowpy/flopy/badge.svg?branch=develop)](https://coveralls.io/github/modflowpy/flopy?branch=develop)
@ -25,14 +24,23 @@ Documentation
FloPy code documentation is available at [http://modflowpy.github.io/flopydoc/](http://modflowpy.github.io/flopydoc/)
FloPy is citable! Please see our paper in Groundwater:
How to Cite
-----------------------------------------------
##### ***Citation for FloPy:***
[Bakker, M., Post, V., Langevin, C. D., Hughes, J. D., White, J. T., Starn, J. J. and Fienen, M. N. (2016), Scripting MODFLOW Model Development Using Python and FloPy. Groundwater, 54: 733739. doi:10.1111/gwat.12413](http://dx.doi.org/10.1111/gwat.12413)
##### ***Software/Code citation for FloPy:***
[Bakker, M., Post, V., Langevin, C.D., Hughes, J.D., White, J.T., Starn, J.J., and Fienen, M.N., 2016, FloPy v3.2.6: U.S. Geological Survey Software Release, 19 March 2017, http://dx.doi.org/10.5066/F7BK19FH](http://dx.doi.org/10.5066/F7BK19FH)
Examples
-----------------------------------------------
### [IPython Notebook Examples](docs/notebook_examples.md)
### [jupyter Notebook Examples](docs/notebook_examples.md)
### [Python Script Examples](docs/script_examples.md)
@ -49,7 +57,35 @@ FloPy requires **Python** 2.7 or **Python** 3.3 (or higher)
**Dependencies:**
FloPy requires **NumPy** 1.9 (or higher), **matplotlib** 1.4 (or higher) for mapping and cross-section capabilities in the `flopy.plot` submodule, and **enum34** for **Python** 2.7 or **Python** 3.3. The mapping and cross-section capabilities in the `flopy.plot` submodule and shapefile export capabilities (`to_shapefile()`) require **Pyshp** 1.2 (or higher). The NetCDF export capabilities in the `flopy.export` submodule require **python-dateutil** 2.4 (or higher), **netcdf4** 1.1 (or higher), and **pyproj** 1.9 (or higher). Other NetCDF dependencies are detailed on the [UniData](http://unidata.github.io/netcdf4-python/) website. The `get_dataframes` method in the `ListBudget` class in the `flopy.utils` submodule require **pandas** 0.15 (or higher).
FloPy requires **NumPy** 1.9 (or higher) and **enum34** for **Python** 2.7 or **Python** 3.3.
***Optional Method Dependencies:***
Additional dependencies to use optional FloPy helper methods are listed below.
| Method | Python Package |
| ----------------------------------------------------------------------------------- | -------------------------------------------------- |
| `.plot()` | **matplotlib** >= 1.4 |
| `.plot_shapefile()` | **matplotlib** >= 1.4 and **Pyshp** >= 1.2 |
| `.to_shapefile()` | **Pyshp** >= 1.2 |
| `.export(*.shp)` | **Pyshp** >= 1.2 |
| `.export(*.nc)` | **netcdf4** >= 1.1 and **python-dateutil** >= 2.4 |
| `.export(*.tif)` | **rasterio** |
| `.export(*.asc)` in `flopy.utils.reference` `SpatialReference` class | **scipy.ndimage** |
| `.interpolate()` in `flopy.utils.reference` `SpatialReference` class | **scipy.interpolate** |
| `.interpolate()` in `flopy.mf6.utils.reference` `StructuredSpatialReference` class | **scipy.interpolate** |
| `.get_dataframes()` in `flopy.utils.mflistfile` `ListBudget` class | **pandas** >= 0.15 |
| `.get_dataframes()` in `flopy.utils.observationfile` `ObsFiles` class | **pandas** >= 0.15 |
| `.get_dataframes()` in `flopy.utils.sfroutputfile` `ModflowSfr2` class | **pandas** >= 0.15 |
| `.get_dataframes()` in `flopy.utils.util_list` `MfList` class | **pandas** >= 0.15 |
| `.get_dataframes()` in `flopy.utils.zonebud` `ZoneBudget` class | **pandas** >= 0.15 |
| `.pivot_keyarray()` in `flopy.mf6.utils.arrayutils` `AdvancedPackageUtil` class | **pandas** >= 0.15 |
| `._get_vertices()` in `flopy.mf6.utils.binaryfile_utils` `MFOutputRequester` class | **pandas** >= 0.15 |
| `.get_dataframe()` in `flopy.mf6.utils.mfobservation` `Observations` class | **pandas** >= 0.15 |
| `.df()` in `flopy.modflow.mfsfr2` `SfrFile` class | **pandas** >= 0.15 |
| `.time_coverage()` in `flopy.export.metadata` `acc` class - ***optional usage*** | **pandas** >= 0.15 |
| `.loadtxt()` in `flopy.utils.flopyio` - ***optional usage*** | **pandas** >= 0.15 |
**For base Python distributions:**

View File

@ -1,29 +1,37 @@
Examples
-----------------------------------------------
### IPython Notebook Examples
### jupyter Notebook Examples
The following IPython Notebooks contain example FloPy scripts for a variety of models and FloPy features
The following jupyter Notebooks contain examples for using FloPy pre- and post-processing capabilities with a variety of MODFLOW-based models.
#### Basic examples
#### MODFLOW-2000, MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, MODPATH, MT3DMS, MT3D-USGS, and SEAWAT
##### ***Basic examples***
+ An overview of loading existing MODFLOW models, creating models, and common post-processing capabilities using FloPy is presented in the [flopy3_working_stack_demo](../examples/Notebooks/flopy3_working_stack_demo.ipynb) Notebook.
+ An overview of the options to enter *layer, row, column, data* values for packages such as the wel and ghb packages is given in the [flopy3_modflow_boundaries](../examples/Notebooks/flopy3_modflow_boundaries.ipynb) Notebook
+ An overview of how to control the format of numeric arrays written by FloPy to MODFLOW-based input files is given in the [flopy3_array_outputformat_options](../examples/Notebooks/flopy3_array_outputformat_options.ipynb) Notebook.
+ An overview of how FloPy3 handles external files for numeric arrays written by FloPy to MODFLOW-based input files is given in the [flopy3_external_file_handling](../examples/Notebooks/flopy3_external_file_handling.ipynb) Notebook.
+ An overview of how FloPy handles external files for numeric arrays written by FloPy to MODFLOW-based input files is given in the [flopy3_external_file_handling](../examples/Notebooks/flopy3_external_file_handling.ipynb) Notebook.
+ An overview of FloPy3 capabilities to load a SFR2 file and evaluate data contained in the file is given in the [flopy3_SFR2_load](../examples/Notebooks/flopy3_SFR2_load.ipynb) Notebook.
+ An overview of FloPy functionality in the ```SpatialReference``` class for locating the model in a "real world" coordinate reference system is given in the [flopy3_SpatialReference_demo](../examples/Notebooks/flopy3_SpatialReference_demo.ipynb) Notebook.
+ An overview of FloPy3 capabilities to create a SFR2 file and evaluate data contained in the file is given in the [flopy3_sfrpackage_example](../examples/Notebooks/flopy3_sfrpackage_example.ipynb) Notebook. This example also shows how to read SFR water balance output into a pandas dataframe for additional postprocessing.
+ An overview of FloPy capabilities to load a SFR2 file and evaluate data contained in the file is given in the [flopy3_SFR2_load](../examples/Notebooks/flopy3_SFR2_load.ipynb) Notebook.
+ An overview of FloPy3 capabilities to create a MNW2 file and evaluate data contained in the file is given in the [flopy3_mnw2package_example](../examples/Notebooks/flopy3_mnw2package_example.ipynb) Notebook.
+ An overview of FloPy capabilities to create a SFR2 file and evaluate data contained in the file is given in the [flopy3_sfrpackage_example](../examples/Notebooks/flopy3_sfrpackage_example.ipynb) Notebook. This example also shows how to read SFR water balance output into a pandas dataframe for additional postprocessing.
+ An overview of FloPy3 capabilities to create a UZF file and evaluate data contained in the file and UZF output files is given in the [flopy3_uzf_example](../examples/Notebooks/flopy3_uzf_example) Notebook.
+ An overview of FloPy capabilities to create a MNW2 file and evaluate data contained in the file is given in the [flopy3_mnw2package_example](../examples/Notebooks/flopy3_mnw2package_example.ipynb) Notebook.
+ An overview of FloPy3 capabilities for exporting two-dimensional array data as a binary file is given in the [flopy3_save_binary_data_file](../examples/Notebooks/flopy3_save_binary_data_file.ipynb) Notebook.
+ An overview of FloPy capabilities to create a UZF file and evaluate data contained in the file and UZF output files is given in the [flopy3_uzf_example](../examples/Notebooks/flopy3_uzf_example) Notebook.
+ An overview of FloPy3 capabilities to create MODPATH models and plot MODPATH results is given in the [flopy3_Modpath_example](../examples/Notebooks/flopy3_Modpath_example.ipynb) Notebook.
+ An overview of FloPy capabilities for exporting two-dimensional array data as a binary file is given in the [flopy3_save_binary_data_file](../examples/Notebooks/flopy3_save_binary_data_file.ipynb) Notebook.
+ An overview of FloPy capabilities to create MODPATH models and plot MODPATH results is given in the [flopy3_Modpath_example](../examples/Notebooks/flopy3_Modpath_example.ipynb) Notebook.
+ An overview of using FloPy and GRIDGEN to creating layered quadtree grids for MODFLOW-USG is given in the [flopy3_gridgen](../examples/Notebooks/flopy3_gridgen.ipynb) Notebook.
+ The [lake example](../examples/Notebooks/flopy3_lake_example.ipynb), a very simple FloPy example of steady flow in a square model with a fixed head cell in the middle (representing a lake) in a 10-layer model.
@ -35,27 +43,46 @@ The following IPython Notebooks contain example FloPy scripts for a variety of m
+ The ['Crank-Nicolson' example distributed with MT3D-USGS](../examples/Notebooks/flopy3_MT3D-USGS_example.ipynb), a simple MT3D-USGS model that uses the SFT Package.
+ The [Henry Problem](../examples/Notebooks/flopy3_SEAWAT_henry_problem.ipynb), a simple saltwater intrusion model developed with Flopy and run using SEAWAT.
+ The [Henry Problem](../examples/Notebooks/flopy3_SEAWAT_henry_problem.ipynb), a simple saltwater intrusion model developed with FloPy and run using SEAWAT.
#### SWI2 examples
##### ***SWI2 examples***
+ [Example 1](../examples/Notebooks/flopy3_swi2package_ex1.ipynb) of the SWI2 manual, simulating a rotating interface.
+ [Example 4](../examples/Notebooks/flopy3_swi2package_ex4.ipynb) of the SWI2 manual, upconing below a pumping well below a two-aquifer island system.
#### Model analysis and error checking examples
##### ***Model analysis and error checking examples***
+ An overview of the FloPy [model input data `check()` method capabilities](../examples/Notebooks/flopy3_ModelCheckerExample.ipynb)
+ An overview of the FloPy [model input data `check()` method capabilities](../examples/Notebooks/flopy3_ModelCheckerExample.ipynb).
+ An overview of the FloPy [zone budget `ZoneBudget()` method capabilities](../examples/Notebooks/flopy3_ZoneBudget_example) Notebook. The `ZoneBudget()` method is a python implementation of USGS ZONEBUDGET executable for MODFLOW (Harbaugh, 1990).
+ An overview of the Flopy [`get_transmissivities()` method for computing open interval transmissivities (for weighted averages of heads or fluxes)](../examples/Notebooks/flopy3_get_transmissivities_example.ipynb) Notebook. This method can be used to:
+ An overview of the FloPy [`get_transmissivities()` method for computing open interval transmissivities (for weighted averages of heads or fluxes)](../examples/Notebooks/flopy3_get_transmissivities_example.ipynb) Notebook. This method can be used to:
* compute vertically-averaged head target values representative of observation wells of varying open intervals (including variability in saturated thickness due to the position of the water table). This may be especially important for reducing error in observations used for parameter estimation, in areas with appreciable vertical head gradients (due to aquitards, pumping, discharge to surface water, etc.)
* apportion boundary fluxes (e.g. from an analytic element model) among model layers based on transmissivity.
* any other analysis where a distribution of transmissivity is needed for a specified vertical interval of the model.
+ An overview of utilties for [post-processing head results from MODFLOW](../examples/Notebooks/flopy3_Modflow_postprocessing_example.ipynb)
#### Plotting examples
+ An overview of utilties for [post-processing head results from MODFLOW](../examples/Notebooks/flopy3_Modflow_postprocessing_example.ipynb).
#### ***Export examples***
+ An overview of the FloPy [netCDF and shapefile export capabilities](../examples/Notebooks/flopy3_export.ipynb).
+ [Exporting 2-D arrays as rasters or contour shapefiles](../examples/Notebooks/flopy3_Modflow_postprocessing_example.ipynb).
#### ***Parameter Estimation examples***
+ An overview of the FloPy [parameter estimation capabilities](../examples/Notebooks/flopy3_PEST.ipynb).
#### MODFLOW 6
##### ***Basic examples***
+ A simple MODFLOW 6 example is given in the [flopy3_mf6_A_simple-model](../examples/Notebooks/flopy3_mf6_A_simple-model.ipynb) Notebook.
+ A more complicated MODFLOW 6 example is given in the [flopy3_mf6_B_complex-model](../examples/Notebooks/flopy3_mf6_B_complex-model.ipynb) Notebook.
#### Plotting examples ***(limited functionality for MODFLOW 6 models)***
+ An overview of the FloPy [map and cross-section plotting capabilities](../examples/Notebooks/flopy3_MapExample.ipynb).
@ -65,14 +92,9 @@ The following IPython Notebooks contain example FloPy scripts for a variety of m
+ The [flopy3_shapefile_features](../examples/Notebooks/flopy3_shapefile_features.ipynb) Notebook illustrates some functionality in flopy for exchanging MODFLOW-related information with shapefiles, including convenience functions for working with shapefile data in numpy recarrays, some simple container objects for storing geographic information, and a demonstration of automatic writing of projection (.prj) files using EPSG codes.
#### Export examples
+ An overview of [plotting MODFLOW-USG unstructured grid data and model results](../examples/Notebooks/flopy3_UnstructuredGridPlotting.ipynb).
+ An overview of the FloPy [netCDF and shapefile export capabilities](../examples/Notebooks/flopy3_export.ipynb).
+ [Exporting 2-D arrays as rasters or contour shapefiles](../examples/Notebooks/flopy3_Modflow_postprocessing_example.ipynb)
#### Parameter Estimation examples
+ An overview of the FloPy [parameter estimation capabilities](../examples/Notebooks/flopy3_PEST.ipynb).
+ An overview of [how to plot MODFLOW 6 results for a single GWF model](../examples/Notebooks/flopy3_BasicMODFLOW6Plot.ipynb).
#### Additional MODFLOW examples

View File

@ -5,7 +5,9 @@ Examples
FloPy scripts for running and post-processing the lake example and SWI2 Examples (examples 1 to 5) that are described in [Bakker et al. (2013)](http://pubs.usgs.gov/tm/6a46/) are available:
+ [Lake Example](../examples/scripts/lake_example.py)
+ [Henry problem using SEAWAT version 4](../examples/scripts/flopy_henry.py)
+ [Lake Example](../examples/scripts/flopy_lake_example.py)
+ [SWI2 Example 1](../examples/scripts/flopy_swi2_ex1.py)
@ -17,6 +19,4 @@ FloPy scripts for running and post-processing the lake example and SWI2 Examples
+ [SWI2 Example 5](../examples/scripts/flopy_swi2_ex5.py)
+ [Henry problem using SEAWAT version 4](../examples/scripts/henry.py)
Note that examples 2 and 5 also include FloPy code for running and post-processing SEAWAT models.

View File

@ -92,3 +92,47 @@ FloPy Supported Packages
| River Observation (RVOB) | Not supported | Not supported | Not supported |
| Stream Observation (STOB) | Not supported | Not supported | Not supported |
| Specified-Head Flow Observation (CHOB) | Not supported | Not supported | Not supported |
### MODFLOW 6
| Package | Creation and Write | Load Available |
| ---------------------------------------------- | -------------------- | -------------------- |
| Temporal Discretization (TDIS6) | Supported | Supported |
| Structured Discretization (DIS6) | Supported | Supported |
| Discretization with Vertices (DISV6) | Supported | Supported |
| Unstructured Discretization (DISU6) | Supported | Supported |
| Initial Conditions (IC6) | Supported | Supported |
| Output Control (OC6) | Supported | Supported |
| Groundwater Flow Observations (OBS6) | Supported | Supported |
| Node Property Flow (NPF6) | Supported | Supported |
| Horizontal Flow Barrier (HFB6) | Supported | Supported |
| Storage (STO6) | Supported | Supported |
| Constant-Head (CHD6) | Supported | Supported |
| Constant-Head Observations (OBS6) | Supported | Supported |
| Well (WEL6) | Supported | Supported |
| Well Observations (OBS6) | Supported | Supported |
| Drain (DRN6) | Supported | Supported |
| Drain Observations (OBS6) | Supported | Supported |
| River (RIV6) | Supported | Supported |
| River Observations (OBS6) | Supported | Supported |
| General-Head-Boundary (GHB6) | Supported | Supported |
| General-Head-Boundary Observations (OBS6) | Supported | Supported |
| Recharge (RCH6) - List-Based | Supported | Supported |
| Recharge (RCH6) - Array-Based | Supported | Supported |
| Recharge Observations (OBS6) | Supported | Supported |
| Evapotranspiration (EVT6) - List-Based | Supported | Supported |
| Evapotranspiration (EVT6) - Array-Based | Supported | Supported |
| Evapotranspiration Observations (OBS6) | Supported | Supported |
| Multi-Aquifer Well (MAW6) | Supported | Supported |
| Multi-Aquifer Well Observations (OBS6) | Supported | Supported |
| Streamflow Routing (SFR6) | Supported | Supported |
| Streamflow Routing Observations (OBS6) | Supported | Supported |
| Lake Package (LAK6) | Supported | Supported |
| Lake Table Input | Supported | Supported |
| Lake Observations (OBS6) | Supported | Supported |
| Unsaturated Zone Flow (UZF6) | Supported | Supported |
| Unsaturated Zone Flow Observations (OBS6) | Supported | Supported |
| Water Mover (MVR6) | Supported | Supported |
| Ghost-Node Correction (GNC6) | Supported | Supported |
| Groundwater Flow Exchange (GWF-GWF) | Supported | Supported |
| Iterative Model Solution (IMS6) | Supported | Supported |
| Timeseries File (TS6) | Supported | Supported |

View File

@ -4204,7 +4204,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at head"
"### Let's look at the simulated head"
]
},
{

View File

@ -5,6 +5,8 @@ try:
import pandas as pd
except:
pd = False
class acdd:
"""Translate ScienceBase global metadata attributes to CF and ACDD
global attributes.
@ -21,11 +23,13 @@ class acdd:
model : flopy model object
"""
def __init__(self, sciencebase_id, model):
self.id = sciencebase_id
self.model = model
self.sciencebase_url = 'https://www.sciencebase.gov/catalog/item/{}'.format(sciencebase_id)
self.sciencebase_url = 'https://www.sciencebase.gov/catalog/item/{}'.format(
sciencebase_id)
self.sb = self.get_sciencebase_metadata(sciencebase_id)
if self.sb is None:
return
@ -46,28 +50,32 @@ class acdd:
self.keywords = [t['name'] for t in self.sb['tags']]
# recommended global attributes
self.naming_authority = 'ScienceBase' # org. that provides the id
#self.history = None # This is a character array with a line for each invocation of a program that has modified the dataset.
self.naming_authority = 'ScienceBase' # org. that provides the id
# self.history = None # This is a character array with a line for each invocation of a program that has modified the dataset.
# Well-behaved generic netCDF applications should append a line containing:
# date, time of day, user name, program name and command arguments.
self.source = model.model_ws # The method of production of the original data.
self.source = model.model_ws # The method of production of the original data.
# If it was model-generated, source should name the model and its version.
#self.processing_level = None # A textual description of the processing (or quality control) level of the data.
#self.comment = None # Miscellaneous information about the data, not captured elsewhere.
# self.processing_level = None # A textual description of the processing (or quality control) level of the data.
# self.comment = None # Miscellaneous information about the data, not captured elsewhere.
# This attribute is defined in the CF Conventions.
self.acknowledgement = self._get_xml_attribute('datacred')
#self.license = None #
#self.standard_name_vocabulary = None
self.date_created = self.sb['provenance']['linkProcess'].get('dateCreated')
# self.license = None #
# self.standard_name_vocabulary = None
self.date_created = self.sb['provenance']['linkProcess'].get(
'dateCreated')
self.creator_name = self.creator.get('name')
self.creator_email = self.creator.get('email')
#self.creator_url = self.sb['webLinks'][0].get('uri')
self.creator_institution = self.creator['organization'].get('displayText')
self.institution = self.creator_institution # also in CF convention for global attributes
# self.creator_url = self.sb['webLinks'][0].get('uri')
self.creator_institution = self.creator['organization'].get(
'displayText')
self.institution = self.creator_institution # also in CF convention for global attributes
self.project = self.sb['title']
self.publisher_name = [d.get('name') for d in self.sb['contacts'] if 'publisher' in d.get('type').lower()][0]
self.publisher_email = self.sb['provenance']['linkProcess'].get('processedBy')
self.publisher_url = 'https://www2.usgs.gov/water/'#self.sb['provenance']['linkProcess'].get('linkReference')
self.publisher_name = [d.get('name') for d in self.sb['contacts'] if
'publisher' in d.get('type').lower()][0]
self.publisher_email = self.sb['provenance']['linkProcess'].get(
'processedBy')
self.publisher_url = 'https://www2.usgs.gov/water/' # self.sb['provenance']['linkProcess'].get('linkReference')
self.geospatial_bounds_crs = 'EPSG:4326'
self.geospatial_lat_min = self.bounds.get('minY')
self.geospatial_lat_max = self.bounds.get('maxY')
@ -75,7 +83,7 @@ class acdd:
self.geospatial_lon_max = self.bounds.get('maxX')
self.geospatial_vertical_min = self.model.dis.botm.array.min()
self.geospatial_vertical_max = self.model.dis.top.array.max()
self.geospatial_vertical_positive = 'up' # assumed to always be up for GW models
self.geospatial_vertical_positive = 'up' # assumed to always be up for GW models
self.time_coverage_start = self.time_coverage.get('start')
self.time_coverage_end = self.time_coverage.get('end')
self.time_coverage_duration = self.time_coverage.get('duration')
@ -96,7 +104,8 @@ class acdd:
@property
def creator(self):
return [d for d in self.sb['contacts'] if 'point of contact' in d['type'].lower()][0]
return [d for d in self.sb['contacts'] if
'point of contact' in d['type'].lower()][0]
@property
def creator_url(self):
@ -139,7 +148,7 @@ class acdd:
tc = {}
for t in ['start', 'end']:
tc[t] = [d.get('dateString') for d in l
if t in d['type'].lower()][0]
if t in d['type'].lower()][0]
if not np.all(self.model.dis.steady) and pd:
# replace with times from model reference
tc['start'] = self.model.dis.start_datetime
@ -223,5 +232,3 @@ class acdd:
text = get_url_text(url,
error_msg='Need an internet connection to get metadata from ScienceBase.')
return ET.fromstring(text)

View File

@ -24,6 +24,7 @@ path = os.path.split(__file__)[0]
with open(path + '/longnames.json') as f:
NC_LONG_NAMES = json.load(f)
class Logger(object):
"""
Basic class for logging events during the linear analysis calculations
@ -135,7 +136,8 @@ class NetCdf(object):
"""
def __init__(self, output_filename, model, time_values=None, z_positive='up',
def __init__(self, output_filename, model, time_values=None,
z_positive='up',
verbose=None, prj=None,
logger=None, forgive=False):
@ -162,15 +164,23 @@ class NetCdf(object):
self.sr.prj = prj
self.shape = (self.model.nlay, self.model.nrow, self.model.ncol)
import dateutil.parser
try:
import dateutil.parser
except:
print('python-dateutil is not installed\n' +
'try pip install python-dateutil')
return None
self.start_datetime = self._dt_str(dateutil.parser.parse(
self.model.start_datetime))
self.logger.warn("start datetime:{0}".format(str(self.start_datetime)))
proj4_str = self.model.sr.proj4_str
if proj4_str is None:
proj4_str = '+init=epsg:4326'
self.log('Warning: model has no coordinate reference system specified. '
'Using default proj4 string: {}'.format(proj4_str))
self.log(
'Warning: model has no coordinate reference system specified. '
'Using default proj4 string: {}'.format(proj4_str))
self.proj4_str = proj4_str
self.grid_units = LENUNI[self.model.sr.lenuni]
self.z_positive = z_positive
@ -700,10 +710,12 @@ class NetCdf(object):
# write some attributes
self.log("setting standard attributes")
self.nc.setncattr("Conventions", "CF-1.6, ACDD-1.3, flopy {}".format(flopy.__version__))
self.nc.setncattr("Conventions", "CF-1.6, ACDD-1.3, flopy {}".format(
flopy.__version__))
self.nc.setncattr("date_created",
datetime.utcnow().strftime("%Y-%m-%dT%H:%M:00Z"))
self.nc.setncattr("geospatial_vertical_positive", "{}".format(self.z_positive))
self.nc.setncattr("geospatial_vertical_positive",
"{}".format(self.z_positive))
min_vertical = np.min(self.zs)
max_vertical = np.max(self.zs)
self.nc.setncattr("geospatial_vertical_min", min_vertical)
@ -742,7 +754,8 @@ class NetCdf(object):
attribs = {"units": "{0} since {1}".format(self.time_units,
self.start_datetime),
"standard_name": "time", "long_name": NC_LONG_NAMES.get("time", "time"),
"standard_name": "time",
"long_name": NC_LONG_NAMES.get("time", "time"),
"calendar": "gregorian",
"_CoordinateAxisType": "Time"}
time = self.create_variable("time", attribs, precision_str="f8",
@ -753,16 +766,19 @@ class NetCdf(object):
# Elevation
sr = self.model.sr
attribs = {"units": sr.units, "standard_name": "elevation",
"long_name": NC_LONG_NAMES.get("elevation", "elevation"), "axis": "Z",
"long_name": NC_LONG_NAMES.get("elevation", "elevation"),
"axis": "Z",
"valid_min": min_vertical, "valid_max": max_vertical,
"positive": self.z_positive}
elev = self.create_variable("elevation", attribs, precision_str="f8",
dimensions=("layer", "y", "x"))
elev[:] = self.zs * sr.length_multiplier # consistent w/ horizontal units
elev[
:] = self.zs * sr.length_multiplier # consistent w/ horizontal units
# Longitude
attribs = {"units": "degrees_east", "standard_name": "longitude",
"long_name": NC_LONG_NAMES.get("longitude", "longitude"), "axis": "X",
"long_name": NC_LONG_NAMES.get("longitude", "longitude"),
"axis": "X",
"_CoordinateAxisType": "Lon"}
lon = self.create_variable("longitude", attribs, precision_str="f8",
dimensions=("y", "x"))
@ -772,7 +788,8 @@ class NetCdf(object):
# Latitude
self.log("creating latitude var")
attribs = {"units": "degrees_north", "standard_name": "latitude",
"long_name": NC_LONG_NAMES.get("latitude", "latitude"), "axis": "Y",
"long_name": NC_LONG_NAMES.get("latitude", "latitude"),
"axis": "Y",
"_CoordinateAxisType": "Lat"}
lat = self.create_variable("latitude", attribs, precision_str="f8",
dimensions=("y", "x"))
@ -780,16 +797,22 @@ class NetCdf(object):
# x
self.log("creating x var")
attribs = {"units": sr.units, "standard_name": "projection_x_coordinate",
"long_name": NC_LONG_NAMES.get("x", "x coordinate of projection"), "axis": "X"}
attribs = {"units": sr.units,
"standard_name": "projection_x_coordinate",
"long_name": NC_LONG_NAMES.get("x",
"x coordinate of projection"),
"axis": "X"}
x = self.create_variable("x_proj", attribs, precision_str="f8",
dimensions=("y", "x"))
dimensions=("y", "x"))
x[:] = sr.xcentergrid
# y
self.log("creating y var")
attribs = {"units": sr.units, "standard_name": "projection_y_coordinate",
"long_name": NC_LONG_NAMES.get("y", "y coordinate of projection"), "axis": "Y"}
attribs = {"units": sr.units,
"standard_name": "projection_y_coordinate",
"long_name": NC_LONG_NAMES.get("y",
"y coordinate of projection"),
"axis": "Y"}
y = self.create_variable("y_proj", attribs, precision_str="f8",
dimensions=("y", "x"))
y[:] = sr.ycentergrid
@ -798,11 +821,13 @@ class NetCdf(object):
attribs = self.sr.crs.grid_mapping_attribs
if attribs is not None:
self.log("creating grid mapping variable")
gmv = self.create_variable(attribs['grid_mapping_name'], attribs, precision_str="f8")
gmv = self.create_variable(attribs['grid_mapping_name'], attribs,
precision_str="f8")
# layer
self.log("creating layer var")
attribs = {"units": "", "standard_name": "layer", "long_name": NC_LONG_NAMES.get("layer", "layer"),
attribs = {"units": "", "standard_name": "layer",
"long_name": NC_LONG_NAMES.get("layer", "layer"),
"positive": "down", "axis": "Z"}
lay = self.create_variable("layer", attribs, dimensions=("layer",))
lay[:] = np.arange(0, self.shape[0])
@ -810,7 +835,8 @@ class NetCdf(object):
# delc
attribs = {"units": self.sr.units.strip('s'),
"long_name": NC_LONG_NAMES.get("delc", "Model grid cell spacing along a column"),
"long_name": NC_LONG_NAMES.get("delc",
"Model grid cell spacing along a column"),
}
delc = self.create_variable('delc', attribs, dimensions=('y',))
delc[:] = self.model.sr.delc[::-1] * self.model.sr.length_multiplier
@ -821,7 +847,8 @@ class NetCdf(object):
# delr
attribs = {"units": self.sr.units.strip('s'),
"long_name": NC_LONG_NAMES.get("delr", "Model grid cell spacing along a row"),
"long_name": NC_LONG_NAMES.get("delr",
"Model grid cell spacing along a row"),
}
delr = self.create_variable('delr', attribs, dimensions=('x',))
delr[:] = self.model.sr.delr[::-1] * self.model.sr.length_multiplier
@ -1020,19 +1047,20 @@ class NetCdf(object):
try:
from numpydoc.docscrape import NumpyDocString
except Exception as e:
raise Exception("NetCdf error importing numpydoc module:\n" + str(e))
raise Exception(
"NetCdf error importing numpydoc module:\n" + str(e))
def startstop(ds):
"""Get just the Parameters section of the docstring."""
start, stop = 0, -1
for i, l in enumerate(ds):
if 'Parameters' in l and '----' in ds[i+1]:
if 'Parameters' in l and '----' in ds[i + 1]:
start = i + 2
if l.strip() in ['Attributes', 'Methods', 'Returns', 'Notes']:
stop = i-1
stop = i - 1
break
if i >= start and '----' in l:
stop = i-2
stop = i - 2
break
return start, stop
@ -1046,12 +1074,12 @@ class NetCdf(object):
k = line.split(':')[0].strip()
stuff[k] = ''
# lines with parameter descriptions
elif k is not None and len(line) > 10: # avoid orphans
elif k is not None and len(line) > 10: # avoid orphans
stuff[k] += line.strip() + ' '
return stuff
# get a list of the flopy classes
#packages = inspect.getmembers(flopy.modflow, inspect.isclass)
# packages = inspect.getmembers(flopy.modflow, inspect.isclass)
packages = [(pp.name[0], pp) for pp in self.model.packagelist]
# get a list of the NetCDF variables
attr = [v.split('_')[-1] for v in self.nc.variables]
@ -1087,4 +1115,3 @@ class NetCdf(object):
return model.sip.hclose, -999
elif model.gmg is not None:
return model.gmg.hclose, model.gmg.rclose

View File

@ -172,7 +172,7 @@ class ObsFiles(FlopyBinaryData):
from ..utils.utils_def import totim_to_datetime
except Exception as e:
raise Exception(
"HydmodObs.get_dataframe() error import pandas: " + \
"ObsFiles.get_dataframe() error import pandas: " + \
str(e))
i0 = 0
i1 = self.data.shape[0]

View File

@ -1,6 +1,5 @@
from __future__ import print_function
import os
import sys
import copy
import numpy as np
from .binaryfile import CellBudgetFile