Editing
Code Guide
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Extract data from database=== Extracting data from the database is simple. For example this code will retrieve all the demand data for the SA1 region: <code> 1 import h5py 2 3 with h5py.File(’STORPROJ_Database.h5’, ’r’) as f: 4 demand_data = f[’Regions’][’SA1’][’Demand’][...,0] </code> Extracting data over a specified time frame: <code> 1 import h5py 2 from AUSP_DatetimeToSample import DatetimeToSample as d2s 3 4 start_date = d2s (’2016/09/01 00:00:00’) 5 end_date = d2s (’2017/09/01 00:00:00’) 6 7 with h5py.File(’STORPROJ_Database.h5’, ’r’) as f: 8 demand_data = f[’Regions’][’SA1’][’Demand’][start_date:end_date][...,0] </code> Extracting and summing several known datasets. The following code will extract all the data from the generators HDWF1 and HDWF2 and sum across each sample resulting in an array of summed generator outputs. <code> 1 import h5py 2 import numpy as np 3 4 with h5py.File(’STORPROJ_Database.h5’, ’r’) as f: 5 data = np.nansum(zip(f[’DUIDs’][’HDWF1’][...,0],f[’DUIDs’][’HDWF2’][...,0]),1) </code> Finally, extracting all data from a range of datasets that have an attribute that is the same. This example retrieves all generators that are in the SA1 region with a primary fuel source of "wind". It also skips past any generators that have no attributes. <code> 1 import h5py 2 import numpy as np 3 4 with h5py.File(’STORPROJ_Database.h5’,’r’) as f: 5 for generator in f[’DUIDs’]: 6 if f[’DUIDs’][generator].attrs.keys( ) != [ ]: 7 if f[’DUIDs’][generator].attrs[’Fuel Source - Primary’ ] == "Wind": 8 if f[’DUIDs’][generator].attrs[’Region’] == "SA1": 9 sa_wind = [np.nansum(x) for x in zip(sa_wind,f[’DUIDs’][generator][...,0])] </code>
Summary:
Please note that all contributions to Derek may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Derek:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information