Ejemplo n.º 1
0
    def spectrum(self):
        """ get the global spectrum for the atmosphere """
        output = 'out.spectrum.txt'
        self.run(output=output)

        with _rtm.Working(self) as working:
            try:
                sbout = working.get(output)
            except IOError:
                raise SBdartError("didn't get output %s -- %s" % (output, err))
            try:
                model_spectrum = numpy.genfromtxt(
                    sbout,
                    skip_header=header_lines,
                    dtype=[
                        ('wavelength', numpy.float64),
                        ('filter_function_value', numpy.float64),
                        ('top_downward_flux', numpy.float64),
                        ('top_upward_flux', numpy.float64),
                        ('top_direct_downward_flux', numpy.float64),
                        ('global', numpy.float64),
                        ('upward', numpy.float64),
                        ('direct', numpy.float64),
                    ])
            except StopIteration:
                raise SBdartError("Bad output file for genfromtxt (%d header" \
                                  " rows)" % (header_lines))

        return model_spectrum
Ejemplo n.º 2
0
    def spectrum(self):
        """get the global spectrum for the atmosphere"""
        output = 'out.spectrum.txt'
        self.run()

        with _rtm.Working(self) as working:
            try:
                smout = working.get(output_file)
            except IOError:
                raise SMARTSError("%s: didn't get output %s" %
                                  (working.path, output_file))
            try:
                model_spectrum = numpy.genfromtxt(
                    smout,
                    skip_header=output_headers,
                    dtype=[
                        ('wavelength', numpy.float64),
                        ('direct_normal', numpy.float64),
                        ('diffuse', numpy.float64),
                        ('global', numpy.float64),
                        ('direct', numpy.float64),
                    ])
            except StopIteration:
                raise SMARTSError("%s: Bad output file for genfromtxt "\
                    "(%d header rows)" % (working.path, output_headers))
            model_spectrum['wavelength'] /= 1000
            model_spectrum['direct_normal'] *= 1000
            model_spectrum['diffuse'] *= 1000
            model_spectrum['direct'] *= 1000
            model_spectrum['global'] *= 1000

        return model_spectrum
Ejemplo n.º 3
0
    def run(self):
        """run smarts"""

        with _rtm.Working(self) as working:
            working.link(resources, path=resource_path)
            full_cmd = '%s > %s' % (command, output_log)
            cards = cardify(translate(self))
            working.write(input_file, cards)
            code, err, rcfg = working.run(full_cmd, output_log)

            if code == 127:
                raise SMARTSError("%d: SMARTS Executable not found. Did you"\
                    " install it correctly? stderr:\n%s" % (code, err))
            elif code != 0:
                raise SMARTSError("%s: Execution failed with code %d. "\
                    "stderr:\n%s" % (working.path, code, err))

            # check for errors
            smlog = working.get('smarts295.out.txt')
            for line in smlog:
                if 'ERROR' in line:
                    if '** ERROR #7 ***' in line:
                        raise SunDownError('%s: smarts refuses to work when '
                                           'the sun is down.\n%s' %
                                           (working.path, line))
                    else:
                        raise SMARTSError("%s: smarts no like\n%s" %
                                          (working.path, line))
Ejemplo n.º 4
0
    def run(self, output=default_out):
        """ run sbdart """

        with _rtm.Working(self) as working:
            full_cmd = '%s > %s' % (command, output)
            namelist = namelistify(translate(self))
            working.write(input_file, namelist)
            code, err, rcfg = working.run(full_cmd, output)

            if code == 127:
                raise SBdartError('%d: sbdart executable not found. '\
                    'stderr:\n%s' % (code, err))
            elif "error: namelist block $INPUT not found" in err:
                raise SBdartError('sbdart could not read the &INPUT '\
                    'namelist. stderr:\n%s' % err)
            elif code != 0:
                raise SBdartError("sbdart execution failed. Code %d, '\
                    'stderr:\n%s" % (status, err))
Ejemplo n.º 5
0
 def raw(self, rawfile):
     """ grab a raw file """
     with _rtm.Working(self) as working:
         return working.get(rawfile)