diff --git a/src/tradssat/tmpl/vals.py b/src/tradssat/tmpl/vals.py index 53f5ad1..33f8a27 100644 --- a/src/tradssat/tmpl/vals.py +++ b/src/tradssat/tmpl/vals.py @@ -391,8 +391,10 @@ def write(self, lines): """ self.check_dims() self.check_vals() - - lines.append('@' + ''.join([vr.write() for vr in self])) + headers = ''.join([vr.write() for vr in self]) + # Hack for soil SALB header + headers = '@' + headers[1:] if headers.startswith(" SLB") else '@' + headers + lines.append(headers) for i in range(self.n_data()): written = [vr.write(i) for vr in self] for i, (x, vr) in enumerate(zip(list(written), self)): @@ -444,6 +446,15 @@ class VariableValue(object): """ def __init__(self, var, val): + """ + + Parameters + ---------- + var : Variable object + Class for all variable types + val : str, int, or floats + Value pertaining to variable + """ self.changed = False diff --git a/src/tradssat/tmpl/var.py b/src/tradssat/tmpl/var.py index 7ad127e..1f35535 100644 --- a/src/tradssat/tmpl/var.py +++ b/src/tradssat/tmpl/var.py @@ -12,6 +12,27 @@ class Variable(object): type_ = None def __init__(self, name, size, spc, header_fill, float_r, miss, sect, info): + """ + + Parameters + ---------- + name : str + A DSSAT variable name + size : int + Allowed maximum width of the variable + spc : int + Number of required leading spaces + header_fill : str + A character with which to fill a header + float_r : bool + Flag to indicate whether a value is a float + miss : str + A substitute to indicate missing data, ie '-99' + sect : str + A section or subsection to which a variable corresponds + info : str + Description for the name + """ self.name = name self.size = size self.spc = spc @@ -33,8 +54,8 @@ def write(self, val=None): txt = self._write(val) if self.float_r: - return ' ' * self.spc + txt.ljust(self.size, fill) - return ' ' * self.spc + txt.rjust(self.size, fill) + return ' ' * self.spc + txt.rjust(self.size, fill) + return ' ' * self.spc + txt.ljust(self.size, fill) def check_val(self, val): raise NotImplementedError @@ -75,7 +96,7 @@ class NumericVar(Variable): def __init__(self, name, size, lims, spc, header_fill, miss, sect, info): - super().__init__(name, size, spc, header_fill, sect=sect, float_r=True, miss=miss, info=info) + super().__init__(name, size=size, spc=spc, header_fill=header_fill, sect=sect, float_r=True, miss=miss, info=info) if lims is None: lims = (-np.inf, np.inf) @@ -103,7 +124,30 @@ class FloatVar(NumericVar): type_ = float def __init__(self, name, size, dec, lims=None, spc=1, sect=None, header_fill=' ', miss='-99', info=''): - super().__init__(name, size, lims, spc, header_fill, miss=miss, sect=sect, info=info) + """ + + Parameters + ---------- + name : str + A DSSAT variable name + size : int + Allowed maximum width of the variable + dec : int + The number of allowed decimal spaces + lims : tuple, optional + Describes the minimum and maximum boundaries for a value, by default None + spc : int, optional + Number of required leading spaces, by default 1 + sect : str, optional + A section or subsection to which a variable corresponds, by default None + header_fill : str, optional + Character with which to fill width of the field, by default ' ' + miss : str, optional + A substitute to indicate missing data, by default '-99' + info : str, optional + Description for the name, by default '' + """ + super().__init__(name, size=size, lims=lims, spc=spc, header_fill=header_fill, miss=miss, sect=sect, info=info) self.dec = dec def _write(self, val):