nrgpy.cloud_api package#
Submodules#
nrgpy.cloud_api.auth module#
- class nrgpy.cloud_api.auth.CloudApi(client_id: str = '', client_secret: str = '', url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/')[source]#
Bases:
object
Parent class for NRG Cloud API functionality
nrgpy simplifies usage of the NRG Cloud APIs. See the documentation for the cloud_api.sites, .export, and .convert modules for more information.
For non-nrgpy implementations, the following Usage information may be helpful.
The base url for the NRG Cloud APIs is
https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/
Use client ID and secret to obtain a bearer token at the /token endpoint. This token is good for 24 hours.
You will be limited to creating 10 tokens per day, though normally one token should suffice, so please cache. nrgpy’s cloud_api modules will automatically manage bearer tokens, refreshing only when necessary.
Endpoints:
- /token
for accessing bearer token. Client ID and Secret required.
- /sites
Get list of sites. Bearer token required
- /convert
Convert RLD file to TXT. Bearer token required
- /export
Export TXT or RLD files for a given date range. NEC files may be used to format TXT outputs. Bearer token required.
- request_session_token() None [source]#
Generates a new session token for convert service api
Requires an active account with NRG Cloud. To sign up for a free account, go to:
Client ID and Secret can be accessed here:
https://cloud.nrgsystems.com/data-manager/api-setup
- Parameters:
- client_idstr
obtained from NRG Systems
- client_secretstr
- Returns:
- session_tokenstr
valid for 24 hour
- session_start_timedatetime
start time of 24 hour countdown
nrgpy.cloud_api.convert module#
- class nrgpy.cloud_api.convert.CloudConvert(rld_dir: str = '', out_dir: str = '', filename: str = '', site_filter: str = '', filter2: str = '', start_date: str = '1970-01-01', end_date: str = '2150-12-31', client_id: str = '', client_secret: str = '', url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/', export_type: str = 'measurements', nec_file: str = '', unzip: bool = True, progress_bar: bool = True, **kwargs)[source]#
Bases:
CloudApi
Uses NRG hosted web-based API to convert RLD and RWD files to text format To sign up for the service, go to https://cloud.nrgsystems.com/.
Note that the site must exist in the NRG Cloud platform, and you must have Contributor or Administrator level access to the site to use these features.
Examples
Convert a single raw data file to Text with NRG Convert API
>>> import nrgpy >>> filename = "/home/user/data/sympro/000123/000123_2019-05-23_19.00_003672.rld >>> client_id = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> client_secret = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> converter = nrgpy.CloudConvert( file_filter=file_filter, filename=filename, client_id=client_id, client_secret=client_secret, )
Convert a folder of raw data files to Text with NRG Convert API
>>> import nrgpy >>> file_filter = "000175" >>> rld_directory = "rlds" >>> txt_dir = "/home/user/data/sympro/000123/txt/" >>> client_id = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> client_secret = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> converter = nrgpy.CloudConvert( file_filter=file_filter, rld_dir=rld_directory, out_dir=txt_dir, client_id=client_id, client_secret=client_secret, start_date="2020-01-01", end_date="2020-01-31", ) >>> converter.process()
- Attributes:
- rld_dirstr (path-like)
path to rld file directory
- out_dirstr (path-like)
path to save text export files
- filenamestr
provide for single file conversion
- site_filterstr, optional
text filter for limiting file set
- filter2str, optional
another text filter…
- start_datestr, optional
text start date to filter on “YYYY-mm-dd”
- end_datestr, optional
text end date to filter on “YYYY-mm-dd”
- client_idstr
provided by NRG Systems
- client_secretstr
provided by NRG Systems
- nec_filestr, optional
path to NEC file for custom export formatting
- export_typestr
[measurements], diagnostic, events, communication
- unzipbool
whether to extract the .txt data file from the .zip file
- session_tokenstr
- headersstr
headers passed in API call
- datastr
data passed in API call
- respstr
API response
- export_filepathstr (path-like)
path of export file
- nrgpy.cloud_api.convert.cloud_convert#
alias of
CloudConvert
nrgpy.cloud_api.export module#
- class nrgpy.cloud_api.export.CloudExport(out_dir: str = '', site_id: str = '', site_number: str = '', logger_sn: str = '', start_date: str = '2014-01-01', end_date: str = '2030-12-31', file_format: str = 'txt', client_id: str = '', client_secret: str = '', url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/', nec_file: str = '', export_type: str = 'measurements', interval: str = '', concatenate: bool = True, unzip: bool = True, **kwargs)[source]#
Bases:
CloudApi
Uses NRG hosted web-based API to download data in text format To sign up for the service, go to https://cloud.nrgsystems.com
Note that the site must exist in the NRG Cloud platform, and you must have Contributor or Administrator level access to the site to use these features.
Use the Site Number or NRG Cloud Site ID to choose the site.
Examples
Download 15 days of data with an NEC file applied, and read data
>>> import nrgpy >>> >>> client_id = "go to https://cloud.nrgsystems.com for access" >>> client_secret = "go to https://cloud.nrgsystems.com for access" >>> save_dir = '/path/to/exported/data' >>> >>> exporter = nrgpy.CloudExport( client_id=client_id, client_secret=client_secret, out_dir=save_dir, nec_file='12vbat.nec', site_id=245, start_date="2021-05-01", end_date="2021-05-15", ) >>> exporter.export() >>> # read result >>> reader = nrgpy.sympro_txt_read(exporter.export_filepath) >>> reader.format_site_data() >>> if reader: >>> print(f"Site number : {reader.site_number}") >>> print(f"Site description : {reader.site_description}") >>> reader.interval_check = nrgpy.check_intervals(reader.data) >>> else: >>> print("unable to get reader")
Download 15 days of data files from ZX 300 site
>>> import nrgpy >>> >>> client_id = "go to https://cloud.nrgsystems.com for access" >>> client_secret = "go to https://cloud.nrgsystems.com for access" >>> save_dir = '/path/to/exported/data' >>> file_format = 'zx' >>> >>> exporter = nrgpy.CloudExport( client_id=client_id, client_secret=client_secret, out_dir=save_dir, file_format='zx', site_id=57, start_date="2022-05-01", end_date="2022-05-15", ) >>> exporter.export()
- Attributes:
- out_dirstr (path-like)
path to save exported data
- site_idint
NRG Cloud site identifier (NOT the site number)
- site_numberint
site number
- logger_snint
serial number of data logger
- start_datestr (‘{YYYY}-{MM}-{DD}T{HH}:{MM}:{SS}’)
start date/time of data export
- end_datestr (‘{YYYY}-{MM}-{DD}T{HH}:{MM}:{SS}’)
end date/time of data export
- file_format{‘txt’, ‘rld’, ‘zx’}
whether SymPRO tab-delimited text or binary output or ZX
- client_idstr
available in the NRG Cloud portal
- client_secretstr
available in the NRG Cloud portal
- nec_filestr, optional
path to NEC file for custom export formatting
- export_type{‘measurements’, ‘diagnostic’, ‘events’, ‘communication’}
which type of data to export
- interval{‘oneMinute’, ‘twoMinute’, ‘fiveMinute’, ‘tenMinute’, ‘fifteenMinute’,
‘thirtyMinute’, ‘Hour’, ‘Day’}, optional averaging interval of exported data; must be a multiple of the logger’s statistical interval
- unzipbool
whether to extract the .txt data file from the .zip file
- session_tokenstr
- headersstr
headers passed in API call
- datastr
data passed in API call
- respstr
API response
- export_filepathstr (path-like)
path of export file
- nrgpy.cloud_api.export.cloud_export#
alias of
CloudExport
nrgpy.cloud_api.jobs module#
- class nrgpy.cloud_api.jobs.CloudExportJob(out_dir: str = '', site_id: str = '', site_number: str = '', logger_sn: str = '', start_date: str = '2014-01-01', end_date: str = '2023-12-31', file_format: str = 'txt', client_id: str = '', client_secret: str = '', url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/', nec_file: str = '', export_type: str = 'measurements', concatenate: bool = True, interval: str = '', unzip: bool = True, **kwargs)[source]#
Bases:
CloudExport
Uses NRG hosted web-based API to download data in text format as an export job To sign up for the service, go to https://cloud.nrgsystems.com
Note that the site must exist in the NRG Cloud platform, and you must have Contributor or Administrator level access to the site to use these features.
Use for creating exports of any size. Extends nrgpy.cloud_export class
- Parameters:
- out_dirstr (path-like)
path to save exported data
- site_idint
NRG Cloud site identifier (NOT the site number)
- site_numberint
site number
- logger_snstr or int
serial number of data logger (like, 820612345)
- start_datestr
“YYYY-MM-DD HH:MM:SS” format, if just date it will return the whole day times are in logger local time
- end_datestr
“YYYY-MM-DD HH:MM:SS” format, if just date it will return the whole day times are in logger local time
- client_idstr
available in the NRG Cloud portal
- client_secretstr
available in the NRG Cloud portal
- nec_filestr, optional
path to NEC file for custom export formatting
- export_typestr
[‘measurements’], ‘diagnostic’, ‘events’, ‘communication’
- file_formatstr
[‘txt’], ‘rld’, ‘zx’ - whether tab-delimited text or binary output
- intervalstr, optional
‘oneMinute’, ‘twoMinute’, ‘fiveMinute’, ‘tenMinute’, ‘fifteenMinute’, ‘thirtyMinute’, ‘Hour’, ‘Day’ must be a multiple of the logger’s statistical interval. if not specified, will use “native” interval (usually oneMinute for solar, tenMinute for wind)
- concatenatebool
(True) set to False to return original CSV files in export (ZX only)
- unzipbool
(True) whether to extract the .txt data file from the .zip file
- Returns:
- object
export object, including API response
Examples
Download one year of data with an NEC file applied, and read data
>>> import nrgpy >>> >>> client_id = "go to https://cloud.nrgsystems.com for access" >>> client_secret = "go to https://cloud.nrgsystems.com for access" >>> save_dir = '/path/to/exported/data' >>> >>> exporter = nrgpy.CloudExportJob( client_id=client_id, client_secret=client_secret, out_dir=save_dir, nec_file='12vbat.nec', site_number=3456, start_date="2021-04-01", end_date="2022-03-31", file_format="singleFile", # use "multipleFiles" for RLD export unzip=True, ) >>> >>> exporter.create_export_job() >>> exporter.monitor_export_job(download=True) >>> # read resulting files >>> reader = nrgpy.sympro_txt_read(exporter.export_filepath) >>> reader.format_site_data() >>> if reader: >>> print(f"Site number : {reader.site_number}") >>> print(f"Site description : {reader.site_description}") >>> reader.interval_check = nrgpy.check_intervals(reader.data) >>> else: >>> print("unable to get reader")
Download 15 days of data files from ZX 300 lidar site
>>> import nrgpy >>> >>> client_id = "go to https://cloud.nrgsystems.com for access" >>> client_secret = "go to https://cloud.nrgsystems.com for access" >>> save_dir = '/path/to/exported/data' >>> >>> exporter = nrgpy.CloudExportJob( client_id=client_id, client_secret=client_secret, out_dir=save_dir, site_number=567, start_date="2022-09-01", end_date="2022-09-15", file_format="zx", concatenate=True, unzip=True, ) >>> >>> exporter.create_export_job() >>> exporter.monitor_export_job(download=True)
- nrgpy.cloud_api.jobs.export_job#
alias of
CloudExportJob
nrgpy.cloud_api.sites module#
- class nrgpy.cloud_api.sites.CloudSites(client_id: str, client_secret: str, url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/')[source]#
Bases:
CloudApi
Find NRG Cloud sites associated with a user.
Examples
>>> import nrgpy >>> client_id = 'go to https://cloud.nrgsystems.com for access' >>> client_secret = 'go to https://cloud.nrgsystems.com for access' >>> sites = nrgpy.CloudSites(client_id=client_id, client_secret=client_secret) >>> sites.sites_df siteId siteNumber siteDescription project loggerSerialNumber 0 33 6716 SunnyDog SunnyDog 820606716 1 213 1234 Suntastic South Suntastic 820601234 >>> sites.get_siteid(site_number=6716) 33
- Attributes:
- client_idstr
available in the NRG Cloud portal
- client_secretstr
available in the NRG Cloud portal
- sites_listlist of dict
- sites_dfpandas dataframe
- nrgpy.cloud_api.sites.cloud_sites#
alias of
CloudSites
nrgpy.cloud_api.upload module#
- class nrgpy.cloud_api.upload.CloudImport(in_dir: str = '', filename: str = '', site_filter: str = '', filter2: str = '', start_date: str = '1970-01-01', end_date: str = '2150-12-31', client_id: str = '', client_secret: str = '', url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/', progress_bar: bool = True, **kwargs)[source]#
Bases:
CloudApi
Uses NRG hosted web-based API to import RLD and CSV/CSV.zip files to existing sites in NRG Cloud. To sign up for the service, go to https://cloud.nrgsystems.com/.
Note that the site must exist in the NRG Cloud platform, and you must have Contributor or Administrator level access to the site to use these features.
Examples
Import a single raw data file with NRG Import API
>>> import nrgpy >>> filename = "/home/user/data/sympro/000123/000123_2019-05-23_19.00_003672.filename >>> client_id = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> client_secret = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> importer = nrgpy.CloudImport( filename=filename, client_id=client_id, client_secret=client_secret, )
Import a folder of data files with NRG Import API
>>> import nrgpy >>> file_filter = "000175" >>> in_directory = "filenames" >>> client_id = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> client_secret = "go to https://cloud.nrgsystems.com/data-manager/api-setup for access" >>> importer = nrgpy.CloudImport( file_filter=file_filter, in_dir=in_directory, client_id=client_id, client_secret=client_secret, start_date="2020-01-01", end_date="2020-01-31", ) >>> importer.process()
- Attributes:
- in_dirstr (path-like)
path to data file directory
- filenamestr
provide for single file import
- site_filterstr, optional
text filter for limiting file set
- filter2str, optional
another text filter…
- start_datestr, optional
text start date to filter on “YYYY-mm-dd”
- end_datestr, optional
text end date to filter on “YYYY-mm-dd”
- client_idstr
provided by NRG Systems
- client_secretstr
provided by NRG Systems
- session_tokenstr
- headersstr
headers passed in API call
- datastr
data passed in API call
- respstr
API response
- job_idsdict
dictionary of filenames and job ids
- nrgpy.cloud_api.upload.cloud_import#
alias of
CloudImport