Skip to content

Commit

Permalink
We add a function to parse text and extract values.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnemina committed Jan 18, 2019
1 parent 1e1c76f commit 600edc9
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions pyOSOAA/osoaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
from io import open


def ExtractValue(text, reference):
""" This function extracts the value for a given reference string for the
text string given and returns it as a float number
text Text to search
reference Reference string
"""
for a in text:
if reference in a:
res = a.replace(reference, "")

return float(res)


class SEA(object):
""" This is the SEA class which defines the interfaces at the bottom of the
ocean and the interface with the air. """
Expand Down Expand Up @@ -725,6 +738,72 @@ def __init__(self, phi=0, level=5, z=-10, vza=0):
self.vza = vza


class OUTPUTS(object):
""" This class contains the standard and advanced outputs generated by the
OSOAA software"""

class VSVZA(object):
""" This file provides the upwelling radiance field (i.e., the Stokes
paramaters I,Q,U where I is the radiance) versus the viewing zenith
angle, for the given relative azimuth angle (-OSOAA.View.Phi) and
for the given altitude or depth (-OSOAA.View.Z associated to
-OSOAA.View.Level equals 5).
This ascii file is composed of a header which describes in detail
the structure of the file and columns data.
"""

def __init__(self, resroot, filename="LUM_vsVZA.txt"):
""" Filename defined by -OSOAA.ResFile.vsVZA, if none is defined
then LUM_vsVZA.txt is used:
This file provides the upwelling radiance field (i.e., the
Stokes paramaters I,Q,U where I is the radiance) versus the
viewing zenith angle, for the given relative azimuth angle
(-OSOAA.View.Phi) and for the given altitude or depth
(-OSOAA.View.Z associated to -OSOAA.View.Level equals 5).
This ascii file is composed of a header which describes in
detail the structure of the file and columns data.
fulltext Full text of the filename file
vzaless Simulated relative azimuth (degrees) for VZA < 0
(sign convention)
vzamore Simulated relative azimuth (degrees) for VZA > 0
(sign convention)
depth Value of the depth selected for the output (m)
vza Viewing Zenith Angle (deg)
scaang Scattering angle (deg)
I Stokes parameter at output level Z (in sr-1)
normalised to the extraterrestrial solar irradiance
(PI * L(z) / Esun)
refl Reflectance at output level Z (PI * L(z) / Ed(z))
polrate Degree of polarization (%)
lpol Polarized intensity at output level Z (in sr-1)
normalised to the extraterrestrial solar irradiance
(PI * Lpol(z) / Esun)
reflpol Polarized reflectance at output level Z
(PI * Lpol(z) / Ed(z))
"""

# We open the file with the corresponding encoding and convert it
# to a text string.
with open(resroot+"/Standard_outputs/"+filename,
encoding="iso-8859-15") as file:
self.fulltext = file.readlines()
self.vzaless = ExtractValue(self.fulltext,
"for VZA < 0 (sign convention):")
self.vzamore = ExtractValue(self.fulltext,
"for VZA > 0 (sign convention):")
self.depth = ExtractValue(self.fulltext,
"Value of the depth selected for the output (m) :")
text = ""
for line in self.fulltext:
text = text + line
self.tmp = self.fulltext
self.fulltext = text

def __init__(self, resroot):
self.vsvza = self.VSVZA(resroot=resroot)


class OSOAA(object):
""" This class creates the OSOAA objecto which configures and runs the
simulation"""
Expand Down Expand Up @@ -1035,3 +1114,6 @@ def run(self):

# Run script with ksh
os.system("ksh "+self.resroot+"/script.kzh")

# read OUTPUTS
self.outputs = OUTPUTS(self.resroot)

0 comments on commit 600edc9

Please sign in to comment.