Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SPC decoder to handle SPC Mesoanalysis text files #161

Open
wants to merge 2 commits into
base: andover
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions sharppy/io/spc_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ def _parse(self):
## create the plot title
data_header = data[title_idx + 1].split()
location = data_header[0]
time = datetime.strptime(data_header[1][:11], '%y%m%d/%H%M')
## Is this the standard SPC text format header?
try:
time = datetime.strptime(data_header[1][:11], '%y%m%d/%H%M')
## If it's not, then it's probably one of the SPC archive files with a different
## header format. This is probably not the greatest way to handle this, as SPC
## isn't exactly consistent with all of their archive text files. But this seems
## to do the trick.
except:
data_header = data[title_idx + 2].split()
time = datetime.strptime(data_header[0], "%y%m%d/%H%M")

if len(data_header) > 2:
lat, lon = data_header[2].split(',')
lat = float(lat)
Expand All @@ -49,13 +59,28 @@ def _parse(self):
## put it all together for StringIO
full_data = '\n'.join(data[start_idx : finish_idx][:])

if not is_py3():
sound_data = StringIO( full_data )
else:
sound_data = BytesIO( full_data.encode() )
## read the data into arrays.
## The SPC Mesoanalysis soundings contain a field
## for Omega - this is the brute-force way of checking
## for that. If the omega field isn't present, it's
## probably an observed file.
try:
if not is_py3():
sound_data = StringIO( full_data )
else:
sound_data = BytesIO( full_data.encode() )

p, h, T, Td, wdir, wspd, omeg = np.genfromtxt( sound_data, delimiter=',', comments="%", unpack=True )

## If Omega isn't present, then try again.
except:
if not is_py3():
sound_data = StringIO( full_data )
else:
sound_data = BytesIO( full_data.encode() )
p, h, T, Td, wdir, wspd = np.genfromtxt( sound_data, delimiter=',', comments="%", unpack=True )
omeg = None

## read the data into arrays
p, h, T, Td, wdir, wspd = np.genfromtxt( sound_data, delimiter=',', comments="%", unpack=True )
# idx = np.argsort(p, kind='mergesort')[::-1] # sort by pressure in case the pressure array is off.

pres = p #[idx]
Expand All @@ -71,7 +96,7 @@ def _parse(self):

# Force latitude to be 35 N. Figure out a way to fix this later.
prof = profile.create_profile(profile='raw', pres=pres, hght=hght, tmpc=tmpc, dwpc=dwpc,
wdir=wdir, wspd=wspd, location=location, date=time, latitude=lat, missing=-9999.00)
wdir=wdir, wspd=wspd, omeg=omeg, location=location, date=time, latitude=lat, missing=-9999.00)

prof_coll = prof_collection.ProfCollection(
{'':[ prof ]},
Expand Down
2 changes: 1 addition & 1 deletion sharppy/sharptab/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def qc(val):
#print(now, self.date)
user = getpass.getuser()
snd_file.write("%TITLE%\n")
#snd_file.write("%s %s\n Saved by user: %s on %s UTC\n" % (snd_loc, self.date.strftime("%y%m%d/%H%M"), user, now.strftime('%Y%m%d/%H%M')))
snd_file.write("%s %s\n Saved by user: %s on %s UTC\n" % (snd_loc, self.date.strftime("%y%m%d/%H%M"), user, now.strftime('%Y%m%d/%H%M')))
snd_file.write(" LEVEL HGHT TEMP DWPT WDIR WSPD\n")
snd_file.write("-------------------------------------------------------------------\n")
snd_file.write("%RAW%\n")
Expand Down