{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## HadISD" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`source` is the same for Hadisd: \"HadISD\", \"hadisd\", \"Hadisd\", \"HADISD\", \"Had-isd\", \"had-isd\", \"HAD-ISD\", \"Had-isd\"\n", "\n", "get meta `load`, if true, read the metadata as Dataframe" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
station_idlatlonelevation
0010010-9999970.933-8.6679.0
1010014-9999959.7925.34148.8
2010030-9999977.00015.50012.0
3010070-9999978.91711.9337.7
4010080-9999978.24615.46626.8
\n", "
" ], "text/plain": [ " station_id lat lon elevation\n", "0 010010-99999 70.933 -8.667 9.0\n", "1 010014-99999 59.792 5.341 48.8\n", "2 010030-99999 77.000 15.500 12.0\n", "3 010070-99999 78.917 11.933 7.7\n", "4 010080-99999 78.246 15.466 26.8" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from obswx import *\n", "\n", "# Get the metadata for the HadISD dataset\n", "met = obswx(source='hadisd')\n", "\n", "# Load the metadata\n", "met.get_meta(load=True).head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "metadata is from [hadisd_meta.csv](https://github.com/envdes/obswx/blob/main/metadata/hadisd_meta.csv>) (last access: 2024-04-30), originally from: https://www.metoffice.gov.uk/hadobs/hadisd/v341_202403p/station_download.html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- get_data `ids_source`, 'AWS' is using AWS S3 ids, isd \n", "- get_data `station`, the station id in metadata\n", "- get_data `output`, optional, the path dir of output file, e.g., \"pyxw/\". By default, the file nc file will be save in current work dir." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting data from HadISD\n", "Goto here to help select station: https://junjieyu-uom.github.io/obswx/hadisd_map\n", "Downloading data from https://www.metoffice.gov.uk/hadobs/hadisd/v341_202403p/data/hadisd.3.4.1.202403p_19310101-20240401_010010-99999.nc.gz\n", "Extracting 010010-99999.nc.gz to 010010-99999.nc\n" ] } ], "source": [ "ds = met.get_data(station=\"010010-99999\", ids_source='hadisd')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset> Size: 254MB\n",
       "Dimensions:                (coordinate_length: 1, time: 278217, test: 71,\n",
       "                            flagged: 19, reporting_v: 19, reporting_t: 1128,\n",
       "                            reporting_2: 2)\n",
       "Coordinates:\n",
       "    longitude              (coordinate_length) float64 8B ...\n",
       "    latitude               (coordinate_length) float64 8B ...\n",
       "    elevation              (coordinate_length) float64 8B ...\n",
       "  * time                   (time) datetime64[ns] 2MB 1931-01-01T06:00:00 ... ...\n",
       "Dimensions without coordinates: coordinate_length, test, flagged, reporting_v,\n",
       "                                reporting_t, reporting_2\n",
       "Data variables: (12/27)\n",
       "    station_id             |S12 12B ...\n",
       "    temperatures           (time) float64 2MB ...\n",
       "    dewpoints              (time) float64 2MB ...\n",
       "    slp                    (time) float64 2MB ...\n",
       "    stnlp                  (time) float64 2MB ...\n",
       "    windspeeds             (time) float64 2MB ...\n",
       "    ...                     ...\n",
       "    wind_gust              (time) float64 2MB ...\n",
       "    past_sigwx1            (time) float64 2MB ...\n",
       "    input_station_id       (time) object 2MB ...\n",
       "    quality_control_flags  (time, test) float64 158MB ...\n",
       "    flagged_obs            (time, flagged) float64 42MB ...\n",
       "    reporting_stats        (reporting_v, reporting_t, reporting_2) float64 343kB ...\n",
       "Attributes: (12/39)\n",
       "    title:                       HadISD\n",
       "    institution:                 Met Office Hadley Centre, Exeter, UK\n",
       "    source:                      HadISD data product\n",
       "    references:                  Dunn, 2019, Met Office Hadley Centre Technic...\n",
       "    creator_name:                Robert Dunn\n",
       "    creator_url:                 www.metoffice.gov.uk\n",
       "    ...                          ...\n",
       "    station_information:         Where station is a composite the station id ...\n",
       "    Conventions:                 CF-1.6\n",
       "    Metadata_Conventions:        Unidata Dataset Discovery v1.0, CF Discrete ...\n",
       "    featureType:                 timeSeries\n",
       "    processing_date:             04-Apr-2024\n",
       "    history:                     Created by mk_netcdf_files.py \\nDuplicate Mo...
" ], "text/plain": [ " Size: 254MB\n", "Dimensions: (coordinate_length: 1, time: 278217, test: 71,\n", " flagged: 19, reporting_v: 19, reporting_t: 1128,\n", " reporting_2: 2)\n", "Coordinates:\n", " longitude (coordinate_length) float64 8B ...\n", " latitude (coordinate_length) float64 8B ...\n", " elevation (coordinate_length) float64 8B ...\n", " * time (time) datetime64[ns] 2MB 1931-01-01T06:00:00 ... ...\n", "Dimensions without coordinates: coordinate_length, test, flagged, reporting_v,\n", " reporting_t, reporting_2\n", "Data variables: (12/27)\n", " station_id |S12 12B ...\n", " temperatures (time) float64 2MB ...\n", " dewpoints (time) float64 2MB ...\n", " slp (time) float64 2MB ...\n", " stnlp (time) float64 2MB ...\n", " windspeeds (time) float64 2MB ...\n", " ... ...\n", " wind_gust (time) float64 2MB ...\n", " past_sigwx1 (time) float64 2MB ...\n", " input_station_id (time) object 2MB ...\n", " quality_control_flags (time, test) float64 158MB ...\n", " flagged_obs (time, flagged) float64 42MB ...\n", " reporting_stats (reporting_v, reporting_t, reporting_2) float64 343kB ...\n", "Attributes: (12/39)\n", " title: HadISD\n", " institution: Met Office Hadley Centre, Exeter, UK\n", " source: HadISD data product\n", " references: Dunn, 2019, Met Office Hadley Centre Technic...\n", " creator_name: Robert Dunn\n", " creator_url: www.metoffice.gov.uk\n", " ... ...\n", " station_information: Where station is a composite the station id ...\n", " Conventions: CF-1.6\n", " Metadata_Conventions: Unidata Dataset Discovery v1.0, CF Discrete ...\n", " featureType: timeSeries\n", " processing_date: 04-Apr-2024\n", " history: Created by mk_netcdf_files.py \\nDuplicate Mo..." ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### transform to pandas dataframe" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
temperatures
time
1931-01-01 06:00:00-5.0
1931-01-01 12:00:00-5.0
1931-01-01 18:00:00-5.0
1931-01-02 06:00:00-5.0
1931-01-02 12:00:00-5.0
......
2024-03-27 13:00:00-2.7
2024-03-27 14:00:00-2.7
2024-03-27 15:00:00-2.7
2024-03-27 16:00:00-3.0
2024-03-27 17:00:00-3.5
\n", "

278217 rows × 1 columns

\n", "
" ], "text/plain": [ " temperatures\n", "time \n", "1931-01-01 06:00:00 -5.0\n", "1931-01-01 12:00:00 -5.0\n", "1931-01-01 18:00:00 -5.0\n", "1931-01-02 06:00:00 -5.0\n", "1931-01-02 12:00:00 -5.0\n", "... ...\n", "2024-03-27 13:00:00 -2.7\n", "2024-03-27 14:00:00 -2.7\n", "2024-03-27 15:00:00 -2.7\n", "2024-03-27 16:00:00 -3.0\n", "2024-03-27 17:00:00 -3.5\n", "\n", "[278217 rows x 1 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds['temperatures'].to_dataframe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "save to a csv file" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = ds['temperatures'].to_dataframe()\n", "df.to_csv('data.csv')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.9" } }, "nbformat": 4, "nbformat_minor": 4 }