Skip to content

Commit

Permalink
IAGA issues solved
Browse files Browse the repository at this point in the history
  • Loading branch information
leonro committed Sep 16, 2016
1 parent 6a3d4ab commit 02794d5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion magpy/gui/magpy_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ def OnExportData(self, event):
"""
#print "Stream: ", len(self.stream), len(self.plotstream)
#print "Data: ", self.stream[0].time, self.stream[-1].time, self.plotstream[0].time, self.plotstream[-1].time
print ("Main : ", filenamebegins, filenameends, dateformat, fileformat, coverage, mode)
#print ("Main : ", filenamebegins, filenameends, dateformat, fileformat, coverage, mode)
try:
self.plotstream.write(path,
filenamebegins=filenamebegins,
Expand Down
49 changes: 32 additions & 17 deletions magpy/lib/format_iaga02.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def readIAGA(filename, headonly=False, **kwargs):
"""
starttime = kwargs.get('starttime')
endtime = kwargs.get('endtime')
debugmode = kwargs.get('debugmode')
getfile = True

array = [[] for key in KEYLIST]
Expand Down Expand Up @@ -63,6 +64,8 @@ def readIAGA(filename, headonly=False, **kwargs):

if getfile:
loggerlib.info('Read: %s Format: %s ' % (filename, "IAGA2002"))
dfpos = KEYLIST.index('df')

for line in fh:
if line.isspace():
# blank line
Expand Down Expand Up @@ -136,22 +139,29 @@ def readIAGA(filename, headonly=False, **kwargs):
if it > 2:
varstr += elem[-1]
varstr = varstr[:4]

stream.header["col-x"] = varstr[0].upper()
stream.header["col-y"] = varstr[1].upper()
stream.header["col-z"] = varstr[2].upper()
stream.header["unit-col-x"] = 'nT'
stream.header["unit-col-y"] = 'nT'
stream.header["unit-col-z"] = 'nT'
stream.header["unit-col-f"] = 'nT'
stream.header["col-f"] = 'f'
if varstr.endswith('g'):
stream.header["unit-col-df"] = 'nT'
stream.header["col-df"] = 'G'
stream.header["col-f"] = 'F'
else:
stream.header["col-f"] = 'F'
if varstr in ['dhzf','dhzg']:
stream.header["col-x"] = 'H'
stream.header["col-y"] = 'D'
stream.header["col-z"] = 'Z'
#stream.header["col-x"] = 'H'
#stream.header["col-y"] = 'D'
#stream.header["col-z"] = 'Z'
stream.header["unit-col-y"] = 'deg'
stream.header['DataComponents'] = 'HDZF'
elif varstr in ['ehzf','ehzg']:
stream.header["col-x"] = 'H'
stream.header["col-y"] = 'E'
stream.header["col-z"] = 'Z'
#stream.header["col-x"] = 'H'
#stream.header["col-y"] = 'E'
#stream.header["col-z"] = 'Z'
stream.header['DataComponents'] = 'HEZF'
elif varstr in ['dhif','dhig']:
stream.header["col-x"] = 'I'
Expand All @@ -161,15 +171,15 @@ def readIAGA(filename, headonly=False, **kwargs):
stream.header["unit-col-y"] = 'deg'
stream.header['DataComponents'] = 'IDFF'
elif varstr in ['hdzf','hdzg']:
stream.header["col-x"] = 'H'
stream.header["col-y"] = 'D'
#stream.header["col-x"] = 'H'
#stream.header["col-y"] = 'D'
stream.header["unit-col-y"] = 'deg'
stream.header["col-z"] = 'Z'
#stream.header["col-z"] = 'Z'
stream.header['DataComponents'] = 'HDZF'
else:
stream.header["col-x"] = 'X'
stream.header["col-y"] = 'Y'
stream.header["col-z"] = 'Z'
#stream.header["col-x"] = 'X'
#stream.header["col-y"] = 'Y'
#stream.header["col-z"] = 'Z'
stream.header['DataComponents'] = 'XYZF'

elif headonly:
Expand Down Expand Up @@ -221,15 +231,19 @@ def readIAGA(filename, headonly=False, **kwargs):
if varstr[-1]=='f':
array[4].append(float(elem[6]))
elif varstr[-1]=='g' and varstr=='xyzg':
array[4].append(np.sqrt(row[3]**2+row[4]**2+row[5]**2) - float(row[6]))
array[4].append(np.sqrt(float(row[3])**2+float(row[4])**2+float(row[5])**2) - float(row[6]))
array[dfpos].append(float(row[6]))
elif varstr[-1]=='g' and varstr in ['hdzg','dhzg','ehzg']:
array[4].append(np.sqrt(row[3]**2+row[5]**2) - float(row[6]))
array[4].append(np.sqrt(float(row[3])**2+float(row[5])**2) - float(row[6]))
array[dfpos].append(float(row[6]))
elif varstr[-1]=='g' and varstr in ['dhig']:
array[4].append(float(row[6]))
array[dfpos].append(float(row[6]))
else:
raise ValueError
else:
array[4].append(float('nan'))

except:
if not float(row[6]) >= 88888:
array[4].append(float(row[6]))
Expand Down Expand Up @@ -371,7 +385,8 @@ def writeIAGA(datastream, filename, **kwargs):
except:
pass
line.append(' #{a:<20} {b:<45s}|\n'.format(a='File created by',b='MagPy '+magpyversion))
line.append('DATE TIME DOY %8s %9s %9s %9s |\n' % (datacomp[0],datacomp[1],datacomp[2],datacomp[3]))
iagacode = header.get('StationIAGAcode',"")
line.append('DATE TIME DOY %8s %9s %9s %9s |\n' % (iagacode+datacomp[0],iagacode+datacomp[1],iagacode+datacomp[2],iagacode+datacomp[3]))


try:
Expand Down
6 changes: 3 additions & 3 deletions magpy/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8438,7 +8438,7 @@ def _write_format(self, format_type, filenamebegins, filenameends, coverage, dat
extension = 'BIN'
filenameends = '.'+extension
if format_type == 'IYFV':
if not filenameends:
if not filenameends or filenameends=='.cdf':
head = self.header
code = head.get('StationIAGAcode','')
if not code == '':
Expand All @@ -8455,8 +8455,8 @@ def _write_format(self, format_type, filenamebegins, filenameends, coverage, dat
if not filenamebegins:
code = head.get('StationIAGAcode','')
if not code == '':
filenamebegins = code.upper()
if not filenameends:
filenamebegins = code.lower()
if not filenameends or filenameends=='.cdf':
samprate = float(str(head.get('DataSamplingRate','0')).replace('sec','').strip())
plevel = head.get('DataPublicationLevel',0)
if int(samprate) == 1:
Expand Down

0 comments on commit 02794d5

Please sign in to comment.