Skip to content

Commit

Permalink
fix netcdf typing
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjwilson committed Mar 10, 2021
1 parent 3d31056 commit 5cb090a
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 82 deletions.
56 changes: 28 additions & 28 deletions nctoolkit/add_etc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def arithall(self, stat="divc", x=None):

def operation(self, method="mul", ff=None, var=None):
"""
Method to add, subtract etc. a NetCDF file from another one
Method to add, subtract etc. a netCDF file from another one
This is used by add etc.
"""

Expand Down Expand Up @@ -128,11 +128,11 @@ def operation(self, method="mul", ff=None, var=None):
def multiply(self, x=None, var=None):
"""
Multiply a dataset
This will multiply a dataset by a constant, another dataset or a NetCDF file.
This will multiply a dataset by a constant, another dataset or a netCDF file.
Parameters
------------
x: int, float, DataSet or NetCDF file
An int, float, single file dataset or NetCDF file to multiply the dataset by.
x: int, float, DataSet or netCDF file
An int, float, single file dataset or netCDF file to multiply the dataset by.
If multiplying by a dataset or single file there must only be a single variable
in it, unless var is supplied. The grids must be the same.
var: str
Expand All @@ -152,7 +152,7 @@ def multiply(self, x=None, var=None):
Grids in the datasets must match. Multiplication will occur in matching timesteps in data1 and data2. If there is only 1 timestep in data2, then
the data from that timestep in data2 will multiply the data in all timesteps in data1.
Multiplying a dataset by the data from another NetCDF file will work in the same way:
Multiplying a dataset by the data from another netCDF file will work in the same way:
>>> data1.multiply("example.nc")
"""
Expand All @@ -162,8 +162,8 @@ def multiply(self, x=None, var=None):
arithall(self, stat="mulc", x=x)
return None

# 2: dataset or NetCDF file multiplication
# get the NetCDF file(s)
# 2: dataset or netCDF file multiplication
# get the netCDF file(s)
if "api.DataSet" in str(type(x)):
x.run()
if len(x) == 1:
Expand All @@ -182,12 +182,12 @@ def multiply(self, x=None, var=None):
def subtract(self, x=None, var=None):
"""
Subtract from a dataset
This will subtract a constant, another dataset or a NetCDF file from the dataset.
This will subtract a constant, another dataset or a netCDF file from the dataset.
Parameters
------------
x: int, float, DataSet or NetCDF file
An int, float, single file dataset or NetCDF file to subtract from the dataset.
If a dataset or NetCDF is supplied this must only have one variable,
x: int, float, DataSet or netCDF file
An int, float, single file dataset or netCDF file to subtract from the dataset.
If a dataset or netCDF is supplied this must only have one variable,
unless var is provided. The grids must be the same.
var: str
A variable in the x to use for the operation
Expand All @@ -206,7 +206,7 @@ def subtract(self, x=None, var=None):
Grids in the datasets must match. Division will occur in matching timesteps in data1 and data2 if there are matching timesteps. If there is only 1 timestep in data2, then
the data from that timestep in data2 will be subtracted from the data in all timesteps in data1.
Subtracting of the data from another NetCDF file will work in the same way:
Subtracting of the data from another netCDF file will work in the same way:
>>> data1.subtract("example.nc")
"""
Expand All @@ -216,8 +216,8 @@ def subtract(self, x=None, var=None):
arithall(self, stat="subc", x=x)
return None

# 2: dataset or NetCDF file subtraction
# get the NetCDF file(s)
# 2: dataset or netCDF file subtraction
# get the netCDF file(s)
if "api.DataSet" in str(type(x)):
x.run()
if len(x) == 1:
Expand All @@ -236,12 +236,12 @@ def subtract(self, x=None, var=None):
def add(self, x=None, var=None):
"""
Add to a dataset
This will add a constant, another dataset or a NetCDF file to the dataset.
This will add a constant, another dataset or a netCDF file to the dataset.
Parameters
------------
x: int, float, DataSet or NetCDF file
An int, float, single file dataset or NetCDF file to add to the dataset.
If a dataset or NetCDF file is supplied, this must have only one variable,
x: int, float, DataSet or netCDF file
An int, float, single file dataset or netCDF file to add to the dataset.
If a dataset or netCDF file is supplied, this must have only one variable,
unless var is provided. The grids must be the same.
var: str
A variable in the x to use for the operation
Expand All @@ -260,7 +260,7 @@ def add(self, x=None, var=None):
Grids in the datasets must match. Addition will occur in matching timesteps in data1 and data2. If there is only 1 timestep in data2, then
the data from that timestep will be added to the data in all data1 time steps.
Adding the data from another NetCDF file will work in the same way:
Adding the data from another netCDF file will work in the same way:
>>> data1.add("example.nc")
Expand All @@ -272,8 +272,8 @@ def add(self, x=None, var=None):
arithall(self, stat="addc", x=x)
return None

# 2: dataset or NetCDF file addition
# get the NetCDF file(s)
# 2: dataset or netCDF file addition
# get the netCDF file(s)
if "api.DataSet" in str(type(x)):
x.run()
if len(x) == 1:
Expand All @@ -292,12 +292,12 @@ def add(self, x=None, var=None):
def divide(self, x=None, var=None):
"""
Divide the data
This will divide the dataset by a constant, another dataset or a NetCDF file.
This will divide the dataset by a constant, another dataset or a netCDF file.
Parameters
------------
x: int, float, DataSet or NetCDF file
An int, float, single file dataset or NetCDF file to divide the dataset by.
If a dataset or NetCDF file is supplied, this must have only one variable,
x: int, float, DataSet or netCDF file
An int, float, single file dataset or netCDF file to divide the dataset by.
If a dataset or netCDF file is supplied, this must have only one variable,
unless var is provided. The grids must be the same.
var: str
A variable in the x to use for the operation
Expand All @@ -316,7 +316,7 @@ def divide(self, x=None, var=None):
Grids in the datasets must match. Division will occur in matching timesteps in data1 and data2. If there is only 1 timestep in data2, then
the data from that timeste in data2 will divided the data in all data1 time steps.
Adding the data from another NetCDF file will work in the same way:
Adding the data from another netCDF file will work in the same way:
>>> data1.divide("example.nc")
"""
Expand All @@ -326,8 +326,8 @@ def divide(self, x=None, var=None):
arithall(self, stat="divc", x=x)
return None

# 2: dataset or NetCDF file division
# get the NetCDF file(s)
# 2: dataset or netCDF file division
# get the netCDF file(s)
if "api.DataSet" in str(type(x)):
x.run()
if len(x) == 1:
Expand Down
10 changes: 5 additions & 5 deletions nctoolkit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import urllib.request
import platform

from NetCDF4 import Dataset
from netCDF4 import Dataset

from nctoolkit.cleanup import cleanup, clean_all, temp_check
from nctoolkit.flatten import str_flatten
Expand Down Expand Up @@ -370,12 +370,12 @@ def file_size(file_path):

def open_data(x=[], checks=False, **kwargs):
"""
Read NetCDF data as a DataSet object
Read netCDF data as a DataSet object
Parameters
---------------
x : str or list
A string or list of NetCDF files or a single url. The function will check the
A string or list of netCDF files or a single url. The function will check the
files exist. If x is not a list, but an iterable it will be converted to a list.
If a *.nc style wildcard is supplied, open_data will use all files available.
By default an empty dataset is created, ie. using open_data() will create an empty
Expand Down Expand Up @@ -656,7 +656,7 @@ def open_thredds(x=None, wait=None, checks=False):

def open_url(x=None, ftp_details=None, wait=None, file_stop=None):
"""
Read NetCDF data from a url as a DataSet object
Read netCDF data from a url as a DataSet object
Parameters
---------------
Expand Down Expand Up @@ -863,7 +863,7 @@ def cor_space(x=None, y=None):

class DataSet(object):
"""
A modifiable ensemble of NetCDF files
A modifiable ensemble of netCDF files
"""

def __init__(self, start=""):
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def cor(self, var1=None, var2=None, method="fld"):
if len([x for x in get_safe() if x == ff]) > 1:
remove_safe(ff)

# tidy up the attributes of the NetCDF file in the dataset
# tidy up the attributes of the netCDF file in the dataset
self.rename({var1: "cor"})
self.set_units({"cor": "-"})
self.set_longnames({"cor": f"Correlation between {var1} & {var2}"})
Expand Down
4 changes: 2 additions & 2 deletions nctoolkit/create_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_ensemble(path="", recursive=True):
Parameters
-------------
path: str
The directory to search for NetCDF files
The directory to search for netCDF files
recursive : boolean
True/False depending on whether you want to search the path recursively.
Defaults to True.
Expand All @@ -24,7 +24,7 @@ def create_ensemble(path="", recursive=True):
Examples
------------
If you wanted to recursively find all NetCDF files available in a directory "data", you would do this:
If you wanted to recursively find all netCDF files available in a directory "data", you would do this:
>>> import nctoolkit as nc
>>> nc.create_ensemble("data")
Expand Down
10 changes: 5 additions & 5 deletions nctoolkit/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def format(self, ext=None):
-------------
ext: str
New format. Must be one of "nc", "nc1", "nc2", "nc4" and "nc5" .
NetCDF = nc1
NetCDF version 2 (64-bit offset) = nc2/nc
NetCDF4 (HDF5) = nc4
NetCDF4-classi = nc4c
NetCDF version 5 (64-bit data) = nc5
netCDF = nc1
netCDF version 2 (64-bit offset) = nc2/nc
netCDF4 (HDF5) = nc4
netCDF4-classi = nc4c
netCDF version 5 (64-bit data) = nc5
"""

