Esempio n. 1
0
 def test_convert(self):
     mf = ModflowOutput(self.resource, config_file=self.wgs84_config_file, exe_name="mf2005", verbose=True)
     assert mf is not None
     output_file = os.path.join(self.output_path, "convert.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
Esempio n. 2
0
def main(name_file, config_file, action, output=None, verbose=None):

    if verbose is True:
        logger.level = logging.DEBUG
    else:
        verbose = False
        logger.level = logging.INFO

    # Try to load files for immediate warnings back to the user
    try:
        with open(name_file) as f:
            f.read()
    except IOError:
        logger.info("Error opening namefile: {!s}".format(name_file))
        return

    try:
        with open(config_file) as f:
            f.read()
    except IOError:
        logger.info("Error opening configuration file: {!s}".format(config_file))
        return

    if action not in ['plot', 'netcdf']:
        logger.error("The 'action' paramter must be 'plot' or 'netcdf'")
        return

    mo = ModflowOutput(name_file, config_file=config_file)
    if action == "plot":
        mo.to_plot()
    else:
        action == "netcdf"
        mo.to_netcdf(output)

    return 0
Esempio n. 3
0
 def test_config_global_attributes(self):
     mf = ModflowOutput(self.resource, config_file=self.wgs84_config_file, exe_name="mf2005", verbose=True)
     assert mf is not None
     output_file = os.path.join(self.output_path, "convert.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     self.assertEquals(nc.id, 'wgs84-config-test')
     self.assertEquals(nc.creator, 'modflow2netcdf')
Esempio n. 4
0
 def test_convert(self):
     mf = ModflowOutput(self.resource,
                        config_file=self.wgs84_config_file,
                        exe_name="mf2005",
                        verbose=True)
     assert mf is not None
     output_file = os.path.join(self.output_path, "convert.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
Esempio n. 5
0
 def test_freyberg_netcdf(self):
     working_dir = os.path.join(self.output_path, "freyberg")
     freyberg_nam = os.path.join(working_dir, "freyberg.nam")
     freyberg_geo = os.path.join(working_dir, "freyberg.geo")
     mf = ModflowOutput(freyberg_nam, config_file=freyberg_geo, exe_name="mf2005", verbose=True, model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(self.output_path, "freyberg", "freyberg.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get("time").units == "days since 1970-01-01T00:00:00Z"
Esempio n. 6
0
 def test_colorado_netcdf(self):
     working_dir = os.path.join(self.output_path, "colorado")
     colorado_nam = os.path.join(working_dir, "mod16_ssfix_wel2.nam")
     colorado_geo = os.path.join(working_dir, "colorado.geo")
     mf = ModflowOutput(colorado_nam, config_file=colorado_geo, exe_name="mf2005", verbose=True, model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(self.output_path, "colorado", "colorado.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get("time").units == "minutes since 1970-01-01T00:00:00Z"
Esempio n. 7
0
 def test_miami_dade_netcdf(self):
     working_dir = os.path.join(self.output_path, "miami-dade")
     miami_nam = os.path.join(working_dir, "UMD_fb.nam")
     miami_geo = os.path.join(working_dir, "miami-dade.geo")
     mf = ModflowOutput(miami_nam, config_file=miami_geo, exe_name="mf2005", verbose=True, model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(working_dir, "miami-dade.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get("time").units == "days since 1996-01-01T00:00:00Z"
Esempio n. 8
0
 def test_carolina_netcdf(self):
     working_dir = os.path.join(self.output_path, "carolina")
     carolina_nam = os.path.join(working_dir, "1-23-07_NOASP.nam")
     carolina_geo = os.path.join(working_dir, "carolina.geo")
     mf = ModflowOutput(carolina_nam, config_file=carolina_geo, exe_name="mf2005", verbose=True, model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(self.output_path, "carolina", "carolina.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get("time").units == "days since 1899-12-31T00:00:00Z"
Esempio n. 9
0
 def test_config_global_attributes(self):
     mf = ModflowOutput(self.resource,
                        config_file=self.wgs84_config_file,
                        exe_name="mf2005",
                        verbose=True)
     assert mf is not None
     output_file = os.path.join(self.output_path, "convert.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     self.assertEquals(nc.id, 'wgs84-config-test')
     self.assertEquals(nc.creator, 'modflow2netcdf')
Esempio n. 10
0
 def test_colorado_netcdf(self):
     working_dir = os.path.join(self.output_path, "colorado")
     colorado_nam = os.path.join(working_dir, "mod16_ssfix_wel2.nam")
     colorado_geo = os.path.join(working_dir, "colorado.geo")
     mf = ModflowOutput(colorado_nam,
                        config_file=colorado_geo,
                        exe_name="mf2005",
                        verbose=True,
                        model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(self.output_path, "colorado", "colorado.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get(
         "time").units == "minutes since 1970-01-01T00:00:00Z"
Esempio n. 11
0
 def test_miami_dade_netcdf(self):
     working_dir = os.path.join(self.output_path, "miami-dade")
     miami_nam = os.path.join(working_dir, "UMD_fb.nam")
     miami_geo = os.path.join(working_dir, "miami-dade.geo")
     mf = ModflowOutput(miami_nam,
                        config_file=miami_geo,
                        exe_name="mf2005",
                        verbose=True,
                        model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(working_dir, "miami-dade.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get(
         "time").units == "days since 1996-01-01T00:00:00Z"
Esempio n. 12
0
 def test_carolina_netcdf(self):
     working_dir = os.path.join(self.output_path, "carolina")
     carolina_nam = os.path.join(working_dir, "1-23-07_NOASP.nam")
     carolina_geo = os.path.join(working_dir, "carolina.geo")
     mf = ModflowOutput(carolina_nam,
                        config_file=carolina_geo,
                        exe_name="mf2005",
                        verbose=True,
                        model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(self.output_path, "carolina", "carolina.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get(
         "time").units == "days since 1899-12-31T00:00:00Z"
Esempio n. 13
0
 def test_freyberg_netcdf(self):
     working_dir = os.path.join(self.output_path, "freyberg")
     freyberg_nam = os.path.join(working_dir, "freyberg.nam")
     freyberg_geo = os.path.join(working_dir, "freyberg.geo")
     mf = ModflowOutput(freyberg_nam,
                        config_file=freyberg_geo,
                        exe_name="mf2005",
                        verbose=True,
                        model_ws=working_dir)
     assert mf is not None
     output_file = os.path.join(self.output_path, "freyberg", "freyberg.nc")
     mf.to_netcdf(output_file=output_file)
     nc = netCDF4.Dataset(output_file)
     assert nc is not None
     assert nc.variables.get(
         "time").units == "days since 1970-01-01T00:00:00Z"
Esempio n. 14
0
def main(name_file, config_file, action, output=None, verbose=None):

    if verbose is True:
        logger.level = logging.DEBUG
    else:
        verbose = False
        logger.level = logging.INFO

    # Try to load files for immediate warnings back to the user
    try:
        with open(name_file) as f:
            f.read()
    except IOError:
        logger.info("Error opening namefile: {!s}".format(name_file))
        return

    try:
        with open(config_file) as f:
            f.read()
    except IOError:
        logger.info(
            "Error opening configuration file: {!s}".format(config_file))
        return

    if action not in ['plot', 'netcdf']:
        logger.error("The 'action' paramter must be 'plot' or 'netcdf'")
        return

    mo = ModflowOutput(name_file, config_file=config_file)
    if action == "plot":
        mo.to_plot()
    else:
        action == "netcdf"
        mo.to_netcdf(output)

    return 0
#define the workspace
freyberg_ws = os.path.join('resources','freyberg')


# In[4]:

# Load MODFLOW output files
from modflow2netcdf.output import ModflowOutput
mf = ModflowOutput('freyberg.nam', config_file=freyberg_config, exe_name="mf2005", model_ws=freyberg_ws, verbose=True)


# In[5]:

# Save NetCDF output
freyberg_output = 'temp_freyberg_output.nc'
_ = mf.to_netcdf(output_file=freyberg_output)


# In[8]:

# Let's check out the NetCDF file we created
import numpy as np
import matplotlib
import matplotlib.cm as cm
import matplotlib.pyplot as plt
get_ipython().magic(u'matplotlib inline')

from mpl_toolkits.mplot3d.axes3d import Axes3D


# In[9]: