示例#1
0
def initialize_site_observations(api, site):
    """Creates an observation at the site for each variable in
    the matched DOE_ARM_VARIABLE_MAP.

    Parameters
    ----------
    api : solarforecastarbiter.io.api.APISession
        An active Reference user session.
    site : datamodel.Site
        The site object for which to create Observations.
    """
    try:
        site_extra_params = common.decode_extra_parameters(site)
    except ValueError:
        logger.error(f'Failed to initialize observations  for {site.name} '
                     'extra parameters could not be loaded.')
        return
    site_arm_vars = _determine_site_vars(site_extra_params['network_api_id'])
    site_sfa_vars = [DOE_ARM_VARIABLE_MAP[v] for v in site_arm_vars]
    for sfa_var in site_sfa_vars:
        logger.info(f'Creating {sfa_var} at {site.name}')
        try:
            common.create_observation(api, site, sfa_var)
        except HTTPError as e:
            logger.error(f'Could not create Observation for "{sfa_var}" '
                         f'at DOE ARM site {site.name}')
            logger.debug(f'Error: {e.response.text}')
示例#2
0
def test_create_observation(mock_api, site, variable,
                            observation_objects_param):
    mock_api.list_observations.return_value = []
    common.create_observation(mock_api, site, variable)
    mock_api.create_observation.assert_called()
    mock_api.create_observation.assert_called_with(
        observation_objects_param[0])
示例#3
0
def initialize_site_observations(api, site):
    """Creates an observation at the site for each variable in the MIDC
    site's file.

    Parameters
    ----------
    api : io.api.APISession
        API Session object, authenticated for the Reference user.
    site : datamodel.Site
        The site object for which to create the Observations.
    """
    try:
        extra_params = common.decode_extra_parameters(site)
    except ValueError:
        logger.warning('Cannot create reference observations at MIDC site '
                       f'{site.name}, missing required parameters.')
        return
    site_api_id = extra_params['network_api_id']
    for sfa_var, midc_var in midc_config.midc_var_map[site_api_id].items():
        obs_extra_params = extra_params.copy()
        obs_extra_params['network_data_label'] = midc_var
        common.create_observation(api,
                                  site,
                                  sfa_var,
                                  extra_params=obs_extra_params)
示例#4
0
def initialize_site_observations(api, site):
    """Creates an observation at the site.

    Parameters
    ----------
    api : solarforecastarbiter.io.api.APISession
        API Session object, authenticated for the Reference user.
    site : solarforecastarbiter.datamodel.Site
        The site object for which to create the Observations.

    Notes
    -----
    Currently only creates observations for net load [MW]
    (`f"EBA.{eia_site_id}.D.H"`), but EIA contains other variables that may be
    incorporated later (e.g. solar generation:
    `f"EBA.{eia_site_id}.NG.SUN.H"`).

    """

    sfa_var = "net_load"
    logger.info(f'Creating {sfa_var} at {site.name}')
    try:
        common.create_observation(api, site, sfa_var)
    except HTTPError as e:
        logger.error(f'Could not create Observation for "{sfa_var}" '
                     f'at EIA site {site.name}')
        logger.debug(f'Error: {e.response.text}')
def initialize_site_observations(api, site):
    """Creates an observaiton at the site for each variable in surfrad_variables.

    Parameters
    ----------
    site : datamodel.Site
        The site object for which to create Observations.
    """
    for variable in surfrad_variables:
        common.create_observation(api, site, variable)
def initialize_site_observations(api, site):
    """Create an observation for each available variable at the SOLRAD site.

    Parameters
    ----------
    api : solarforecastarbiter.io.api.APISession
        An active reference user session
    site : solarforecastarbiter.datamodel.Site

    """
    for variable in crn_variables:
        common.create_observation(api, site, variable)
def initialize_site_observations(api, site):
    """Creates an observaiton at the site for each variable in surfrad_variables.

    Parameters
    ----------
    api : solarforecastarbiter.io.api.APISession
        An active Reference user session.
    site : datamodel.Site
        The site object for which to create Observations.
    """
    for sfa_var in SANDIA_VARIABLE_MAP.values():
        logger.info(f'Creating {sfa_var} at {site.name}')
        try:
            common.create_observation(
                api, site, sfa_var)
        except HTTPError as e:
            logger.error(f'Could not create Observation for "{sfa_var}" '
                         f'at SANDIA site {site.name}')
            logger.debug(f'Error: {e.response.text}')
示例#8
0
def test_create_observation_with_kwargs(mock_api, site, variable, expected,
                                        kwargs):
    common.create_observation(mock_api, site, variable, **kwargs)
    mock_api.create_observation.assert_called()
    mock_api.create_observation.assert_called_with(expected)
示例#9
0
def test_create_observation_extra_parameters(mock_api, site, variable,
                                             expected, extra_params):
    mock_api.list_observations.return_value = []
    common.create_observation(mock_api, site, variable, extra_params)
    mock_api.create_observation.assert_called()
    mock_api.create_observation.assert_called_with(expected)
示例#10
0
def test_create_observation_long_site(mock_api, site, variable, expected):
    common.create_observation(mock_api, site, variable)
    mock_api.create_observation.assert_called()
    mock_api.create_observation.assert_called_with(expected)
示例#11
0
def test_create_observation_exists(mock_api, site_objects_param,
                                   observation_objects_param):
    variable = 'ghi'
    site = site_objects_param[0]
    common.create_observation(mock_api, site, variable)
    mock_api.create_observation.assert_not_called()
示例#12
0
def initialize_site_observations(api, site):
    """Creates an observation at the site for each variable in
    an SRML site's file.

    Parameters
    ----------
    api: :py:class:`solarforecastarbiter.io.api.APISession`

    site : :py:class:`solarforecastarbiter.datamodel.Site
        The site object for which to create Observations.

    Notes
    -----
    Since variables are labelled with an integer instrument
    number, Observations are named with their variable and
    instrument number found in the source files.

    e.g. A SRML file contains two columns labelled, 1001, and
    1002. These columns represent GHI at instrument 1 and
    instrument 2 respectively. The `pvlib.iotools` package
    converts these to 'ghi_1' and 'ghi_2' for us. We use these
    labels to differentiate between measurements recorded by
    different instruments.
    """
    # Request ~month old data at initialization to ensure we get a response.
    start = pd.Timestamp.utcnow() - pd.Timedelta('30 days')
    end = start
    try:
        extra_params = common.decode_extra_parameters(site)
    except ValueError:
        logger.warning('Cannot create reference observations at MIDC site '
                       f'{site.name}, missing required parameters.')
        return
    # use site name without network here to build
    # a name with the original column label rather than
    # the SFA variable
    site_name = common.site_name_no_network(site)
    try:
        site_df = fetch(api, site, start, end)
    except error.HTTPError:
        logger.error('Could not find data to create observations '
                     f'for SRML site {site_name}.')
        return
    else:
        if site_df is None:
            logger.error('Could not find data to create observations '
                         f'for SRML site {site_name}.')
            return
        for variable in srml_variable_map.keys():
            matches = [col for col in site_df.columns
                       if col.startswith(variable)]
            for match in matches:
                observation_extra_parameters = extra_params.copy()
                observation_extra_parameters.update({
                    'network_data_label': match})
                try:
                    # Here, we pass a name with match instead of variable
                    # to differentiate between multiple observations of
                    # the same variable
                    common.create_observation(
                        api, site, srml_variable_map[variable],
                        name=f'{site_name} {match}',
                        interval_label='beginning',
                        extra_params=observation_extra_parameters)
                except HTTPError as e:
                    logger.error(
                        f'Failed to create {variable} observation at Site '
                        f'{site.name}. Error: {e.response.text}')
        with open(DEFAULT_SITEFILE) as fp:
            obs_metadata = json.load(fp)['observations']
        for obs in obs_metadata:
            obs_site_extra_params = json.loads(obs['site']['extra_parameters'])
            if obs_site_extra_params['network_api_id'] == extra_params[
                    'network_api_id']:
                obs['site'] = site
                observation = Observation.from_dict(obs)
                common.check_and_post_observation(api, observation)
示例#13
0
def initialize_site_observations(api, site):
    """Creates an observation at the site for each variable in
    an SRML site's file.

    Parameters
    ----------
    api: io.api.APISession

    site : datamodel.Site
        The site object for which to create Observations.

    Notes
    -----
    Since variables are labelled with an integer instrument
    number, Observations are named with their variable and
    instrument number found in the source files.

    e.g. A SRML file contains two columns labelled, 1001, and
    1002. These columns represent GHI at instrument 1 and
    instrument 2 respectively. The `pvlib.iotools` package
    converts these to 'ghi_1' and 'ghi_2' for us. We use these
    labels to differentiate between measurements recorded by
    different instruments.
    """
    start = pd.Timestamp.now()
    end = pd.Timestamp.now()
    try:
        extra_params = common.decode_extra_parameters(site)
    except ValueError:
        logger.warning('Cannot create reference observations at MIDC site '
                       f'{site.name}, missing required parameters.')
        return
    # use site name without network here to build
    # a name with the original column label rather than
    # the SFA variable
    site_name = common.site_name_no_network(site)
    try:
        site_df = fetch(api, site, start, end)
    except error.HTTPError:
        logger.error('Could not find data to create observations '
                     f'for SRML site {site_name}.')
        return
    else:
        if site_df is None:
            logger.error('Could not find data to create observations '
                         f'for SRML site {site_name}.')
            return
        for variable in srml_variable_map.keys():
            matches = [col for col in site_df.columns if variable in col]
            for match in matches:
                observation_extra_parameters = extra_params.copy()
                observation_extra_parameters.update(
                    {'network_data_label': match})
                try:
                    # Here, we pass a name with match instead of variable
                    # to differentiate between multiple observations of
                    # the same variable
                    common.create_observation(
                        api,
                        site,
                        srml_variable_map[variable],
                        name=f'{site_name} {match}',
                        interval_label='beginning',
                        extra_params=observation_extra_parameters)
                except HTTPError as e:
                    logger.error(
                        f'Failed to create {variable} observation at Site '
                        f'{site.name}. Error: {e.response.text}')