def get_ice_cover(LocationName, fromDate, toDate): """ Method returns a list of IceCover objects from regObs between fromDate to toDate. :param LocationName: [string/list] name as given in regObs in ObsLocation table :param fromDate: [string] The from date as 'YYYY-MM-DD' :param toDate: [string] The to date as 'YYYY-MM-DD' :return: http://api.nve.no/hydrology/regobs/v0.9.4/Odata.svc/IceCoverObsV?$filter= DtObsTime%20gt%20datetime%272013-11-01%27%20and%20 DtObsTime%20lt%20datetime%272014-06-01%27%20and%20 LocationName%20eq%20%27Hakkloa%20nord%20372%20moh%27%20and%20 LangKey%20eq%201 """ iceCoverList = [] if isinstance(LocationName, types.ListType): for l in LocationName: iceCoverList = iceCoverList + get_ice_cover(l, fromDate, toDate) else: view = 'IceCoverObsV' OdataLocationName = fe.change_unicode_to_utf8hex(LocationName) oDataQuery = "DtObsTime gt datetime'{0}' and " \ "DtObsTime lt datetime'{1}' and " \ "LocationName eq '{2}' and " \ "LangKey eq 1".format(fromDate, toDate, OdataLocationName) # get data for current view and dates url = "http://api.nve.no/hydrology/regobs/{0}/Odata.svc/{2}?$filter={1}&$format=json".decode('utf8').format(api_version, oDataQuery, view) data = requests.get(url).json() datalist = data['d']['results'] for ic in datalist: iceCoverDate = pz.normal_time_from_unix_time(int(ic['DtObsTime'][6:-2])) iceCoverName = ic['IceCoverName'] iceCoverBefore = ic['IceCoverBeforeName'] cover = ice.IceCover(iceCoverDate, iceCoverName, iceCoverBefore, LocationName) cover.set_regid(int(ic['RegID'])) iceCoverList.append(cover) return iceCoverList
def get_ice_thickness(LocationName, fromDate, toDate): ''' Method returns a list of ice thickness between two dates for a given location in regObs. :param LocationName: [string/list] name as given in regObs in ObsLocation table. Multiploe locations posible :param fromDate: [string] The from date as 'YYYY-MM-DD' :param toDate: [string] The to date as 'YYYY-MM-DD' :return: ''' ice_columns = [] if isinstance(LocationName, types.ListType): for l in LocationName: ice_columns = ice_columns + get_ice_thickness(l, fromDate, toDate) else: view = 'IceThicknessV' OdataLocationName = fe.change_unicode_to_utf8hex(LocationName) # Crazyshitencoding oDataQuery = "DtObsTime gt datetime'{0}' and " \ "DtObsTime lt datetime'{1}' and " \ "LocationName eq '{2}' and " \ "LangKey eq 1".format(fromDate, toDate, OdataLocationName) # get data for current view and dates url = "http://api.nve.no/hydrology/regobs/{0}/Odata.svc/{2}?$filter={1}&$format=json".decode('utf8').format(api_version, oDataQuery, view) data = requests.get(url).json() datalist = data['d']['results'] for ic in datalist: date = pz.normal_time_from_unix_time(int(ic['DtObsTime'][6:-2])) RegID = ic['RegID'] layers = get_ice_thickness_layers(RegID) if len(layers) == 0: layers = [ ice.IceLayer(float(ic['IceThicknessSum']), 'unknown') ] ice_column = ice.IceColumn(date, layers) ice_column.add_metadata('RegID', RegID) ice_column.add_metadata('LocatonName', LocationName) ice_column.add_layer_at_index(0, ice.IceLayer(ic['SlushSnow'], 'slush')) ice_column.add_layer_at_index(0, ice.IceLayer(ic['SnowDepth'], 'snow')) ice_column.merge_and_remove_excess_layers() ice_column.update_draft_thickness() ice_column.update_top_layer_is_slush() iha = ic['IceHeightAfter'] # if ice height after is not given I make an estimate so that I know where to put it in the plot if iha is None: ice_column.update_water_line() ice_column.add_metadata('IceHeightAfter', 'Modeled') iha = ice_column.draft_thickness - ice_column.water_line if ice_column.top_layer_is_slush: iha = iha + const.snow_pull_on_water ice_column.water_line = ice_column.draft_thickness - float(iha) if ice_column.top_layer_is_slush is True: ice_column.water_line -= ice_column.column[0].height ice_columns.append(ice_column) return ice_columns