Package: pygeoroc
pygeorocPython library to accessGEOROC dataas archived athttps://data.goettingen-research-online.de/dataverse/digis.Cite GEOROC data as specifiedfor each pre-compiled datasetandpygeorocasRobert Forkel. (2022). pofatu/pygeoroc: Programmatic access to GEOROC data. Zenodo.http://doi.org/10.5281/zenodo.3744586InstallInstallpygeorocfrom thePython Package Indexrunningpipinstallpygeorocpreferably in a separatevirtual environment, to keep your system's Python installation unaffected.Installingpygeorocwill also install a command line programgeoroc, which provides
functionality to curate a local copy of the GEOROC data. Rungeoroc-hfor details on usage.OverviewGEOROC provides its downloadable content in precompiled files organized in datasets.pygeorocprovides functionality todownload this data to a local directory, calledrepository,access the data in the repository programmatically from Python code,load the data from the repository into a SQLite database for scalable and
performant analysis.Downloading GEOROC dataRunning$georoc--repostmpdownloadwill create or update a local repository, i.e. a directory with the following layout:$tree-L1.
.
├──csv
└──datasets.jsonThe repository contains a "table of contents" indatasets.json. The checksum recorded per file in this table is checked
when runninggeoroc downloadagain, making sure only new versions of files are fetched.The local repository can be inspected runninggeoroc ls, e.g.$georoc--repostmp/ls--samples--references--formatpipewill output the table included belowfiledatasetsizelast modified# samples# referencespathdoi:10.25625/1KRR1P/QIINIEGEOROC Compilation: Archaean Cratons211.7KB2022-06-2024282022-06-1KRR1P_ALDAN_SHIELD_ARCHEAN.csvdoi:10.25625/1KRR1P/9YG7VJGEOROC Compilation: Archaean Cratons494.3KB2022-06-20564232022-06-1KRR1P_AMAZONIAN_CRATON.csvdoi:10.25625/1KRR1P/E7NI47GEOROC Compilation: Archaean Cratons3.3MB2022-06-203776662022-06-1KRR1P_BALTIC_SHIELD_ARCHEAN.csvdoi:10.25625/1KRR1P/FY7PXYGEOROC Compilation: Archaean Cratons53.8KB2022-06-206152022-06-1KRR1P_BASTAR_CRATON_ARCHEAN.csv...Loading GEOROC data into SQLiteSince GEOROC contains data about hundreds of thousands of samples, querying it
is made a lot easier by loading it into a SQLite database:$georoc--repostmp/createdb100%|██████████████████████████████████████████████████|5/5[00:00<00:00,25.32it/s]INFOtmp/georoc.sqliteThe resulting database has 4 tables:file: Info about a CSV file, basically the data fromindex.csv.sample: Info about individual samples.reference: Info about sources of the datacitation: The association table relating samples with references.The schema can be inspected running:$sqlite3tmp/georoc.sqlite
SQLiteversion3.11.02016-02-1517:29:24
Enter".help"forusagehints.
sqlite>.schemaand looks as follows:CREATETABLEfile(idTEXTPRIMARYKEY,dateTEXT,sectionTEXT);CREATETABLEreference(idINTEGERPRIMARYKEY,referenceTEXT);CREATETABLEsample(idTEXTPRIMARYKEY,file_idTEXT,`AGE`TEXT,`ALTERATION`TEXT,`DRILL_DEPTHAX`TEXT,`DRILL_DEPTH_MIN`TEXT,`ELEVATION_MAX`TEXT,`ELEVATION_MIN`TEXT,`EPSILON_ND`TEXT,`ERUPTION_DAY`TEXT,`ERUPTION_MONTH`TEXT,`ERUPTION_YEAR`TEXT,`GEOL.`TEXT,`LAND_OR_SEA`TEXT,`LATITUDE_MAX`TEXT,`LATITUDE_MIN`TEXT,`LOCATION`TEXT,`LOCATION_COMMENT`TEXT,`LONGITUDE_MAX`TEXT,`LONGITUDE_MIN`TEXT,`MATERIAL`TEXT,`MINERAL`TEXT,`ROCK_NAME`TEXT,`ROCK_TEXTURE`TEXT,`ROCK_TYPE`TEXT,`TECTONIC_SETTING`TEXT,`AR40_K40`TEXT,`HE3_HE4`TEXT,`HE4_HE3`TEXT,`HF176_HF177`TEXT,`K40_AR40`TEXT,`ND143_ND144`TEXT,`ND143_ND144_INI`TEXT,`OS184_OS188`TEXT,`OS186_OS188`TEXT,`OS187_OS186`TEXT,`OS187_OS188`TEXT,`PB206_PB204`TEXT,`PB206_PB204_INI`TEXT,`PB207_PB204`TEXT,`PB207_PB204_INI`TEXT,`PB208_PB204`TEXT,`PB208_PB204_INI`TEXT,`RE187_OS186`TEXT,`RE187_OS188`TEXT,`SR87_SR86`TEXT,`SR87_SR86_INI`TEXT,`AG(PPM)`TEXT,`AL(PPM)`TEXT,`AS(PPM)`TEXT,`AU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TEXT,`SM(PPM)`TEXT,`SN(PPM)`TEXT,`SR(PPM)`TEXT,`TA(PPM)`TEXT,`TB(PPM)`TEXT,`TE(PPM)`TEXT,`TH(PPM)`TEXT,`TI(PPM)`TEXT,`TL(PPM)`TEXT,`TM(PPM)`TEXT,`U(PPM)`TEXT,`V(PPM)`TEXT,`VOLATILES(WT%)`TEXT,`W(PPM)`TEXT,`Y(PPM)`TEXT,`YB(PPM)`TEXT,`ZN(PPM)`TEXT,`ZR(PPM)`TEXT,`AL2O3(WT%)`TEXT,`B2O3(WT%)`TEXT,`CH4(WT%)`TEXT,`CL2(WT%)`TEXT,`CO1(WT%)`TEXT,`CO2(PPM)`TEXT,`CO2(WT%)`TEXT,`CR2O3(WT%)`TEXT,`FE2O3(WT%)`TEXT,`H2O(WT%)`TEXT,`H2OM(WT%)`TEXT,`H2OP(WT%)`TEXT,`H2OT(WT%)`TEXT,`HE3(AT/G)`TEXT,`HE3(CCMSTP/G)`TEXT,`HE3_HE4(R/R(A))`TEXT,`HE4(AT/G)`TEXT,`HE4(CCM/G)`TEXT,`HE4(CCMSTP/G)`TEXT,`HE4(MOLE/G)`TEXT,`HE4(NCC/G)`TEXT,`HE4_HE3(R/R(A))`TEXT,`K2O(WT%)`TEXT,`NA2O(WT%)`TEXT,`P2O5(WT%)`TEXT,`SIO2(WT%)`TEXT,`SO2(WT%)`TEXT,`SO3(WT%)`TEXT,`SO4(WT%)`TEXT,`TIO2(WT%)`TEXT,FOREIGNKEY(file_id)REFERENCESfile(id));CREATETABLEcitation(sample_idTEXT,reference_idINTEGER,FOREIGNKEY(sample_id)REFERENCESsample(id),FOREIGNKEY(reference_id)REFERENCESreference(id));Thus, information similar to what is reported bygeoroc lscan be obtained by
running SQL queries.E.g. to determine the paper which contributed the highest number of samples, we can runSELECTr.reference,COUNT(c.sample_id)AScFROMreferenceasr,citationascWHEREr.id=c.reference_idGROUPBYr.referenceORDERBYcDESCLIMIT1;which yieldsFONTIJN K., MCNAMARA K., TADESSE A. Z., PYLE D. M., DESSALEGN F., HUTCHISON W., MATHER T. A., YIRGU G.:    CONTRASTING STYLES OF POST-CALDERA VOLCANISM ALONG THE MAIN ETHIOPIAN RIFT: IMPLICATIONS FOR CONTEMPORARY VOLCANIC HAZARDS  J. VOLCANOL. GEOTHERM. RES. 356   [2018] 90-113    doi: 10.1016/j.jvolgeores.2018.02.001|3978Accessing GEOROC data programmaticallypygeorocprovides a Python API to access local GEOROC data:>>>frompygeorocimportGEOROC>>>api=GEOROC('tmp/')>>>forsampleinapi.iter_samples():>>>forsample,fileinapi.iter_samples():...print(sample)...print(file)...break...Sample(id='138180',name='s_27-261-33,CC,PC. 2 [2118]',citations=['2118'],data={'SR(PPM)':'',...})File(name='Ocean_Basin_Flood_Basalts_comp__ARGO_ABYSSAL_PLAIN;INDIAN_OCEAN.csv',date=datetime.date(2020,3,9),section='Ocean Basin Flood Basalts')ConvertersFor both access modes - SQLite and the python API -pygeorocprovides a
mechanism to specify "converters", i.e. python callables to convert the values
for specific columns in GEOROC CSV data. This mechanism can be used to fix
errata - e.g. missing negative signs in geographic coordinates - or cast data
to more suitable datatypes.This mechanism is implemented inpygeoroc.errataand works as follows: If the data repository contains a python module calledconverters.py, this module is loaded and two pythondicts are looked up
by name:FIELDS:dictmapping CSV column names to converter functions.COORDINATES:dictmapping CSV filenames (as stored in the repository)
todicts specifying converter functions for keyslatitudeandlongitude.A "converter function" is a python callable with the following signature:defconv(old,data,fname):"""@param old: old value for the respective field in the sample data@param data: full `dict` of the sample data in one row in the GEOROC CSV@param fname: name of the GEOROC CSV file containing the row@return: the new value for "field" in "data""""Some useful converter functions are available as attributes ofpygeoroc.errata.CONVERTERS.So, to specify that values for the columnLAND_OR_SEAmust be all uppercase,
and latitudes in the fileBISMARCK_ARC_NEW_BRITAIN_ARC.csvmust be negative
(look up filenames in your repository'scsv/directory or by runningSELECT id FROM file;in the SQLite db),
you would put the following python code in your repository'sconverters.py:frompygeoroc.errataimportCONVERTERSFIELDS={'LAND_OR_SEA':CONVERTERS.upper,}COORDINATES={"BISMARCK_ARC_NEW_BRITAIN_ARC.csv":{'latitude':CONVERTERS.negative,},}