예제 #1
0
 def test_carolina_plot(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
     mf.to_plot(variable='heads', colormap=matplotlib.cm.GnBu).show()
예제 #2
0
 def test_plot(self):
     mf = ModflowOutput(self.resource,
                        config_file=self.wgs84_config_file,
                        exe_name="mf2005",
                        verbose=True)
     assert mf is not None
     mf.to_plot().show()
예제 #3
0
 def test_miami_dade_plot(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
     mf.to_plot(variable='heads', colormap=matplotlib.cm.GnBu).show()
예제 #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
예제 #5
0
 def test_colorado_plot(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
     mf.to_plot(variable='heads', level=4).show()
예제 #6
0
 def test_freyberg_plot(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
     mf.to_plot(variable='flow_right_face_centered', colormap=matplotlib.cm.GnBu).show()
예제 #7
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
예제 #8
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')
예제 #9
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
예제 #10
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')
예제 #11
0
 def test_miami_dade_plot(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
     mf.to_plot(variable='heads', colormap=matplotlib.cm.GnBu).show()
예제 #12
0
 def test_carolina_plot(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
     mf.to_plot(variable='heads', colormap=matplotlib.cm.GnBu).show()
예제 #13
0
 def test_colorado_plot(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
     mf.to_plot(variable='heads', level=4).show()
예제 #14
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"
예제 #15
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"
예제 #16
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"
예제 #17
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"
예제 #18
0
 def test_freyberg_plot(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
     mf.to_plot(variable='flow_right_face_centered',
                colormap=matplotlib.cm.GnBu).show()
예제 #19
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"
예제 #20
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"
예제 #21
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"
예제 #22
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"
예제 #23
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
예제 #24
0
 def test_plot(self):
     mf = ModflowOutput(self.resource, config_file=self.wgs84_config_file, exe_name="mf2005", verbose=True)
     assert mf is not None
     mf.to_plot().show()
예제 #25
0
 def test_bad_config_file(self):
     with self.assertRaises(ValueError):
         ModflowOutput(self.resource,
                       config_file=self.bad_config_file,
                       exe_name="mf2005",
                       verbose=True)
    print f.read()


# In[2]:

# Freyberg NAM file
freyberg_nam = '../../modflow2netcdf/tests/resources/freyberg/freyberg.nam'
with open(freyberg_nam) as f:
    print f.read()


# In[3]:

# Load MODFLOW output files
from modflow2netcdf.output import ModflowOutput
mf = ModflowOutput(freyberg_nam, config_file=freyberg_config, exe_name="mf2005", verbose=False)


# In[4]:

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


# In[5]:

# Load NetCDF output
import netCDF4
nc = netCDF4.Dataset(freyberg_output)
freyberg_nam = os.path.join('resources','freyberg','freyberg.nam')
with open(freyberg_nam) as f:
    print f.read()


# In[3]:

#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