<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Precipitation in the BMI-ed Meteorology component
Goal
Step1:  Import the Meteorology component and create an instance
Step2:  Locate the cfg file and initialize the component
Step3:  Despite setting a value of 20 mm/hr for P in the cfg file, if I call get_value at this point, the model precip values are zeroed out
Step4:  Maybe this will change after the first update?
Show the model start, current, and stop times
Step5:  Advance the model by one time step
Step6:  Note that it hasn't precipitated
Step7:  But this might be expected, since the initial precip value retrieved by get_value was also zero.
Try manually setting the precip rate variable to an arbitrary non-zero value
Step8:  Note that I can't simply give set_value a new value of 15; I need to create a one-element Numpy array with a value of 15 to match what TopoFlow needs internally.
Advance the model by another time step
Step9:  Is precipitation being produced?
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import numpy as np
Explanation: Precipitation in the BMI-ed Meteorology component
Goal: In this example, I want to give the Meteorology component a constant scalar precipitation value and check whether it produces output when the model state is updated.
Start with an import and some magic:
End of explanation
from topoflow.components.met_base import met_component
m = met_component()
Explanation: Import the Meteorology component and create an instance:
End of explanation
cfg_file = './input/meteorology.cfg'
m.initialize(cfg_file)
Explanation: Locate the cfg file and initialize the component:
End of explanation
precip = m.get_value('atmosphere_water__precipitation_leq-volume_flux')  # `P` internally
print type(precip)
print precip.size
precip
Explanation: Despite setting a value of 20 mm/hr for P in the cfg file, if I call get_value at this point, the model precip values are zeroed out:
End of explanation
print m.get_start_time(), m.get_current_time(), m.get_end_time()
Explanation: Maybe this will change after the first update?
Show the model start, current, and stop times:
End of explanation
m.update()
print '\nCurrent time: {} s'.format(m.get_current_time())
Explanation: Advance the model by one time step:
End of explanation
precip = m.get_value('atmosphere_water__precipitation_leq-volume_flux')
print precip
Explanation: Note that it hasn't precipitated:
End of explanation
new_value = np.array(15, dtype=np.float64)  # set_value doesn't convert to the TF type...
m.set_value('atmosphere_water__precipitation_leq-volume_flux', new_value)
precip = m.get_value('atmosphere_water__precipitation_leq-volume_flux')
print precip
Explanation: But this might be expected, since the initial precip value retrieved by get_value was also zero.
Try manually setting the precip rate variable to an arbitrary non-zero value:
End of explanation
m.update()
print '\nCurrent time: {} s'.format(m.get_current_time())
Explanation: Note that I can't simply give set_value a new value of 15; I need to create a one-element Numpy array with a value of 15 to match what TopoFlow needs internally.
Advance the model by another time step:
End of explanation
precip = m.get_value('atmosphere_water__precipitation_leq-volume_flux')
print precip
Explanation: Is precipitation being produced?
End of explanation
<END_TASK>