Commit 685f4968 authored by Hoek, Steven's avatar Hoek, Steven
Browse files

Because some dependencies were removed from the file requirements.txt, checks...

Because some dependencies were removed from the file requirements.txt, checks and errors have to be built in to indicate that those packages still have to be installed if one wants to make use of these modules.
parent 2bf1dade
# Copyright (c) 2004-2021 WUR, Wageningen
import os.path
import re
import tables
from collections import Sequence
from tables.exceptions import NoSuchNodeError
from .raster import Raster
from .gridenvelope2d import GridEnvelope2D
try:
import tables
from tables.exceptions import NoSuchNodeError
HAS_TABLES = True
except ImportError:
HAS_TABLES = False
raise Exception("If one wants to use the module hdf5raster, he / she needs to install Python package tables!")
__author__ = "Steven B. Hoek"
# Class for reading quick and dirty HDF5 format that can store weather data
# in a raster format in an efficient way, for fast access
class Hdf5Raster(Raster, GridEnvelope2D):
"A raster represented by 2 files, with extensions 'h5' and 'hdr'"
'''A raster represented by 2 files, with extensions "h5" and "hdr"'''
# Constants
DATAFILEXT = "h5";
......@@ -45,7 +50,13 @@ class Hdf5Raster(Raster, GridEnvelope2D):
dataset_name="dummy", group_prefix="row", table_prefix="col", index_format="04i", variables=[], units=[]):
# Initialise
super(Hdf5Raster, self).open(mode);
fpath = os.path.join(self.folder, self.name);
fpath = os.path.join(self.folder, self.name)
# Raise error again if Python package tables is not installed
if not HAS_TABLES:
raise Exception("If one wants to use the module hdf5raster, he / she needs to install Python package tables!")
# Now prepare to read from file or to write it
if (mode[0] == 'w'):
# Open the file
self.datafile = tables.open_file(fpath, 'w');
......
# Copyright (c) 2004-2020 WUR, Wageningen
from .netcdf4envelope2d import Netcdf4Envelope2D;
from .gridenvelope2d import GridEnvelope2D;
from netCDF4 import Dataset;
import os;
# Copyright (c) 2004-2021 WUR, Wageningen
from .netcdf4envelope2d import Netcdf4Envelope2D
from .gridenvelope2d import GridEnvelope2D
import os
try:
from netCDF4 import Dataset
HAS_NETCDF4 = True
except ImportError:
HAS_NETCDF4 = False
raise Exception("If one wants to use the module netcdf4raster, he / she needs to install Python package netCDF4!")
__author__ = "Steven B. Hoek"
......@@ -35,6 +40,12 @@ class Netcdf4Raster(Netcdf4Envelope2D):
def open(self, mode, ncols=1, nrows=1, xll=0, yll=0, cellsize=1, nodatavalue=-9999.0):
# If file does not exist and mode[0] = 'w', create it!
fpath = os.path.join(self.folder, self.name);
# Raise error again if netCDF4 is not installed
if not HAS_NETCDF4:
raise Exception("If one wants to use the module netcdf4raster, he / she needs to install Python package netCDF4!")
# Now prepare to read from file or to write it
if mode[0] == 'a':
if os.path.exists(fpath):
print("About to open file " + fpath + " in append mode");
......
# Copyright (c) 2004-2021 WUR, Wageningen
import os.path
import numpy as np
from .raster import Raster
from .gridenvelope2d import GridEnvelope2D
from .const import constants as const
try:
import numpy as np
HAS_NUMPY = True
except ImportError:
HAS_NUMPY = False
raise Exception("If one wants to use the module numpyraster, he / she needs to install Python package numpy!")
__author__ = "Steven B. Hoek"
......@@ -34,6 +39,11 @@ class NumpyRaster(Raster, GridEnvelope2D):
def open(self, mode, ncols=1, nrows=1, xll=0., yll=0., cellsize=1., nodatavalue=-9999.0):
super(NumpyRaster, self).open(mode);
fpath = os.path.join(self.folder, self.name)
# Raise error again if numpy is not installed
if not HAS_NUMPY:
raise Exception("If one wants to use the module numpyraster, he / she needs to install Python package numpy!")
if (mode[0] == 'w'):
# Open the file
self.datafile = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment