.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "source/auto_examples/utils/plot_parse_filename.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_source_auto_examples_utils_plot_parse_filename.py: Parse the ARM datastream filename --------------------------------- This is an example of how to parse the datastream filename into its constituent parts. .. GENERATED FROM PYTHON SOURCE LINES 9-43 .. rst-class:: sphx-glr-script-out .. code-block:: none Site is sgp Datastream Class is met Facility is E13 Level is b1 Datastream is sgpmetE13.b1 Date is 20190501 Time is 024254 File extension is nc Site is sgp Datastream Class is met Facility is E13 Level is b1 Datastream is sgpmetE13.b1 Date is None Time is None File extension is None | .. code-block:: Python from act.utils.data_utils import DatastreamParserARM # Here we have a full path filename. filename = '/data/sgp/sgpmetE13.b1/sgpmetE13.b1.20190501.024254.nc' # What if we want to extract some metadata from the filename instead of reading the file # and extracting from the global attributes. We can call the DatastreamParserARM() method # and extract the string value from the object using its properties. fn_obj = DatastreamParserARM(filename) print(f"Site is {fn_obj.site}") print(f"Datastream Class is {fn_obj.datastream_class}") print(f"Facility is {fn_obj.facility}") print(f"Level is {fn_obj.level}") print(f"Datastream is {fn_obj.datastream}") print(f"Date is {fn_obj.date}") print(f"Time is {fn_obj.time}") print(f"File extension is {fn_obj.ext}") # We can also use the parser for just the datastream part to extract the parts. # The other methods will not have a value and return None. filename = 'sgpmetE13.b1' fn_obj = DatastreamParserARM(filename) print(f"\nSite is {fn_obj.site}") print(f"Datastream Class is {fn_obj.datastream_class}") print(f"Facility is {fn_obj.facility}") print(f"Level is {fn_obj.level}") print(f"Datastream is {fn_obj.datastream}") print(f"Date is {fn_obj.date}") print(f"Time is {fn_obj.time}") print(f"File extension is {fn_obj.ext}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.001 seconds) .. _sphx_glr_download_source_auto_examples_utils_plot_parse_filename.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_parse_filename.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_parse_filename.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_parse_filename.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_