if ext is None:
Expand Down
4 changes: 2 additions & 2 deletions nctoolkit/mergers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def merge(self, match=["year", "month", "day"]):
Parameters
-------------
match: list, str
a list or str stating what must match in the NetCDF files.
a list or str stating what must match in the netCDF files.
Defaults to year/month/day. This list must be some combination of
year/month/day. An error will be thrown if the elements of time in match
do not match across all NetCDF files. The only exception is if there is a
do not match across all netCDF files. The only exception is if there is a
single date file in the ensemble.
"""

Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/meridonials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def zonstat(self, stat="mean"):
"""Method to calculate the meridonial statistic from a NetCDF file"""
"""Method to calculate the meridonial statistic from a netCDF file"""
for ff in self:
if is_curvilinear(ff):
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def regrid(self, grid=None, method="bil", recycle = False):
Parameters
-------------
grid : nctoolkit.DataSet, pandas data frame or NetCDF file
grid : nctoolkit.DataSet, pandas data frame or netCDF file
The grid to remap to
method : str
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def nc_remove(ff, deep=False):
"""
Method for removing NetCDF files.
Method for removing netCDF files.
This is ultra-safe and makes sure the file is in the tmp directory before deleting
Parameters
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/rollstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def rollstat(self, window=None, stat="mean"):
"""Method to calculate the monthly statistic from a NetCDF file"""
"""Method to calculate the monthly statistic from a netCDF file"""
# check window supplied is valid

if window is None:
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/setters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def set_date(self, year=None, month=None, day=None, base_year=1900):
day : int
The day
base_year : int
The base year for time creation in the NetCDF. Defaults to 1900.
The base year for time creation in the netCDF. Defaults to 1900.
"""

if year is None:
Expand Down
12 changes: 6 additions & 6 deletions nctoolkit/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def nc_times(ff):
"""
Function to return times available in a NetCDF file
Function to return times available in a netCDF file
"""

cdo_result = subprocess.run(
Expand All @@ -21,7 +21,7 @@ def nc_times(ff):

def nc_format(ff):
"""
Function to return the format of a NetCDF file
Function to return the format of a netCDF file
"""

cdo_result = subprocess.run(
Expand All @@ -39,7 +39,7 @@ def nc_format(ff):

def nc_levels(ff):
"""
Function to get the depths available in a NetCDF file
Function to get the depths available in a netCDF file
"""

cdo_result = subprocess.run(
Expand All @@ -60,7 +60,7 @@ def nc_levels(ff):

def nc_years(ff):
"""
Function to get the years available in a NetCDF file
Function to get the years available in a netCDF file
"""

all_years = []
Expand All @@ -80,7 +80,7 @@ def nc_years(ff):

def nc_variables(ff):
"""
Function to get the variables available in a NetCDF file
Function to get the variables available in a netCDF file
"""

cdo_result = subprocess.run(
Expand All @@ -97,7 +97,7 @@ def nc_variables(ff):

def nc_months(ff):
"""
Function to get the months available in a NetCDF file
Function to get the months available in a netCDF file
"""

cdo_result = subprocess.run(
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/strip_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def strip_variables(self, vars=None):
"""
Remove any variables, such as bnds etc., from variables.
This should probably only be done at the end of a processing chain before converting to a dataframe etc., as it is stripping away critical info for NetCDF operations.
This should probably only be done at the end of a processing chain before converting to a dataframe etc., as it is stripping away critical info for netCDF operations.
Parameters
-------------
Expand Down
2 changes: 1 addition & 1 deletion nctoolkit/temporals.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def dailystat(self, stat="mean"):


def monstat(self, stat="mean"):
"""Method to calculate the monthly statistic from a NetCDF file"""
"""Method to calculate the monthly statistic from a netCDF file"""
cdo_command = f"cdo -mon{stat}"

run_this(cdo_command, self, output="ensemble")
Expand Down
Loading

0 comments on commit 5cb090a

Please sign in to comment.