meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
pluginto:calculators [2021/10/26 00:11] – gregbalco | pluginto:calculators [2022/05/03 00:22] (current) – gregbalco | ||
---|---|---|---|
Line 3: | Line 3: | ||
In addition to just responding to browser requests with web pages, the online exposure age calculators are more general "web services." | In addition to just responding to browser requests with web pages, the online exposure age calculators are more general "web services." | ||
- | This page is still incomplete. | + | 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. |
- | ==== Online exposure age calculator for mostly-spallogenic nuclides ==== | + | The URLs for use of the calculators as a web service are < |
+ | |||
+ | ==== 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 11: | Line 13: | ||
^ Field name ^ Description ^ | ^ Field name ^ Description ^ | ||
|text_block|A text string containing input text in [[http:// | |text_block|A text string containing input text in [[http:// | ||
+ | |mlmfile|' | ||
|reportType|' | |reportType|' | ||
|plotFlag|' | |plotFlag|' | ||
|resultType|' | |resultType|' | ||
- | |summaryFlag|' | + | |summary|' |
- | For example, suppose the request has the following field values: | + | For example, suppose the request has the following field values |
|text_block|< | |text_block|< | ||
Line 22: | Line 25: | ||
PH-1 Be-10 quartz 123453 3717 KNSTD; | PH-1 Be-10 quartz 123453 3717 KNSTD; | ||
PH-1 Al-26 quartz 712408 31238 KNSTD;'</ | PH-1 Al-26 quartz 712408 31238 KNSTD;'</ | ||
+ | |mlmfile|' | ||
|reportType|' | |reportType|' | ||
|plotFlag|' | |plotFlag|' | ||
|resultType|' | |resultType|' | ||
- | |summaryFlag|' | + | |summary|' |
- | The response is an XML object. A request with the input data given above will produce this response: | + | The XML response |
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | No diagnostics | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | XML response goes here | ||
The content of the XML response may vary depending on (i) the contents of the ' | The content of the XML response may vary depending on (i) the contents of the ' | ||
Line 36: | Line 93: | ||
**Elements that are always present:** | **Elements that are always present:** | ||
- | < | + | < |
- | Version block | + | < |
+ | |||
+ | < | ||
**Elements that are sometimes present: | **Elements that are sometimes present: | ||
- | Blocks having to do with images generated on the remote server. | + | Blocks having to do with images generated on the remote server. |
- | A block reporting summary data. Present if ' | + | < |
+ | < | ||
+ | </ | ||
- | ** XML object if an error is encountered: | + | These contain URL stubs for plots that have been generated on the remote server. Add ' |
- | If the calculator code encounters an error in the input data it returns an XML object describing the error (a detectable error, that is...some errors can cause it to crash completely and return nothing). Thus, your software may consider checking to make sure an error is not present before trying to process the XML results. Here is an example of an XML error structure. | + | A block reporting summary |
- | Insert error XML | + | < |
- | Nearly | + | < |
+ | <all> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | To get an idea of what is in all these blocks, you can enter the same data into [[http:// | ||
+ | |||
+ | |||
+ | ** 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 < | ||
+ | |||
=== Example of how to do this in MATLAB === | === Example of how to do this in MATLAB === | ||
This example uses the MATLAB ' | This example uses the MATLAB ' | ||
- | Note that the example uses a hokey string matching scheme | + | Note that the example uses a hokey regular expression match to get the needed information out of the XML object. Recent versions of MATLAB have a [[https:// |
- | Insert MATLAB example here. | + | < |
+ | % Text string in version 3 format | ||
+ | |||
+ | text_string = [' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | % URL of service | ||
+ | calc_url = ' | ||
+ | |||
+ | % Script to run | ||
+ | calc_mfile = ' | ||
+ | |||
+ | % Use webread with other inputs as name,value pairs | ||
+ | ages_xml = webread(calc_url,' | ||
+ | ' | ||
+ | |||
+ | % Hokey string matching to extract ages from XML | ||
+ | t10_string = regexp(ages_xml, | ||
+ | t26_string = regexp(ages_xml, | ||
+ | t10_string = t10_string{1}{1}; | ||
+ | t26_string = t26_string{1}{1}; | ||
+ | |||
+ | % Report | ||
+ | disp([' | ||
+ | disp([' | ||
+ | </ | ||
===Example of how to do this in Python === | ===Example of how to do this in Python === | ||
- | This uses urllib and urllib2 | + | The below uses urllib |
+ | |||
+ | < | ||
+ | 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 Be-10 quartz 123453 3717 KNSTD; | ||
+ | PH-1 Al-26 quartz 712408 31238 KNSTD;""" | ||
+ | |||
+ | |||
+ | form_fields = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | # Encode request | ||
+ | form_data = urllib.parse.urlencode(form_fields) | ||
+ | form_data = form_data.encode(' | ||
+ | |||
+ | full_url = " | ||
+ | |||
+ | # Send request | ||
+ | result = urllib.request.urlopen(full_url, | ||
+ | |||
+ | # 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 ==== | ==== Online exposure age calculator for Cl-36 ==== | ||
- | This is structured similarly to the other one. You may get some additional | + | 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 ' |
+ | |||
+ | ^ Field name ^ Description ^ | ||
+ | |text_block|A text string containing input text in valid input form for Cl-36 data. This is explained [[http:// | ||
+ | |mlmfile|' | ||
+ | |reportType|' | ||
+ | |plotFlag|' | ||
+ | |summary|' | ||
+ | |||
+ | The main difference in output is that you will get different | ||
+ | |||
+ | Note: this is only installed on stoneage.ice-d.org. It is not installed on hess.ess.washington.edu, | ||
+ | |||
+ | |||
+ | ==== Online erosion rate calculator for mostly-spallogenic nuclides (not Cl-36) ===== | ||
+ | |||
+ | Again, this is similar to the exposure age calculations described in detail above. The main difference in the input fields is that the ' | ||
+ | |||
+ | ^ 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|' | ||
+ | |reportType|' | ||
+ | |resultType|' | ||
+ | |plotFlag|' | ||
+ | |||
+ | The XML output for erosion rate results is slightly different from the output for exposure-age results. If you send in the same example data from above: | ||
+ | |||
+ | < | ||
+ | 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: | ||
+ | |||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | The main difference is that each result from a different nuclide concentration measurement is in its own < | ||
+ | |||
+ | This only returns results as mass erosion rates with units of g/ | ||
+ | |||
+ | At the moment this doesn' | ||
+ | |||
+ | 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 ' | ||
+ | |||
+ | This requires different input that includes the independent age information. Suitable calibration data in the correct input format can be obtained from http:// | ||
+ | |||
+ | 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: | ||
+ | |||
+ | 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. | ||
+ | |||
+ | < | ||
+ | % This gets calibration data from the ICE-D: | ||
+ | % 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(' | ||
+ | |||
+ | % 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,'< | ||
+ | endindex = strfind(cal_page_html,'</ | ||
+ | cal_input_text = cal_page_html(startindex: | ||
+ | |||
+ | %% Send that to the online calculator and get calibration results | ||
+ | |||
+ | url = " | ||
+ | cal_xml_result = webread(url,' | ||
+ | |||
+ | % 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_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, | ||
+ | value_St_string = temp{1}{1}; | ||
+ | temp = regexp(cal_xml_result, | ||
+ | uncert_St_string = temp{1}{1}; | ||
+ | temp = regexp(cal_xml_result, | ||
+ | value_Lm_string = temp{1}{1}; | ||
+ | temp = regexp(cal_xml_result, | ||
+ | uncert_Lm_string = temp{1}{1}; | ||
+ | temp = regexp(cal_xml_result, | ||
+ | value_LSDn_string = temp{1}{1}; | ||
+ | temp = regexp(cal_xml_result, | ||
+ | uncert_LSDn_string = temp{1}{1}; | ||
+ | |||
+ | %% Now we have the production rate parameters obtained from the calibration | ||
+ | % data. | ||
+ | |||
+ | % Get some data from ICE-D: | ||
- | Example in MATLAB | + | unknowns_page_html = webread(' |
- | ==== Online erosion rate calculator for mostly-spallogenic nuclides ===== | + | % Get the formatted text out of the HTML |
- | I think that's it. | + | |
- | 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. | + | startindex = strfind(unknowns_page_html,'<!-- begin v3 -->< |
+ | endindex = strfind(unknowns_page_html,'</ | ||
+ | unknowns_input_text = unknowns_page_html(startindex: | ||
- | Differences in the XML blocks | ||
- | Example in MATLAB | + | %% Send sample info to exposure age calculator with additional options to |
+ | % force non-default Be-10 production rate | ||
- | ==== Online exposure age calculator for mostly-spallogenic nuclides used for production rate calibration ==== | + | url = " |
- | The (non-Cl-36) exposure age calculator can also be used in reverse mode for production rate calibration. | + | unknowns_xml_result_calibrated = webread(url,' |
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
- | This requires different input that includes | + | %% 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. | ||
- | This also generates different output. | + | unknowns_xml_result_default = webread(url,' |
+ | ' | ||
- | Example in MATLAB that obtains a production rate estimate from calibration data and then uses it to compute | + | % We leave it as an exercise for the student |
+ | % from unknowns_xml_result_calibrated and unknowns_xml_result_default, | ||
+ | % verify that they are different. | ||
+ | </ | ||