Пример #1
0
def get_all_season_ice(LocationName, fromDate, toDate):
    '''
    This returns a list of all ice columns in a period from fromDate to toDate. At index 0 is first ice (date with no
    ice layers) and on last index (-1) is last ice which is the date where there is no more ice on the lake.

    If no first or last ice is found in regObs the first or/and last dates in the request is used for initial and
    end of ice cover season,

    :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:
    '''

    first = get_first_ice_cover(LocationName, fromDate, toDate)
    last = get_last_ice_cover(LocationName, fromDate, toDate)

    start_column = []
    end_column = []

    fc = ice.IceColumn(first.date, 0)
    fc.add_metadata('RegID', first.RegID)
    start_column.append(fc)

    lc = ice.IceColumn(last.date, 0)
    lc.add_metadata('RegID', first.RegID)
    end_column.append(lc)

    columns = get_ice_thickness(LocationName, fromDate, toDate)

    all_columns = start_column + columns + end_column

    return all_columns
Пример #2
0
def runStorvannetHammerfest(startDate, endDate):

    LocationNames = ['Storvannet, 7 moh']
    x = 821340
    y = 7862497

    from_date = dt.datetime.strptime(startDate, "%Y-%m-%d")
    to_date = dt.datetime.strptime(endDate, "%Y-%m-%d")

    cs_temp = gcsd.getGriddata(x, y, 'tm', from_date, to_date)
    cs_sno = gcsd.getGriddata(x, y, 'fsw', from_date, to_date)
    cs_snotot = gcsd.getGriddata(x, y, 'sd', from_date, to_date)
    wsCC = gws.getMetData(95350, 'NNM', startDate, endDate, 0, 'list')  # BANAK - østover innerst i fjorden

    temp, date = we.strip_metadata(cs_temp, True)
    sno = we.strip_metadata(cs_sno, False)
    snotot = we.strip_metadata(cs_snotot, False)
    cc = we.strip_metadata(wsCC, False)

    observed_ice = gro.get_all_season_ice(LocationNames, startDate, endDate)

    if len(observed_ice) == 0:
        ice_cover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno, cc)
    else:
        ice_cover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno, cc)

    plot_filename = '{0}StorvannetHammerfest {1}-{2}.png'.format(plot_folder, startDate[0:4], endDate[0:4])
    pts.plot_ice_cover(ice_cover, observed_ice, date, temp, snotot, plot_filename)
Пример #3
0
def runBaklidammen(startDate, endDate):

    LocationNames = ['Baklidammen 200 moh']
    x = 266550
    y = 7040812

    from_date = dt.datetime.strptime(startDate, "%Y-%m-%d")
    to_date = dt.datetime.strptime(endDate, "%Y-%m-%d")

    cs_temp = gcsd.getGriddata(x, y, 'tm', from_date, to_date)
    cs_sno = gcsd.getGriddata(x, y, 'fsw', from_date, to_date)
    cs_snotot = gcsd.getGriddata(x, y, 'sd', from_date, to_date)
    wsCC = gws.getMetData(68860, 'NNM', startDate, endDate, 0, 'list')  # TRONDHEIM - VOLL

    temp, date = we.strip_metadata(cs_temp, True)
    sno = we.strip_metadata(cs_sno, False)
    snotot = we.strip_metadata(cs_snotot, False)
    cc = we.strip_metadata(wsCC, False)

    observed_ice = gro.get_all_season_ice(LocationNames, startDate, endDate)

    if len(observed_ice) == 0:
        ice_cover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno, cc)
    else:
        ice_cover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno, cc)

    plot_filename = '{0}Baklidammen {1}-{2}.png'.format(plot_folder, startDate[0:4], endDate[0:4])
    pts.plot_ice_cover(ice_cover, observed_ice, date, temp, snotot, plot_filename)
Пример #4
0
def runGiljastolsvatnet(startDate, endDate):

    LocationNames = ['Giljastølsvatnet 412 moh', 'Giljastølvatnet sør 412 moh']
    x = -1904
    y = 6553573

    from_date = dt.datetime.strptime(startDate, "%Y-%m-%d")
    to_date = dt.datetime.strptime(endDate, "%Y-%m-%d")

    #cs_temp = gcsd.getStationdata('189.3.0','17.1', from_date, to_date)
    cs_temp = gcsd.getGriddata(x, y, 'tm', from_date, to_date)
    cs_sno = gcsd.getGriddata(x, y, 'fsw', from_date, to_date)
    cs_snotot = gcsd.getGriddata(x, y, 'sd', from_date, to_date)
    wsCC = gws.getMetData(43010, 'NNM', startDate, endDate, 0, 'list')  # Eik - Hove. Ligger lenger sør men er litt inn i landet.
    #wsCC = getMetData(43010, 'NNM', startDate, endDate, 0, 'list') # Sola (44560) er et alternativ

    temp, date = we.strip_metadata(cs_temp, True)
    sno = we.strip_metadata(cs_sno, False)
    snotot = we.strip_metadata(cs_snotot, False)
    cc = we.strip_metadata(wsCC, False)

    observed_ice = gro.get_all_season_ice(LocationNames, startDate, endDate)

    if len(observed_ice) == 0:
        ice_cover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno, cc)
    else:
        ice_cover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno, cc)

    plot_filename = '{0}Giljastolsvatnet {1}-{2}.png'.format(plot_folder, startDate[0:4], endDate[0:4])
    pts.plot_ice_cover(ice_cover, observed_ice, date, temp, snotot, plot_filename)
Пример #5
0
def runSkoddebergvatnet(startDate, endDate):

    LocationName = 'Skoddebergvatnet - nord 101 moh'
    # Skoddebergvatnet - sør 101 moh
    from_date = dt.datetime.strptime(startDate, "%Y-%m-%d")
    to_date = dt.datetime.strptime(endDate, "%Y-%m-%d")

    #cs_temp = gcsd.getGriddata('189.3.0','17.1', from_date, to_date)
    cs_temp = gcsd.getGriddata(593273, 7612469, 'tm', from_date, to_date)
    cs_sno = gcsd.getGriddata(593273, 7612469, 'fsw', from_date, to_date)
    cs_snotot = gcsd.getGriddata(593273, 7612469, 'sd', from_date, to_date)
    wsCC = gws.getMetData(87640, 'NNM', startDate, endDate, 0, 'list')  # Harstad Stadion

    temp, date = we.strip_metadata(cs_temp, True)
    sno = we.strip_metadata(cs_sno, False)
    snotot = we.strip_metadata(cs_snotot, False)
    cc = we.strip_metadata(wsCC, False)

    observed_ice = gro.get_all_season_ice(LocationName, startDate, endDate)

    if len(observed_ice) == 0:
        ice_cover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno, cc)
    else:
        ice_cover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno, cc)

    plot_filename = '{0}Skoddebergvatnet {1}-{2}.png'.format(plot_folder, startDate[0:4], endDate[0:4])
    pts.plot_ice_cover(ice_cover, observed_ice, date, temp, snotot, plot_filename)
Пример #6
0
def runHakkloa(startDate, endDate):

    LocationName = 'Hakkloa nord 372 moh'
    from_date = dt.datetime.strptime(startDate, "%Y-%m-%d")
    to_date = dt.datetime.strptime(endDate, "%Y-%m-%d")

    cs_temp = gcsd.getStationdata('6.24.4','17.1', from_date, to_date, timeseries_type=0)
    cs_sno = gcsd.getGriddata(260150, 6671135, 'fsw', from_date, to_date, timeseries_type=0)
    cs_snotot = gcsd.getGriddata(260150, 6671135, 'sd', from_date, to_date, timeseries_type=0)
    wsCC = gws.getMetData(18700, 'NNM', startDate, endDate, 0, 'list')

    temp, date = we.strip_metadata(cs_temp, True)
    sno = we.strip_metadata(cs_sno, False)
    snotot = we.strip_metadata(cs_snotot, False)
    cc = we.strip_metadata(wsCC, False)

    observed_ice = gro.get_all_season_ice(LocationName, startDate, endDate)

    if len(observed_ice) == 0:
        ice_cover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno, cc)
    else:
        ice_cover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno, cc)

    plot_filename = '{0}Hakkloa {1}-{2}.png'.format(plot_folder, startDate[0:4], endDate[0:4])
    pts.plot_ice_cover(ice_cover, observed_ice, date, temp, snotot, plot_filename)
Пример #7
0
def runOrovannMET(startDate, endDate):

    location_name = 'Otrøvatnet v/Nystuen 971 moh'
    wsTemp = gws.getMetData(54710, 'TAM', startDate, endDate, 0, 'list')
    wsSno  = gws.getMetData(54710, 'SA',  startDate, endDate, 0, 'list')

    date = []
    snotot = []
    temp = []

    for e in wsTemp:
        date.append(e.Date)
        temp.append(e.Value)
    for e in wsSno:
        snotot.append(e.Value)

    sno = dp.delta_snow_from_total_snow(snotot)

    #observed_ice_filename = '{0}Otroevann observasjoner {1}-{2}.csv'.format(data_path, startDate.year, endDate.year)
    #observed_ice = importColumns(observed_ice_filename)
    observed_ice = gro.get_all_season_ice(location_name, startDate, endDate)

    if len(observed_ice) == 0:
        icecover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno)
    else:
        icecover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno)

    # Need datetime objects from now on
    from_date = dt.datetime.strptime(startDate, "%Y-%m-%d")
    to_date = dt.datetime.strptime(endDate, "%Y-%m-%d")

    plot_filename = '{0}Ortovann MET {1}-{2}.png'.format(plot_folder, from_date.year, to_date.year)
    pts.plot_ice_cover(icecover, observed_ice, date, temp, snotot, plot_filename)
Пример #8
0
def calculate_ice_cover_eb(
        utm33_x, utm33_y, date, temp_atm, prec, prec_snow, cloud_cover, wind, rel_hum, pressure_atm, inn_column=None):
    """

    :param utm33_x:
    :param utm33_y:
    :param date:
    :param temp_atm:
    :param prec:
    :param prec_snow:
    :param cloud_cover:
    :param wind:
    :param inn_column:
    :return:
    """

    if inn_column is None:
        inn_column = ice.IceColumn(date[0], [])

    icecover = []
    time_span_in_sec = 60*60*24     # fixed timestep of 24hrs given in seconds
    inn_column.remove_metadata()
    inn_column.remove_time()
    icecover.append(copy.deepcopy(inn_column))
    energy_balance = []

    age_factor_tau = 0.
    albedo_prim = const.alfa_black_ice

    for i in range(0, len(date), 1):
        print "{0}".format(date[i])
        if date[i] < inn_column.date:
            i = i + 1
        else:
            out_column, eb = dit.get_ice_thickness_from_energy_balance(
                utm33_x=utm33_x, utm33_y=utm33_y, ice_column=inn_column, temp_atm=temp_atm[i],
                prec=prec[i], prec_snow=prec_snow[i], time_span_in_sec=time_span_in_sec,
                albedo_prim=albedo_prim, age_factor_tau=age_factor_tau, wind=wind[i], cloud_cover=cloud_cover[i],
                rel_hum=rel_hum[i], pressure_atm=pressure_atm[i])

            icecover.append(out_column)
            energy_balance.append(eb)
            inn_column = copy.deepcopy(out_column)

            if eb.EB is None:
                age_factor_tau = 0.
                albedo_prim = const.alfa_black_ice
            else:
                age_factor_tau = eb.age_factor_tau
                albedo_prim = eb.albedo_prim

    return icecover, energy_balance
Пример #9
0
def runSemsvann(startDate, endDate):

    LocationName = 'Semsvannet v/Lo 145 moh'

    wsTemp = gws.getMetData(19710, 'TAM', startDate, endDate, 0, 'list')
    wsSno = gws.getMetData(19710, 'SA', startDate, endDate, 0, 'list')
    wsCC = gws.getMetData(18700, 'NNM', startDate, endDate, 0, 'list')

    temp, date = we.strip_metadata(wsTemp, True)
    snotot = we.strip_metadata(wsSno, False)
    cc = we.strip_metadata(wsCC, False)

    sno = dp.delta_snow_from_total_snow(snotot)

    #observed_ice_filename = '{0}Semsvann observasjoner {1}-{2}.csv'.format(data_path, startDate[0:4], endDate[0:4])
    #observed_ice = importColumns(observed_ice_filename)
    observed_ice = gro.get_all_season_ice(LocationName, startDate, endDate)
    if len(observed_ice) == 0:
        icecover = calculate_ice_cover_air_temp(ice.IceColumn(date[0], []), date, temp, sno, cc)
    else:
        icecover = calculate_ice_cover_air_temp(copy.deepcopy(observed_ice[0]), date, temp, sno, cc)

    plot_filename = '{0}Semsvann {1}-{2}.png'.format(plot_folder, startDate[0:4], endDate[0:4])
    pts.plot_ice_cover(icecover, observed_ice, date, temp, snotot, plot_filename)
Пример #10
0
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
Пример #11
0
def importColumns(filepath_inn):
    '''Reads observed ice columns from file. Input file contains multiple observations.
    Method returns a list of ice coluns.

    :param filepath_inn:    path to the .csv file with observations
    :return:                a list of iceColumn objects [iceColum, iceColum, iceColum, ...]

    Example of inputfile:

    ##################
    #
    #  Observed icecolumns on Otrøvannet winter 2011-2012
    #  Values given as [value; type].
    #  Valid values are: 'date', 'water_line' and all the ice types: 'black_ice', 'slush_ice', 'slush', 'snow'.
    #  Hashtags are omitted and ' ', \n and such are removed when reading the file.
    #  An observation with only date is of "no ice".
    #
    ##################

    2011-12-08; date

    ##################

    2012-01-16; date
    0.32; snow
    0.01; slush
    0.08; slush_ice
    0.22; black_ice
    0.29; water_line

    ##################

    '''
    import copy
    import ice as ice

    # Read file
    innfile = open(filepath_inn)
    inndata = innfile.readlines()
    innfile.close()

    # fileseperator
    separator = ';'

    # This column is only for initiation and is removed from columns before returned
    column = ice.IceColumn(dt.datetime(1, 1, 1), 0)
    columns = []

    for row in inndata:
        row = row.strip()  # get rid of ' ' and '\n' and such on the row
        if len(row) != 0 and row[0] != '#':
            row = row.split(
                separator)  # splits line into list of elements in the line
            row[0] = row[0].strip(
            )  # get rid of ' ' and '\n' and such on the separate elements
            row[1] = row[1].strip()
            if row[1] == 'date':
                columns.append(copy.deepcopy(column))
                date = dt.datetime.strptime(row[0], "%Y-%m-%d")
                column = ice.IceColumn(date, 0)
            elif row[1] == 'water_line':
                column.water_line = float(row[0])
            else:
                column.add_layer_at_index(-1,
                                          ice.IceLayer(float(row[0]), row[1]))

    # the last object is not added in the loop
    columns.append(column)

    # this was the inital object. If data is the first element of the inputfile this object is empty.
    # If date was not sett before rows with icelayers the icelayer data is lost.
    columns.remove(columns[0])

    # This must be set on each object because Ive not been able to find a way to initialize it properly yet
    for column in columns:
        if column.water_line == -1:
            column.update_water_line()

    return columns