{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Parse the ARM datastream filename\n\nThis is an example of how to parse\nthe datastream filename into its constituent parts.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from act.utils.data_utils import DatastreamParserARM\n\n# Here we have a full path filename.\nfilename = '/data/sgp/sgpmetE13.b1/sgpmetE13.b1.20190501.024254.nc'\n\n# What if we want to extract some metadata from the filename instead of reading the file\n# and extracting from the global attributes. We can call the DatastreamParserARM() method\n# and extract the string value from the object using its properties.\n\nfn_obj = DatastreamParserARM(filename)\nprint(f\"Site is {fn_obj.site}\")\nprint(f\"Datastream Class is {fn_obj.datastream_class}\")\nprint(f\"Facility is {fn_obj.facility}\")\nprint(f\"Level is {fn_obj.level}\")\nprint(f\"Datastream is {fn_obj.datastream}\")\nprint(f\"Date is {fn_obj.date}\")\nprint(f\"Time is {fn_obj.time}\")\nprint(f\"File extension is {fn_obj.ext}\")\n\n# We can also use the parser for just the datastream part to extract the parts.\n# The other methods will not have a value and return None.\n\nfilename = 'sgpmetE13.b1'\n\nfn_obj = DatastreamParserARM(filename)\nprint(f\"\\nSite is {fn_obj.site}\")\nprint(f\"Datastream Class is {fn_obj.datastream_class}\")\nprint(f\"Facility is {fn_obj.facility}\")\nprint(f\"Level is {fn_obj.level}\")\nprint(f\"Datastream is {fn_obj.datastream}\")\nprint(f\"Date is {fn_obj.date}\")\nprint(f\"Time is {fn_obj.time}\")\nprint(f\"File extension is {fn_obj.ext}\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }