def flaskrun(default_host='0.0.0.0', default_port=int(ownstorj_port_settings)): parser = optparse.OptionParser() parser.add_option("-H", "--host", help="Hostname/IP of OwnStorj " + "[default %s]" % default_host, default=default_host) parser.add_option("-P", "--port", help="Port for the OwnStorj " + "[default %s]" % default_port, default=default_port) parser.add_option("-d", "--debug", action="store_true", dest="debug", help=optparse.SUPPRESS_HELP) options, _ = parser.parse_args() try: context = SSL.Context(SSL.SSLv23_METHOD) # context.use_privatekey_file('server.key') # context.use_certificate_file('server.crt') except BaseException as e: _print(e) app.run( debug=options.debug, host=options.host, port=int(options.port), threaded=True )
def order(catalog_id): """Order the catalog ID(s) passed in""" if len(catalog_id) == 0: six._print("No catalog IDs passed in.") return if len(catalog_id) == 1: # pull the one item and just order that show( gbdx.ordering.order(catalog_id[0]) ) else: # this is a list with multiple entries show( gbdx.ordering.order(catalog_id) )
def order(catalog_id): """Order the catalog ID(s) passed in""" if len(catalog_id) == 0: six._print("No catalog IDs passed in.") return if len(catalog_id) == 1: # pull the one item and just order that show(gbdx.ordering.order(catalog_id[0])) else: # this is a list with multiple entries show(gbdx.ordering.order(catalog_id))
def update(self, current_time, Tb=24., Tr=0., **kwds): """ Update fields with current loading conditions. Parameters ---------- current_time: float Current time (years). Tr: float, optional Storm duration (hours). Tb: float, optional Inter-storm duration (hours). """ P_ = self._cell_values['rainfall__daily_depth'] self._PET = ( self._cell_values['surface__potential_evapotranspiration_rate']) self._pet_g = ( self. _cell_values['surface__potential_evapotranspiration_rate__grass']) self._SO = ( self._cell_values['soil_moisture__initial_saturation_fraction']) self._vegcover = self._cell_values['vegetation__cover_fraction'] self._water_stress = self._cell_values['vegetation__water_stress'] self._S = self._cell_values['soil_moisture__saturation_fraction'] self._D = self._cell_values['soil_moisture__root_zone_leakage'] self._ETA = self._cell_values['surface__evapotranspiration'] self._fr = (self._cell_values['vegetation__live_leaf_area_index'] / self._LAIR_max) self._runoff = self._cell_values['surface__runoff'] self._runon = self._cell_values['surface__runon'] self._runoff[:] = 0. # Initializing runoff to zero self._runon[:] = 0. # Initializing runon to zero # LAIl = self._cell_values['vegetation__live_leaf_area_index'] # LAIt = LAIl+self._cell_values['DeadLeafAreaIndex'] # if LAIt.all() == 0.: # self._fr = np.zeros(self.grid.number_of_cells) # else: # self._fr = (self._vegcover[0]*LAIl/LAIt) self._fr[self._fr > 1.] = 1. self._Sini = np.zeros(self._SO.shape) self._ETmax = np.zeros(self._SO.shape) self._ts = np.zeros(self._SO.shape) # record Time to Saturation self._precip_int = np.zeros(self._SO.shape) # Adding routine to add runon & runoff if self._runon_switch: # Make sure that flow_router has been called before r_cell = (self.grid.cell_at_node[ self.grid.at_node['flow__receiver_node']]) r_cell = r_cell[r_cell != -1] # finding cells that aren't part of # ordered cells (delineated watershed) diff_cells = (np.setdiff1d(range(0, self.grid.number_of_cells), self.ordered_cells)) # trvrsl_order has ordered cells computed first and then the rest # of the cells trvrsl_order = np.concatenate((self.ordered_cells, diff_cells), axis=0) else: # trvrsl_order is just regular 'all cells' if no runon is computed trvrsl_order = range(0, self.grid.number_of_cells) for cell in trvrsl_order: # Routine to calculate runon if self._runon_switch: if cell in self.ordered_cells: donors = [] donors = list(np.where(r_cell == cell)[0]) if len(donors) != 0: for k in range(0, len(donors)): self._runon[cell] += self._runoff[donors[k]] P = P_[cell] runon = self._runon[cell] if runon < 0: six._print('Runon < 0!') # print cell s = self._SO[cell] fbare = self._fbare ZR = self._zr[cell] pc = self._soil_pc[cell] fc = self._soil_fc[cell] scc = self._soil_sc[cell] wp = self._soil_wp[cell] hgw = self._soil_hgw[cell] beta = self._soil_beta[cell] Ks = self._soil_Ks[cell] if self._vegtype[cell] == 0: # 0 - GRASS sc = scc * self._fr[cell] + (1 - self._fr[cell]) * fc else: sc = scc # Infiltration capacity Inf_cap = (self._soil_Ib[cell] * (1 - self._vegcover[cell]) + self._soil_Iv[cell] * self._vegcover[cell]) # Interception capacity Int_cap = min(self._vegcover[cell] * self._interception_cap[cell], P * self._vegcover[cell]) # Effective precipitation depth Peff = max((P + max(runon, 0.) - Int_cap), 0.) mu = (Ks / 1000.0) / (pc * ZR * (np.exp(beta * (1. - fc)) - 1.)) if self._vegtype[cell] == 3: Ep = max((fbare * self._pet_g[cell]), 0.0001) else: Ep = max((self._PET[cell] * self._fr[cell] + fbare * self._pet_g[cell] * (1. - self._fr[cell])) - Int_cap, 0.0001) # mm/d self._ETmax[cell] = Ep nu = ((Ep / 24.) / 1000.) / (pc * ZR) # Loss function parameter # Loss function parameter nuw = ((self._soil_Ew / 24.) / 1000.) / (pc * ZR) # Precipitation Intensity precip_int = Peff / Tr self._precip_int[cell] = precip_int # Time to saturation Ts if precip_int <= 0.: Ts = np.inf else: Ts = (((1 - self._SO[cell]) * (pc * ZR * 1000.)) / (precip_int * (1 - np.exp((-1) * Inf_cap / precip_int)))) self._ts[cell] = Ts # Computing runoff # If using Poisson storms with Tr = 0, (Precip_int * Tr = Precip) if Tr == 0.: self._runoff[cell] = max((Peff - Inf_cap), 0.) sini = min( self._SO[cell] + ((Peff - self._runoff[cell]) / (pc * ZR * 1000.)), 1.) # If using regular storms with (Tr != 0.) elif Tr < Ts: self._runoff[cell] = max((precip_int - Inf_cap) * Tr, 0.) sini = min( self._SO[cell] + ((precip_int * Tr - self._runoff[cell]) / (pc * ZR * 1000.)), 1.) else: sini = 1 self._runoff[cell] = max( ((precip_int - Inf_cap) * Ts + (precip_int * (Tr - Ts))), 0.) if sini >= fc: tfc = (1. / (beta * (mu - nu))) * (beta * (fc - sini) + np.log( (nu - mu + mu * np.exp(beta * (sini - fc))) / nu)) tsc = ((fc - sc) / nu) + tfc twp = ((sc - wp) / (nu - nuw)) * np.log(nu / nuw) + tsc if Tb < tfc: s = abs(sini - (1. / beta) * np.log(( (nu - mu + mu * np.exp(beta * (sini - fc))) * np.exp(beta * (nu - mu) * Tb) - mu * np.exp(beta * (sini - fc))) / (nu - mu))) self._D[cell] = ((pc * ZR * 1000.) * (sini - s)) - (Tb * (Ep / 24.)) self._ETA[cell] = (Tb * (Ep / 24.)) elif Tb >= tfc and Tb < tsc: s = fc - (nu * (Tb - tfc)) self._D[cell] = ((pc * ZR * 1000.) * (sini - fc)) - ((tfc) * (Ep / 24.)) self._ETA[cell] = (Tb * (Ep / 24.)) elif Tb >= tsc and Tb < twp: s = (wp + (sc - wp) * ((nu / (nu - nuw)) * np.exp( (-1) * ((nu - nuw) / (sc - wp)) * (Tb - tsc)) - (nuw / (nu - nuw)))) self._D[cell] = ((pc * ZR * 1000.) * (sini - fc)) - (tfc * Ep / 24.) self._ETA[cell] = (1000. * ZR * pc * (sini - s)) - self._D[cell] else: s = (hgw + (wp - hgw) * np.exp( (-1) * (nuw / (wp - hgw)) * max(Tb - twp, 0.))) self._D[cell] = ((pc * ZR * 1000.) * (sini - fc)) - (tfc * Ep / 24.) self._ETA[cell] = (1000. * ZR * pc * (sini - s)) - self._D[cell] elif sini < fc and sini >= sc: tfc = 0. tsc = (sini - sc) / nu twp = ((sc - wp) / (nu - nuw)) * np.log(nu / nuw) + tsc if Tb < tsc: s = sini - nu * Tb self._D[cell] = 0. self._ETA[cell] = 1000. * ZR * pc * (sini - s) elif Tb >= tsc and Tb < twp: s = (wp + (sc - wp) * ((nu / (nu - nuw)) * np.exp( (-1) * ((nu - nuw) / (sc - wp)) * (Tb - tsc)) - (nuw / (nu - nuw)))) self._D[cell] = 0 self._ETA[cell] = (1000. * ZR * pc * (sini - s)) else: s = hgw + (wp - hgw) * np.exp( (-1) * (nuw / (wp - hgw)) * (Tb - twp)) self._D[cell] = 0. self._ETA[cell] = (1000. * ZR * pc * (sini - s)) elif sini < sc and sini >= wp: tfc = 0 tsc = 0 twp = (((sc - wp) / (nu - nuw)) * np.log(1 + (nu - nuw) * (sini - wp) / (nuw * (sc - wp)))) if Tb < twp: s = (wp + ((sc - wp) / (nu - nuw)) * ((np.exp((-1) * ((nu - nuw) / (sc - wp)) * Tb)) * (nuw + ((nu - nuw) / (sc - wp)) * (sini - wp)) - nuw)) self._D[cell] = 0. self._ETA[cell] = (1000. * ZR * pc * (sini - s)) else: s = hgw + (wp - hgw) * np.exp( (-1) * (nuw / (wp - hgw)) * (Tb - twp)) self._D[cell] = 0. self._ETA[cell] = (1000. * ZR * pc * (sini - s)) else: tfc = 0. tsc = 0. twp = 0. s = hgw + (sini - hgw) * np.exp((-1) * (nuw / (wp - hgw)) * Tb) self._D[cell] = 0. self._ETA[cell] = (1000. * ZR * pc * (sini - s)) self._water_stress[cell] = min(((max( ((sc - (s + sini) / 2.) / (sc - wp)), 0.))**4.), 1.0) self._S[cell] = s self._SO[cell] = s self._Sini[cell] = sini current_time += (Tb + Tr) / (24. * 365.25) return current_time
six.print_( 'copying', dir, '...' ) shutil.copytree( dir, os.path.join(pypiDir,dir) ) six.print_( 'Copying doc files to doc directory.' ) docDir = os.path.join( pypiDir, 'CrossMgrImpinjDoc' ) os.mkdir( docDir ) for f in ['LinuxInstallReadme.txt']: shutil.copy( f, os.path.join(docDir, f) ) six.print_( 'Collecting data_files.' ) data_files = [] for dir in ['CrossMgrImpinjImages']: dataDir = os.path.join(pypiDir, dir) data_files.append( (dir, [os.path.join(dir,f) for f in os.listdir(dataDir)]) ) six._print( 'Copy the src files and add the copyright notice.' ) license = license.replace( '\n', '\n# ' ) for fname in glob.glob( '*.*' ): if not (fname.endswith( '.py' ) or fname.endswith('.pyw')): continue six.print_( ' ', fname, '...' ) with io.open(fname, 'r') as f: contents = f.read() if contents.startswith('import'): p = 0 else: for search in ['\nimport', '\nfrom']: p = contents.find(search) if p >= 0: p += 1 break
if __name__ == '__main__': connection_string = "[Connection String]" endorsement_key = "[Endorsement Key]" registration_id = "[Registration ID]" #set up the provisioning service client psc = ProvisioningServiceClient.create_from_connection_string(connection_string) #build IndividualEnrollment model att = AttestationMechanism.create_with_tpm(endorsement_key) ie = IndividualEnrollment.create(registration_id, att) #create IndividualEnrollment on the Provisioning Service ie = psc.create_or_update(ie) six._print(ie) #get IndividualEnrollment from the Provisioning Service (note: this step is useless here, as ie is already up to date) ie = psc.get_individual_enrollment(registration_id) six._print(ie) #delete IndividualEnrollment from the Provisioning Service psc.delete(ie) #could also use psc.delete_individual_enrollment_by_param(ie.registration_id, ie.etag) #bulk create IndividualEnrollments enrollments = [] for i in range(5): enrollments.append(IndividualEnrollment.create(registration_id + str(i + 1), att)) bulk_op = BulkEnrollmentOperation("create", enrollments)
local_tz = pytz.timezone(tz_name) else: local_tz = pytz.utc super(DateTimeUTC, self).__init__(data, data_tz=pytz.utc, local_tz=local_tz, tz_name=tz_name) # Just for testing purposes if __name__ == '__main__': tz_name = 'America/Vancouver' a = DateTimeLocal('2017-01-01 09:03:01', tz_name=tz_name) b = DateTimeLocal('2017-01-11 21:51:32', tz_name=tz_name) six._print(a.local_str()) six._print(">", a.utc_str()) six._print(b.local_str()) six._print(">", b.utc_str()) r = TimeRange(a, b) six._print("Local day difference", r.local_days()) six._print("UTC day difference", r.utc_days()) for c in r.local_chunks(): six._print(c.local_str()) d = Date('2018-02-16', tz_name=tz_name) six._print(d) six._print(d.local_start_time().local_str())