meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
pluginto:calculators [2021/10/26 01:04] gregbalcopluginto:calculators [2022/05/03 00:22] (current) gregbalco
Line 5: Line 5:
 For programmatic use, you most likely want the XML output. Nearly all programming languages have XML parsers that you can use to unpack the XML object and get useful information out of it.  For programmatic use, you most likely want the XML output. Nearly all programming languages have XML parsers that you can use to unpack the XML object and get useful information out of it. 
  
-The URLs for use of the calculators as a web service are http://hess.ess.washington.edu/cgi-bin/matweb for the original server at UW, or http://stoneage.ice-d.org/cgi-bin/matweb for the mirror. +The URLs for use of the calculators as a web service are <nowiki>http://hess.ess.washington.edu/cgi-bin/matweb</nowiki> for the original server at UW, or <nowiki>http://stoneage.ice-d.org/cgi-bin/matweb</nowiki> for the mirror.  
  
-This page is incomplete.  +==== Online exposure age calculator for mostly-spallogenic nuclides (not Cl-36) ====
- +
-==== Online exposure age calculator for mostly-spallogenic nuclides ====+
  
 The normal version of the online exposure age calculator computes exposure ages for He-3 in pyroxene or olivine as well as He-3, Be-10, C-14, Ne-21, and Al-26 in quartz. The fields that can be attached to an HTTP request to this calculator are as follows: The normal version of the online exposure age calculator computes exposure ages for He-3 in pyroxene or olivine as well as He-3, Be-10, C-14, Ne-21, and Al-26 in quartz. The fields that can be attached to an HTTP request to this calculator are as follows:
