'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;'
|
|mlmfile|'age_input_v3'|
|reportType|'XML'|
|plotFlag|'no'|
|resultType|'long'|
|summary|'no'|
The XML response will be as follows:
PH-1
28196
871
2446
27491
828
2287
26948
832
2232
26296
792
2125
28857
892
1963
28110
846
1862
25713
1162
2990
24975
1095
2761
24607
1110
2626
23921
1049
2481
26056
1178
2592
25288
1109
2441
No diagnostics
3.0.2
validate_v3_input.m - 3.0
3.0.2
1A, alpha = 1
2020-08-26
The content of the XML response may vary depending on (i) the contents of the 'summarize' field; (ii) how many samples are present; (iii) whether there are multiple-nuclide data for any samples; and (iv) possibly other factors. It's probably a good idea to try out the expected possibilities that your code is expected to generate to make sure that you are getting the right information out of the XML.
**Elements that are always present:**
http://hess.ess.washington.edu/scratch/splotv3_355173
These contain URL stubs for plots that have been generated on the remote server. Add '.ps', '.gmt', or '.png' to the end to obtain the complete URL for the GMT script, Postscript image, or PNG image. These are the same plots that are normally generated by the online exposure age calculator. Note that they only live on the server for an hour before being deleted.
A block reporting summary data is present if 'summary' is set. Here is an example of what this would look like if you sent the input text from [[http://alpine.ice-d.org/site/BST|here]] with resultType = 'short' and summary = 'yes.'
1.7729e+04
2.1628e+02
1.7737e+04
1.5711e+02
1.9938e+00
9.0000e+00
9.9157e-01
All data: mean 17729; SD 216; chi-squared p-value is 0.9916....Pruned 0 outliers. ...Remaining data have p greater than 0.05; using error-weighted mean. ... Summary value is 17737 +/- 157 (1416)....If this is a moraine, the probability that it is Younger Dryas age is 0.00....The probability it belongs to the Antarctic Cold Reversal is 0.02.
1.7729e+04
2.1628e+02
1.7737e+04
1.5711e+02
1.9963e+00
9.0000e+00
9.9153e-01
1.7737e+04
1.5711e+02
1.4162e+03
1.5582e-02
3.0815e-04
1.7729e+04
2.1628e+02
1.7737e+04
1.5711e+02
1.9938e+00
9.0000e+00
9.9157e-01
All data: mean 17729; SD 216; chi-squared p-value is 0.9916....Pruned 0 outliers. ...Remaining data have p greater than 0.05; using error-weighted mean. ... Summary value is 17737 +/- 157 (1416)....If this is a moraine, the probability that it is Younger Dryas age is 0.00....The probability it belongs to the Antarctic Cold Reversal is 0.02.
1.7729e+04
2.1628e+02
1.7737e+04
1.5711e+02
1.9963e+00
9.0000e+00
9.9153e-01
1.7737e+04
1.5711e+02
1.4162e+03
1.5582e-02
3.0815e-04
To get an idea of what is in all these blocks, you can enter the same data into [[http://stoneage.ice-d.org/math/v3/v3_age_in.html|this page]] with the 'These data are from a single landform' box checked, and match the XML up with the grouped and labeled results. Setting summary to 'yes' and plotFlag to 'yes' should return URLs for the camel plots.
** 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. 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
% Text string in version 3 format
text_string = ['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;'];
% URL of service
calc_url = 'http://hess.ess.washington.edu/cgi-bin/matweb';
% Script to run
calc_mfile = 'age_input_v3';
% Use webread with other inputs as name,value pairs
ages_xml = webread(calc_url,'mlmfile',calc_mfile,'text_block',text_string, ...
'reportType','XML','resultType','long','plotFlag','no','summary','no');
% Hokey string matching to extract ages from XML
t10_string = regexp(ages_xml,['(.*?) '],'tokens');
t26_string = regexp(ages_xml,['(.*?) '],'tokens');
t10_string = t10_string{1}{1};
t26_string = t26_string{1}{1};
% Report
disp(['Be-10 exposure age is ' sprintf('%0.0f',str2num(t10_string))])
disp(['Al-26 exposure age is ' sprintf('%0.0f',str2num(t26_string))])
===Example of how to do this in Python ===
The below uses urllib to talk to the calculator web service and then xml.etree to parse the XML. Works in Python 3.
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)
==== Online exposure age calculator for Cl-36 ====
This is structured similarly to the above. The 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.
^ 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|
The main difference in output is that you will get different plots. Otherwise the structure of the XML is similar.
Note: this is only installed on stoneage.ice-d.org. It is not installed on hess.ess.washington.edu, so sending this request to
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;
The XML result is as follows:
PH-1
2.65
N10quartz
7.0664e-03
2.1517e-04
6.0417e-04
7.3190e-03
2.2277e-04
5.9797e-04
6.8713e-03
2.0929e-04
4.6044e-04
N26quartz
7.7150e-03
3.4519e-04
8.8852e-04
7.9934e-03
3.5739e-04
8.4543e-04
7.5758e-03
3.3908e-04
7.4651e-04
No diagnostics
3.0
validate_v3_input.m - 3.0
3.0
3.1
2020-08-26
The main difference is that each result from a different nuclide concentration measurement is in its own
% 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,'') + length('');
endindex = strfind(cal_page_html,'
') - 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,['(.*?) '],'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,['(.*?) '],'tokens');
value_St_string = temp{1}{1};
temp = regexp(cal_xml_result,['(.*?) '],'tokens');
uncert_St_string = temp{1}{1};
temp = regexp(cal_xml_result,['(.*?) '],'tokens');
value_Lm_string = temp{1}{1};
temp = regexp(cal_xml_result,['(.*?) '],'tokens');
uncert_Lm_string = temp{1}{1};
temp = regexp(cal_xml_result,['(.*?) '],'tokens');
value_LSDn_string = temp{1}{1};
temp = regexp(cal_xml_result,['(.*?) '],'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,'') + length('');
endindex = strfind(unknowns_page_html,'
') - 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.