def metadata(self):
        """
        Retrieve the metadata from Mesowest. Two calls are made to the Mesowest API.
        The first call is to get the networks in order to determine the `network` and
        `primary_provider`. The second call retrieves the metadata given the `config`
        parameters. The two dataframes are combined and inserted into the database
        given the :class:`~wxcb.database.Database` instance.
        """

        self._logger.info('Obtaining metadata form Mesowest')
        m = Meso(token=self.token)

        # get the networks associated with the metadata
        networks = m.networks()
        net = pd.DataFrame(networks['MNET'])
        net['MNET_ID'] = net['ID']

        # get metadata from Mesowest
        self._logger.debug('Obtaining metadata for {}'.format(self.config))
        meta = m.metadata(**self.config)

        # add the networks to the meta dataframe
        mdf = pd.DataFrame(meta['STATION'])
        mdf = pd.merge(mdf, net, on='MNET_ID')

        # pull out the data from Mesowest into the database format
        DF = pd.DataFrame()
        for c in self.conversion:
            DF[self.conversion[c]] = mdf[c]

        # fill in the network conversion
        for n in self.network_conversion:
            DF[self.network_conversion[n]] = mdf[n]

        # elevation is reported in feet, convet to meters
        DF['elevation'] = DF['elevation'].astype(float) / 3.28084

        # these are the reported lat/long's for the station that may get changed
        # down the road due to location errors
        DF['reported_lat'] = DF['latitude']
        DF['reported_long'] = DF['longitude']

        # calculate the UTM coordinates
        DF['utm_x'], DF['utm_y'], DF['utm_zone'] = zip(
            *DF.apply(utils.df_utm, axis=1))

        # add the source to the DF
        DF['source'] = 'mesowest'

        DF = DF.where((pd.notnull(DF)), None)

        # insert the dataframe into the database
        self.db.insert_data(DF, 'metadata', description='Mesowest metadata')
示例#2
0
attime = m.attime(stid='kfnl', attime='201504261800', within='30')

# Or just get the latest observation within the last 15 minutes
latest = m.latest(stid='kfnl', within='15')

# Returns a time series from Fort Collins airport from Apr 26 18z to Apr 26 23z
time = m.timeseries(stid='kfnl', start='201504261800', end='201504262300')

# Returns the precip obs from Fort Collins airport from Apr 26 18z to Apr 27 12z
precip = m.precip(stid='kfnl',
                  start='201504261800',
                  end='201504271200',
                  units='precip|in')

# Learn more about all of the networks in MesoWest with the networks() func
networks = m.networks()

# Or explore the categories MesoWest networks belong to
nettypes = m.networktypes()

# You can obtain time series statistics for any station
stats = m.time_stats(stid='mtmet',
                     start='201403240000',
                     end='201403280000',
                     type='all')

# Or get climatology stats for a station (remember to change the date!)
clim_stats = m.climate_stats(stid='mtmet',
                             startclim='03240000',
                             endclim='03280000',
                             type='all')
示例#3
0
variables = m.variables()

# This returns a climatology for Denver from Apr 26 OOz to Apr 27 OOz
climate = m.climatology(stid='kden', startclim='04260000', endclim='04270000', units='precip|in')

# Fetches the latest obs for Fort Collins airport within 30 min of Apr 26 18z
attime = m.attime(stid='kfnl', attime='201504261800', within='30')

# Or just get the latest observation within the last 15 minutes
latest = m.latest(stid='kfnl', within='15')

# Returns a time series from Fort Collins airport from Apr 26 18z to Apr 26 23z
time = m.timeseries(stid='kfnl', start='201504261800', end='201504262300')

# Returns the precip obs from Fort Collins airport from Apr 26 18z to Apr 27 12z
precip = m.precip(stid='kfnl', start='201504261800', end='201504271200', units='precip|in')

# Learn more about all of the networks in MesoWest with the networks() func
networks = m.networks()

# Or explore the categories MesoWest networks belong to
nettypes = m.networktypes()

# You can obtain time series statistics for any station
stats = m.time_stats(stid='mtmet', start='201403240000', end='201403280000', type='all')

# Or get climatology stats for a station (remember to change the date!)
clim_stats = m.climate_stats(stid='mtmet', startclim='03240000', endclim='03280000', type='all')

# Lastly, see the latency of the API by using the latency() function
latency = m.latency(stid='mtmet', start='201403240000', end='201403280000')