Line 15: Line 13:
 ^ Field name ^ Description ^ ^ Field name ^ Description ^
 |text_block|A text string containing input text in [[http://stoneage.ice-d.org/math/docs/v3/v3_input_explained.html|calculators v3 input format]]| |text_block|A text string containing input text in [[http://stoneage.ice-d.org/math/docs/v3/v3_input_explained.html|calculators v3 input format]]|
-|mlmfile|'age_input+v3' (identifies script to be used on server)|+|mlmfile|'age_input_v3' (identifies script to be used on server)|
 |reportType|'HTML' or 'XML' to control output format| |reportType|'HTML' or 'XML' to control output format|
 |plotFlag|'yes' or 'no' to enable or disable plot generation| |plotFlag|'yes' or 'no' to enable or disable plot generation|
Line 95: Line 93:
 **Elements that are always present:** **Elements that are always present:**
  
-<exposureAgeResult>...</exposureAgeResult> elements. Each one of these blocks contains all the exposure-age results, for all scaling methods, with uncertainties, for one sample. In the example above, there is one sample with two measurements, and resultType was set to 'long', so there are three scaling methods, leading to 18 elements with exposure age results. The element tags contain the nuclide/mineral pair (t10quartz or t26quartz in this case), the scaling method ('St,' 'Lm,' 'LSDn') and what it is ('t' for age, 'del...int' for internal uncertainties, etc.). In this case there is one set of t10quartz results and one set of t2quartz results. If two Be-10 measurements were submitted for the same sample there would be two sets of t10quartz elements. In most cases, the <exposureAgeresult> element will also include normalized nuclide concentrations (the <nNorm...> blocks for each scaling method, which can be used for plotting on a two-nuclide diagram. +<exposureAgeResult>...</exposureAgeResult> elements. Each one of these blocks contains all the exposure-age results, for all scaling methods, with uncertainties, for one sample. In the example above, there is one sample with two measurements, and resultType was set to 'long', so there are three scaling methods. Each scaling method generates an age with internal and external uncertainties, so the exposure age results comprise 2 x 3 x 3 = 18 XML elements. The element tags contain the nuclide/mineral pair (t10quartz or t26quartz in this case), the scaling method ('St,' 'Lm,' 'LSDn') and what it is ('t' for age, 'del...int' for internal uncertainties, etc.). In this case there is one set of t10quartz results and one set of t26quartz results. If two Be-10 measurements were submitted for the same sample there would be two sets of t10quartz elements. In most cases, the <exposureAgeResult> element will also include normalized nuclide concentrations (the <Nnorm...> blocks for each scaling method), which can be used for plotting on a two-nuclide diagram. 
  
 <diagnostics>...</diagnostics> element. Contains either 'no diagnostics' or the error text that you would see in the normal exposure age calculator output.  <diagnostics>...</diagnostics> element. Contains either 'no diagnostics' or the error text that you would see in the normal exposure age calculator output. 
Line 176: Line 174:
 ** XML object if an error is encountered:** ** XML object if an error is encountered:**
  
-If the calculator code encounters an error in the input data, it should return a lot of zeros in the exposure age fields and a description of the error in the diagnostics field. However, there are some errors that will just cause it to fail and return nothing, so there should be a timeout. +If the calculator code encounters an error in the input data, it should return a lot of zeros in the exposure age fields and a description of the error in the diagnostics field. Note that there may be a bug in which the XML tags containing zeros get scrambled, or only the diagnostics element might be present. A sensible fix would be to set an <error>...</error> block that would be easily recognized, but that has not been done. In any case, if you process the XML and you can't find any exposure ages greater than zero, that should be interpreted as an error and one would want to look in the diagnostics block to see what happened. In addition, there are some errors that will just cause the calculator to fail and return nothing, so there should be a timeout. 
    
- 
 === Example of how to do this in MATLAB === === Example of how to do this in MATLAB ===
  
Line 215: Line 212:
 ===Example of how to do this in Python === ===Example of how to do this in Python ===
  
-This uses urllib and urllib2 in Python. Check Python to 3? +The below uses urllib to talk to the calculator web service and then xml.etree to parse the XML. Works in Python 3 
 + 
 +<code> 
 +import urllib.parse 
 +import urllib.request 
 +import xml.etree.ElementTree as et 
 + 
 +# assemble form data 
 + 
 +# s is a string in calculator input format 
 + 
 +s = """PH-1 41.3567 -70.7348 91 std 4.5 2.65 1 0.00008 1999; 
 +    PH-1 Be-10 quartz 123453 3717 KNSTD; 
 +    PH-1 Al-26 quartz 712408 31238 KNSTD;""" 
 + 
 + 
 +form_fields = { 
 + "mlmfile" : "age_input_v3", 
 + "reportType" : "XML", 
 + "resultType" : "long", 
 + "summary" : "no",  
 + "plotFlag" : "no", 
 + "text_block" : s } 
 + 
 +# Encode request 
 +form_data = urllib.parse.urlencode(form_fields) 
 +form_data = form_data.encode('ascii'
 + 
 +full_url = "http://hess.ess.washington.edu/cgi-bin/matweb" 
 + 
 +# Send request 
 +result = urllib.request.urlopen(full_url,form_data) 
 + 
 +# Extract result 
 +result_XML = result.read() 
 + 
 +# Parse XML 
 +tree = et.fromstring(result_XML) 
 + 
 +# Spit out some results 
 +for item in tree[0]: 
 + print(item.tag + ": " + item.text) 
 + 
 + 
 +</code>
  
 ==== Online exposure age calculator for Cl-36 ==== ==== Online exposure age calculator for Cl-36 ====
  
-This is structured similarly to the other oneYou may get some additional plots+This is structured similarly to the aboveThe main differences in input fields are (i) of course the format for the input data is different; (ii) there is no 'resultType' switch to choose not to compute the time-dependent scaling results, and (iii) the value for 'mlmfile' needs to be different to send the request to a different script
  
-Example in MATLAB+^ Field name ^ Description ^ 
 +|text_block|A text string containing input text in valid input form for Cl-36 data. This is explained [[http://stoneage.ice-d.org/math/docs/v3/v3_input_explained.html|here]]. Some examples are [[http://alpine.ice-d.org/site/Jom2018-VS-B|here]] and [[http://calibration.ice-d.org/cds/16|here]].| 
 +|mlmfile|'Cl36_input_v3' (identifies script to be used on server)| 
 +|reportType|'HTML' or 'XML' to control output format| 
 +|plotFlag|'yes' or 'no' to enable or disable plot generation| 
 +|summary|'yes' or 'no' to enable or disable outlier detection, averaging, and summary plot generation|
  
-This is only installed on stoneage.ice-d.org. Not installed on hess.ess.washington.edu+The main difference in output is that you will get different plotsOtherwise the structure of the XML is similar
  
-==== Online erosion rate calculator for mostly-spallogenic nuclides =====+Note: this is only installed on stoneage.ice-d.org. It is not installed on hess.ess.washington.edu, so sending this request to <nowiki>http://hess.ess.washington.edu/cgi-bin/matweb</nowiki> will fail. 
  
-Again, this is structured quite similarly to the exposure-age calculator. In fact, the input is the same. The XML output has some different stuff in it.  
  
-Differences in the XML blocks+==== Online erosion rate calculator for mostly-spallogenic nuclides (not Cl-36) =====
  
-Example in MATLAB+Again, this is similar to the exposure age calculations described in detail above. The main difference in the input fields is that the 'summary' flag is not available. 
  
-==== Online exposure age calculator for mostly-spallogenic nuclides used for production rate calibration ====+^ Field name ^ Description ^ 
 +|text_block|A text string containing input text in valid v3 calculator input form. Note that this input format is the same for both exposure age and erosion rate calculations.| 
 +|mlmfile|'erosion_input_v3' (identifies script to be used on server)| 
 +|reportType|'HTML' or 'XML' to control output format| 
 +|resultType|'short' returns only results with time-constant ('St') scaling; 'long' includes time-dependent scaling results| 
 +|plotFlag|'yes' or 'no' to enable or disable plot generation|
  
-The (non-Cl-36) exposure age calculator can also be used in reverse mode for production rate calibration+The XML output for erosion rate results is slightly different from the output for exposure-age resultsIf you send in the same example data from above:
  
-This requires different input that includes the independent age information+<code> 
 +PH-1 41.3567 -70.7348 91 std 4.5 2.65 1 0.00008 1999; 
 +PH-1 Be-10 quartz 123453 3717 KNSTD; 
 +PH-1 Al-26 quartz 712408 31238 KNSTD; 
 +</code>
  
-This also generates different output. +The XML result is as follows:
  
-Example in MATLAB that obtains a production rate estimate from calibration data and then uses it to compute exposure ages of unknowns.+ 
 +<code> 
 +<calcs_v3_erosion_data> 
 + <erosionRateResult> 
 + <sample_name>PH-1</sample_name> 
 + <sample_density>2.65</sample_density> 
 + <nuclide_result> 
 + <nuclide>N10quartz</nuclide>  
 + <E_gcm2_St>7.0664e-03</E_gcm2_St> 
 + <delE_gcm2_St>2.1517e-04</delE_gcm2_St> 
 + <delE_gcm2_St>6.0417e-04</delE_gcm2_St> 
 + <E_gcm2_Lm>7.3190e-03</E_gcm2_Lm> 
 + <delE_gcm2_Lm>2.2277e-04</delE_gcm2_Lm> 
 + <delE_gcm2_Lm>5.9797e-04</delE_gcm2_Lm> 
 + <E_gcm2_LSDn>6.8713e-03</E_gcm2_LSDn> 
 + <delE_gcm2_LSDn>2.0929e-04</delE_gcm2_LSDn> 
 + <delE_gcm2_LSDn>4.6044e-04</delE_gcm2_LSDn> 
 + </nuclide_result> 
 + <nuclide_result> 
 + <nuclide>N26quartz</nuclide> 
 + <E_gcm2_St>7.7150e-03</E_gcm2_St> 
 + <delE_gcm2_St>3.4519e-04</delE_gcm2_St> 
 + <delE_gcm2_St>8.8852e-04</delE_gcm2_St> 
 + <E_gcm2_Lm>7.9934e-03</E_gcm2_Lm> 
 + <delE_gcm2_Lm>3.5739e-04</delE_gcm2_Lm> 
 + <delE_gcm2_Lm>8.4543e-04</delE_gcm2_Lm> 
 + <E_gcm2_LSDn>7.5758e-03</E_gcm2_LSDn> 
 + <delE_gcm2_LSDn>3.3908e-04</delE_gcm2_LSDn> 
 + <delE_gcm2_LSDn>7.4651e-04</delE_gcm2_LSDn> 
 + </nuclide_result> 
 + </erosionRateResult> 
 + <diagnostics>No diagnostics</diagnostics> 
 + <version> 
 + <wrapper>3.0</wrapper> 
 + <validate>validate_v3_input.m - 3.0</validate> 
 + <erates>3.0</erates> 
 + <muons>3.1</muons> 
 + <consts>2020-08-26</consts> 
 + </version> 
 +</calcs_v3_erosion_data> 
 +</code> 
 + 
 +The main difference is that each result from a different nuclide concentration measurement is in its own <nuclide_result>...</nuclide_result> block within the <erosionRateResult>...</erosionRateResult> block that corresponds to the sample. That is, you have to go down one more level to get the erosion rate results. Of course this is better way to organize it than was originally used in the exposure age XML result. The exposure-age XML should be fixed, but that's a hassle because downstream code that uses it will also have to be fixed.  
 + 
 +This only returns results as mass erosion rates with units of g/cm<sup>2</sup>. This is because that's the thing that you actually measured. It also returns whatever density you input for each sample so that there is enough information within the XML response to convert to linear units (e.g., m/Myr).  
 + 
 +At the moment this doesn't return normalized nuclide concentrations (Nnorm...) for plotting on two-isotope diagrams. That's mainly because it's not really clear how to calculate these for erosion-rate data.  
 + 
 +Note: there is no erosion rate calculation service for Cl-36.  
 + 
 +==== Online exposure age calculator for mostly-spallogenic nuclides (not Cl-36), used for production rate calibration ==== 
 + 
 +The (non-Cl-36) exposure age calculator can also be used in reverse mode for production rate calibration by setting the mlmfile field to 'cal_input_v3'  
 + 
 +This requires different input that includes the independent age information. Suitable calibration data in the correct input format can be obtained from http://calibration.ice-d.org. It also generates different output -- obviously, the XML will contain production rate estimates for each sample, not exposure ages.  
 + 
 +Note: you can only calibrate the production rate for one nuclide at a time. So the input data can only have measurements of one nuclide; otherwise generates an error.  
 + 
 +Here is an example in MATLAB that (i) scrapes calibration data in the appropriate input form from the ICE-D:CALIBRATION website; (ii) sends those data to the web service to generate calibrated production rate parameters; and (iii) uses those calibrated parameters to calculate exposure ages of some unknown-age data.  
 + 
 +This is somewhat complicated but if you are familiar with how the exposure age calculators work, and have gotten through all the previous examples, it should be fairly straightforward.  
 + 
 +<code> 
 +% This gets calibration data from the ICE-D:CALIBRATION website, obtains 
 +% calibrated production rate parameters with it, and uses those calibrated 
 +% production rate parameters to compute exposure ages at an unknown-age 
 +% site.  
 + 
 +clear all; 
 + 
 +% Get some calibration data from the calibration website 
 + 
 +cal_page_html = webread('http://calibration.ice-d.org/cds/1'); 
 + 
 +% Note: this input data must include data for only one nuclide 
 + 
 +% Scrape the formatted text block out of the HTML 
 +startindex = strfind(cal_page_html,'<!-- begin v3 --><pre>') + length('<!-- begin v3 --><pre>'); 
 +endindex = strfind(cal_page_html,'</pre><!-- end v3 -->') - 1; 
 +cal_input_text = cal_page_html(startindex:endindex); 
 + 
 +%% Send that to the online calculator and get calibration results 
 + 
 +url = "http://hess.ess.washington.edu/cgi-bin/matweb"; 
 +cal_xml_result = webread(url,'mlmfile','cal_input_v3','reportType','XML','plotFlag','no','text_block',cal_input_text); 
 + 
 +% Extract calibration information from XML. This is a stupid regexp 
 +% matching scheme. In MATLAB R2021 you can use the proper XML parser.  
 + 
 +% First, get the name of the nuclide -- eventually you will have to send this to the 
 +% calibration code, because you can only do a calibration for one nuclide 
 +% at a time.  
 + 
 +temp = regexp(cal_xml_result,['<nuclide>(.*?)</nuclide>'],'tokens'); 
 +nuclide_string = temp{1}{1}; 
 + 
 +% Get calibrated production rate parameters 
 +% Obviously, the below could be shortened by looping over scaling methods 
 +temp = regexp(cal_xml_result,['<summary_value_St>(.*?)</summary_value_St>'],'tokens'); 
 +value_St_string = temp{1}{1}; 
 +temp = regexp(cal_xml_result,['<summary_uncert_St>(.*?)</summary_uncert_St>'],'tokens'); 
 +uncert_St_string = temp{1}{1}; 
 +temp = regexp(cal_xml_result,['<summary_value_Lm>(.*?)</summary_value_Lm>'],'tokens'); 
 +value_Lm_string = temp{1}{1}; 
 +temp = regexp(cal_xml_result,['<summary_uncert_Lm>(.*?)</summary_uncert_Lm>'],'tokens'); 
 +uncert_Lm_string = temp{1}{1}; 
 +temp = regexp(cal_xml_result,['<summary_value_LSDn>(.*?)</summary_value_LSDn>'],'tokens'); 
 +value_LSDn_string = temp{1}{1}; 
 +temp = regexp(cal_xml_result,['<summary_uncert_LSDn>(.*?)</summary_uncert_LSDn>'],'tokens'); 
 +uncert_LSDn_string = temp{1}{1}; 
 + 
 +%% Now we have the production rate parameters obtained from the calibration 
 +% data.  
 + 
 +% Get some data from ICE-D:ALPINE to calculate the exposure age of 
 + 
 +unknowns_page_html = webread('http://alpine.ice-d.org/site/BST'); 
 + 
 +% Get the formatted text out of the HTML  
 + 
 +startindex = strfind(unknowns_page_html,'<!-- begin v3 --><pre>') + length('<!-- begin v3 --><pre>'); 
 +endindex = strfind(unknowns_page_html,'</pre><!-- end v3 -->') - 1; 
 +unknowns_input_text = unknowns_page_html(startindex:endindex); 
 + 
 + 
 +%% Send sample info to exposure age calculator with additional options to 
 +% force non-default Be-10 production rate 
 + 
 +url = "https://hess.ess.washington.edu/cgi-bin/matweb"; 
 + 
 +unknowns_xml_result_calibrated = webread(url,'mlmfile','age_input_v3','reportType','XML','resultType','long','plotFlag','no',... 
 +    'text_block',unknowns_input_text,... 
 +    'trace_string','nothing here but this is required',... 
 +    'calib_name','nothing here either but this is required too',... 
 +    'nuclide_name',nuclide_string,... 
 +    'P_St',value_St_string,'delP_St',uncert_St_string,... 
 +    'P_Lm',value_Lm_string,'delP_Lm',uncert_Lm_string,... 
 +    'P_LSDn',value_LSDn_string,'delP_LSDn',uncert_LSDn_string); 
 + 
 +%% Here is what it would look like if we omit the additional calibration  
 +% parameters. In this case we get the results using the normal default 
 +% production rate calibration.  
 + 
 +unknowns_xml_result_default = webread(url,'mlmfile','age_input_v3','reportType','XML','resultType','long','plotFlag','no',... 
 +    'text_block',unknowns_input_text); 
 + 
 +% We leave it as an exercise for the student to extract the exposure ages 
 +% from unknowns_xml_result_calibrated and unknowns_xml_result_default, and 
 +% verify that they are different 
 +</code>