In [14]:
import sys
#sys.path.insert(0,'/Users/wildrocker/PmagPy')
sys.path.insert(0,'/Users/ltauxe/Programs/PmagPy/GIT/PmagPy')
from IPython.display import Image
import pandas as pd
import numpy as np
from IPython.display import Image
First let's take a look at the SRM Archive data:
In [ ]:
!IODP_srm_magic.py -loc U1456A -f SRM_data/srmsection-355-U1456-A.csv -Fsa U1456A_MagIC/SRM_er_samples.txt -F U1456A_MagIC/srmsection-355-U1456-A.csv.magic
In [ ]:
!Core_depthplot.py -fsa U1456A_MagIC/SRM_er_samples.txt -fsum U1456A_MagIC/CoreSummary_355_U1456A.csv -f U1456A_MagIC/srmsection-355-U1456-A.csv.magic -LP AF 20 -L -sav -fmt png
In [ ]:
Image(filename='U1456A_m:_LT-AF-Z_core-depthplot.png')
In [2]:
def get_dictitem(In,k,v,flag):
""" returns a list of dictionaries from list In with key,k = value, v . CASE INSENSITIVE # allowed keywords:"""
#try:
if flag=="T":return [dictionary for dictionary in In if dictionary[k]==v] # return that which is
if flag=="F":
return [dictionary for dictionary in In if dictionary[k].lower()!=v.lower()] # return that which is not
if flag=="has":return [dictionary for dictionary in In if v.lower() in dictionary[k].lower()] # return that which is contained
if flag=="not":return [dictionary for dictionary in In if v.lower() not in dictionary[k].lower()] # return that which is not contained
if flag=="eval":
A=[dictionary for dictionary in In if dictionary[k]!=''] # find records with no blank values for key
return [dictionary for dictionary in A if float(dictionary[k])==float(v)] # return that which is
if flag=="min":
A=[dictionary for dictionary in In if dictionary[k]!=''] # find records with no blank values for key
return [dictionary for dictionary in A if float(dictionary[k])>=float(v)] # return that which is greater than
if flag=="max":
A=[dictionary for dictionary in In if dictionary[k]!=''] # find records with no blank values for key
return [dictionary for dictionary in A if float(dictionary[k])<=float(v)] # return that which is less than
#except Exception, err:
#print 'boo-boo'
Load in data and metadata
In [3]:
srm_data=pd.read_csv('SRM_data/srmsection-355-U1456-A.csv',header=0)
disturbance=pd.read_csv('drilling_disturbance.csv',header=0)
sections=pd.read_csv('SectionSummary_355_U1456A.csv',header=0)
sediment=pd.read_csv('Sediment_U1456A.csv',header=0)
sand=sediment.ix[sediment['principal nam']=='sand [Leg210]']
withsand=sediment.ix[sediment['lithology suffix']=='with sand [2014]']
Peel out 20 mT data and take out section ends
In [4]:
srm_list=[srm_data.iloc[line,:].T.to_dict() for line in range(len(srm_data))]
srm_20mT=get_dictitem(srm_list,'Demag level (mT)',20,'eval')
In [5]:
Cores=srm_data.Core.values.tolist()
Core_list=[] # get a list of unique cores.
for core in Cores:
if core not in Core_list:Core_list.append(core)
noends=[]
for core in Core_list:
core_data=get_dictitem(srm_20mT,'Core',core,'T')
Section_list=[] # get a list of unique sections.
for rec in core_data:
if rec['Sect'] not in Section_list:Section_list.append(rec['Sect'])
for section in Section_list:
section_data=get_dictitem(core_data,'Sect',section,'T')
trimmed=section_data[2:-2] # delete top and bottom 2 measurement
for rec in trimmed:noends.append(rec)
print len(srm_20mT),len(noends)
Take out sandy layers
In [6]:
sand_list=[sand.iloc[line,:].T.to_dict() for line in range(len(sand))]
firstpass,nosand=[],[]
for rec in noends:
depth=rec['Depth CSF-A (m)']
sandy=get_dictitem(sand_list,'Top depth',depth,'max')
sandy=get_dictitem(sandy,'Base depth',depth,'min')
if len(sandy)==0:firstpass.append(rec)
withsand_list=[withsand.iloc[line,:].T.to_dict() for line in range(len(withsand))]
for rec in firstpass:
depth=rec['Depth CSF-A (m)']
sandy=get_dictitem(withsand_list,'Top depth',depth,'max')
sandy=get_dictitem(sandy,'Base depth',depth,'min')
if len(sandy)==0:nosand.append(rec)
print len(noends),len(nosand)
Take out 'soupy layers'
In [8]:
soup=disturbance.ix[disturbance['Drilling disturbance type']=='soupy']
soup_list=[soup.iloc[line,:].T.to_dict() for line in range(len(soup))]
nosoup=[]
for rec in nosand:
sample=str(rec['Core'])+rec['Type']+'-'+str(rec['Sect'])
cm=rec['Offset (cm)']
soupy=get_dictitem(soup_list,'Sample',sample,'has')
soupy=get_dictitem(soupy,'Top [cm]',cm,'max')
soupy=get_dictitem(soupy,'Bottom [cm]',cm,'min')
if len(soupy)==0:nosoup.append(rec)
print len(nosand),len(nosoup)
In [9]:
flowin=disturbance.ix[disturbance['Drilling disturbance type']=='basal flow-in']
flow_list=[flowin.iloc[line,:].T.to_dict() for line in range(len(flowin))]
noflowin=[]
for rec in nosoup:
sample=str(rec['Core'])+rec['Type']+'-'+str(rec['Sect'])
cm=rec['Offset (cm)']
flow=get_dictitem(flow_list,'Sample',sample,'has')
flow=get_dictitem(flow,'Top [cm]',cm,'max')
flow=get_dictitem(flow,'Bottom [cm]',cm,'min')
if len(flow)==0:noflowin.append(rec)
print len(nosoup),len(noflowin)
Write it out to a new data file.
In [11]:
out=open('SRM_data/SRM_20_nosand_nosoup_noflow.csv','w')
keys=noflowin[0].keys()
outstring=""
for key in keys:
outstring=outstring+key+','
outstring=outstring.strip(',')+'\n'
out.write(outstring)
for rec in noflowin:
outstring=""
for key in keys:
outstring=outstring+str(rec[key])+','
outstring=outstring.strip(',')+'\n'
out.write(outstring)
out.close()
In [12]:
!IODP_srm_magic.py -loc U1456A -f SRM_data/SRM_20_nosand_nosoup_noflow.csv -Fsa U1456A_MagIC/SRM_er_samples_edited.txt -F U1456A_MagIC/SRM_20_nosand_nosoup_noflow.csv.magic
In [13]:
!Core_depthplot.py -fsa U1456A_MagIC/SRM_er_samples.txt -fsum U1456A_MagIC/CoreSummary_355_U1456A.csv -f U1456A_MagIC/SRM_20_nosand_nosoup_noflow.csv.magic -LP AF 20 -L -sav -fmt png
In [15]:
Image(filename='U1456A_m:_LT-AF-Z_core-depthplot.png')
Out[15]:
In [ ]: