working at cell level instead of subcatchment

16 views
Skip to first unread message

Joseba Ullibarri

unread,
May 15, 2017, 4:49:15 AM5/15/17
to shyft
Hei,

I am trying to simulate and extract the swe for a certain point, from which I knoe the exact coordinates, in the Nea-Nidelva catchment.
How can I delimit the running simulation only for a certain number of cells around that point, instead of running for a whole subcatchment (ID: 1228, 1308, 1330, 1394, ... marked in yellow in the script below) ??

Thank you and looking forward to a response.

The script that I am using to extract the swe is the following one:

# from os import path # from shyft import shyftdata_dir from shyft import api from shyft.repository.default_state_repository import DefaultStateRepository from shyft.orchestration.configuration import yaml_configs from shyft.orchestration.simulators.config_simulator import ConfigSimulator config_dir = 'C:\\thesis\\shyft\\shyft\\tests\\netcdf\\neanidelva_ptgsk\\neanidelva_simulation.yaml' # Type the config file cfg = yaml_configs.YAMLSimConfig(config_dir, "neanidelva") # get a simulator simulator = ConfigSimulator(cfg) # activate collection (saving) of swe and sca since it is deactivated by default # This is usually used to activate calibration using snow data # simulator.region_model.set_snow_sca_swe_collection(-1, True) # -1 means for all catchments # activate collection (saving) of ALL states since it is deactivated by default simulator.region_model.set_state_collection(-1, True) # -1 means for all catchments n_cells = simulator.region_model.size() state_repos = DefaultStateRepository(simulator.region_model.__class__, n_cells) simulator.run(cfg.time_axis, state_repos.get_state(0)) # SWE and SCA are responses in ptgsk # to extract swe from ptgsk as a numpy array # swe = simulator.region_model.gamma_snow_response.swe([]).v.to_numpy() # SWE and SCA are states in ptssk and pthsk # to extract swe from ptssk as a numpy array # swe = simulator.region_model.skaugen_snow_state.swe([]).v.to_numpy() # to extract swe from pthsk as a numpy array # swe = simulator.region_model.hbv_snow_state.swe([]).v.to_numpy() ts_swe = simulator.region_model.gamma_snow_response.swe([]) # specify snow routine and state/response !! and catchment values = ts_swe.v.to_numpy() print(values) from datetime import datetime times = [datetime.utcfromtimestamp(ts_swe.time(i)) for i in range(ts_swe.size())] import matplotlib.pyplot as plt fig,ax = plt.subplots() plt.ylabel("Snow Water Equivalent [mm]", fontsize=12) ax.plot(times,values)




Felix Matt

unread,
May 16, 2017, 4:49:09 AM5/16/17
to sh...@googlegroups.com

Hi,

Not sure if I'm interpreting correctly what you want.

If you just want the time-series of a state- or result-variable for a certain cell, then just access the cells via

    cells = simulator.region_model.cells

This returns a list-like object with each cell of the simulation.

Then you can access a cetain cell, e.g.

    cell = cells[129]

Each cell has a geo-location:

    cell.mid_point().x

    cell.mid_point().y

    cell.mid_point().z

If you search for a cell closes to you measurements, just loop over the cells and find the cell with the closest geo-location to you measurment location.

When you found your cell, you can access the state and result variables of that cell (here shown for SWE in the response-collector "rc") via the response and the state collectors:

   swe = cell.rc.snow_swe.v.to_numpy()

Is that what you mean?

Best,

Felix

--
You received this message because you are subscribed to the Google Groups "shyft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shyft+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shyft/14e7f868-03f4-4533-8eec-d3d784c34640%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joseba Ullibarri

unread,
May 16, 2017, 11:17:14 AM5/16/17
to shyft, f.n....@geo.uio.no
Hei,

Thank you Felix.

Yes, that was very helpful.

Best regards,

Joseba
Reply all
Reply to author
Forward
0 new messages