예제 #1
0
파일: test.py 프로젝트: pcraster/pcraster
 def testComException(self):
   exceptionThrown = False
   try:
     # Calculating the slope of a boolean map sucks.
     slope = pcraster.slope("and_Expr1.map")
   except RuntimeError, exception:
     message = str(exception)
     self.assert_(string.find(message, "argument nr. 1 of function 'slope': type is boolean, legal type is scalar") != -1)
     exceptionThrown = True
예제 #2
0
파일: test.py 프로젝트: xuexianwu/pcraster
 def testComException(self):
   exceptionThrown = False
   try:
     # Calculating the slope of a boolean map sucks.
     slope = pcraster.slope("and_Expr1.map")
   except RuntimeError as exception:
     message = str(exception)
     self.assert_(message.find("argument nr. 1 of function 'slope': type is boolean, legal type is scalar") != -1)
     exceptionThrown = True
   self.assert_(exceptionThrown)
예제 #3
0
 def assignDemSlope(self, glacmask):
     mask = np.where(glacmask==self.mv)
     #-copy of entire dem
     glacdem = np.copy(self.dem)
     #-calculate max and min dem values of selected glacier
     z = np.copy(glacdem)
     z[mask] = np.nan
     z = z.flatten()
     dH = np.nanmax(z) - np.nanmin(z)
     z = None; del z
     #-assign missing values where glacier is not true
     glacdem[mask] = self.demMV
     #-convert dem to pcraster map to calculate slope
     glacdem = pcr.numpy2pcr(pcr.Scalar, glacdem, self.demMV)
     glacSlope = pcr.slope(glacdem); #m = None; del m
     glacSlope = pcr.pcr2numpy(glacSlope, self.demMV)
     glacSlope = np.arctan(glacSlope) / math.pi * 180
     glacSlope[mask] = np.nan
     glacdem = pcr.pcr2numpy(glacdem, np.nan)
     return glacdem, glacSlope, dH
예제 #4
0
import rasterio

from rasterio.plot import show

from rasterio.plot import show_hist

from rasterio.mask import mask

import pycrs

dem = 'D:/Chinmay/Hydro_modeling_erin_fall_2018/sp_model/dem.map'
output_path = 'D:/Chinmay/Hydro_modeling_erin_fall_2018/sp_model/'

pcr.setclone(dem)

slope = pcr.slope(dem)
pcr.report(slope, output_path + "gradient.map")

ldd = pcr.lddcreate(dem, 1e31, 1e31, 1e31, 1e31)
pcr.report(ldd, output_path + "ldd.map")

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

#def downloadDEM(url):
#
#    """The function downloads the DEM from the given url
#    (In this case National Elevation Dataset, USGS.) """
#    # Translate url into a filename
#    filename = url.rsplit('/', 1)[-1]
#    if not os.path.exists(filename):
#        outfile = urllib.URLopener()
예제 #5
0
    def createInstancesInitial(self):
        import generalfunctions

        if readDistributionOfParametersFromDisk:
            path = '/home/derek/tmp/'
            maximumInterceptionCapacityPerLAI = pcr.scalar(
                path +
                pcrfw.generateNameS('RPic', self.currentSampleNumber()) +
                '.map')
            ksat = pcr.scalar(
                path +
                pcrfw.generateNameS('RPks', self.currentSampleNumber()) +
                '.map')
            regolithThicknessHomogeneous = pcr.scalar(
                path +
                pcrfw.generateNameS('RPrt', self.currentSampleNumber()) +
                '.map')
            saturatedConductivityMetrePerDay = pcr.scalar(
                path +
                pcrfw.generateNameS('RPsc', self.currentSampleNumber()) +
                '.map')
            multiplierMaxStomatalConductance = pcr.scalar(
                path +
                pcrfw.generateNameS('RPmm', self.currentSampleNumber()) +
                '.map')
        else:
            maximumInterceptionCapacityPerLAI = generalfunctions.areauniformBounds(
                0.0001, 0.0005, pcr.nominal(1),
                pcr.scalar(cfg.maximumInterceptionCapacityValue),
                createRealizations)
            ksat = generalfunctions.areauniformBounds(
                0.025, 0.05, pcr.nominal(1), pcr.scalar(cfg.ksatValue),
                createRealizations)
            regolithThicknessHomogeneous = generalfunctions.areauniformBounds(
                1.0, 3.5, cfg.areas,
                pcr.scalar(cfg.regolithThicknessHomogeneousValue),
                createRealizations)
            saturatedConductivityMetrePerDay = generalfunctions.mapuniformBounds(
                25.0, 40.0,
                pcr.scalar(cfg.saturatedConductivityMetrePerDayValue),
                createRealizations)
            multiplierMaxStomatalConductance = generalfunctions.mapuniformBounds(
                0.8, 1.1,
                pcr.scalar(cfg.multiplierMaxStomatalConductanceValue),
                createRealizations)

        if swapCatchments:
            regolithThicknessHomogeneous = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, regolithThicknessHomogeneous, True)

        self.d_randomparameters = randomparameters.RandomParameters(
            timeStepsToReportRqs, setOfVariablesToReport,
            maximumInterceptionCapacityPerLAI, ksat,
            regolithThicknessHomogeneous, saturatedConductivityMetrePerDay,
            multiplierMaxStomatalConductance)

        # class for exchange variables in initial and dynamic
        # introduced to make filtering possible
        self.d_exchangevariables = exchangevariables.ExchangeVariables(
            timeStepsToReportSome,
            setOfVariablesToReport,
        )

        ################
        # interception #
        ################

        self.ldd = cfg.lddMap

        initialInterceptionStore = pcr.scalar(0.000001)
        leafAreaIndex = pcr.scalar(cfg.leafAreaIndexValue)

        if swapCatchments:
            leafAreaIndex = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, leafAreaIndex, True)
        gapFraction = pcr.exp(
            -0.5 * leafAreaIndex)  # equation 40 in Brolsma et al 2010a
        maximumInterceptionStore = maximumInterceptionCapacityPerLAI * leafAreaIndex

        self.d_interceptionuptomaxstore = interceptionuptomaxstore.InterceptionUpToMaxStore(
            self.ldd, initialInterceptionStore, maximumInterceptionStore,
            gapFraction, self.timeStepDurationHours, timeStepsToReportSome,
            setOfVariablesToReport)

        #################
        # surface store #
        #################

        initialSurfaceStore = pcr.scalar(0.0)
        maxSurfaceStore = pcr.scalar(cfg.maxSurfaceStoreValue)
        self.d_surfaceStore = surfacestore.SurfaceStore(
            initialSurfaceStore, maxSurfaceStore, self.timeStepDurationHours,
            timeStepsToReportSome, setOfVariablesToReport)

        ################
        # infiltration #
        ################

        # N initialMoistureContentFraction taken from 1st July

        # DK
        # we do not use rts and Gs as input to calculate initial moisture fraction to avoid
        # problems when the initial regolith thickness is calibrated (it might be thinner than
        # initialMoistureThick -> problems!)
        # instead, we use initial moisture content fraction as input, read from disk, it is just calculated
        # by pcrcalc 'mergeInitialMoistureContentFraction=Gs000008.761/rts00008.761'
        # note that I also changed the name for the initial soil moisture as a fraction
        initialSoilMoistureFractionFromDisk = pcr.scalar(
            cfg.initialSoilMoistureFractionFromDiskValue)
        if swapCatchments:
            initialSoilMoistureFractionFromDisk = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, initialSoilMoistureFractionFromDisk, True)

        # initial soil moisture as a fraction should not be above soil porosity as a fraction, just a check
        soilPorosityFraction = pcr.scalar(cfg.soilPorosityFractionValue)
        if swapCatchments:
            soilPorosityFraction = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, soilPorosityFraction, True)
        initialSoilMoistureFraction = pcr.min(
            soilPorosityFraction, initialSoilMoistureFractionFromDisk)
        hf = pcr.scalar(-0.0000001)
        self.d_infiltrationgreenandampt = infiltrationgreenandampt.InfiltrationGreenAndAmpt(
            soilPorosityFraction, initialSoilMoistureFraction, ksat, hf,
            self.timeStepDurationHours, timeStepsToReportSome,
            setOfVariablesToReport)

        ####################
        # subsurface water #
        ####################

        demOfBedrockTopography = self.dem

        stream = pcr.boolean(cfg.streamValue)
        theSlope = pcr.slope(self.dem)
        regolithThickness = pcr.ifthenelse(stream, 0.01,
                                           regolithThicknessHomogeneous)

        self.multiplierWiltingPoint = pcr.scalar(1.0)
        limitingPointFraction = pcr.scalar(cfg.limitingPointFractionValue)

        if swapCatchments:
            limitingPointFraction = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, limitingPointFraction, True)
        mergeWiltingPointFractionFS = pcr.scalar(
            cfg.mergeWiltingPointFractionFSValue)
        if swapCatchments:
            mergeWiltingPointFractionFS = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, mergeWiltingPointFractionFS, True)
        wiltingPointFractionNotChecked = mergeWiltingPointFractionFS * self.multiplierWiltingPoint
        wiltingPointFraction = pcr.min(wiltingPointFractionNotChecked,
                                       limitingPointFraction)

        fieldCapacityFraction = pcr.scalar(cfg.fieldCapacityFractionValue)
        if swapCatchments:
            fieldCapacityFraction = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, fieldCapacityFraction, True)

        self.d_subsurfaceWaterOneLayer = subsurfacewateronelayer.SubsurfaceWaterOneLayer(
            self.ldd, demOfBedrockTopography, regolithThickness,
            initialSoilMoistureFraction, soilPorosityFraction,
            wiltingPointFraction, fieldCapacityFraction, limitingPointFraction,
            saturatedConductivityMetrePerDay, self.timeStepDurationHours,
            timeStepsToReportSome, setOfVariablesToReport)

        ##########
        # runoff #
        ##########

        self.d_runoffAccuthreshold = runoffaccuthreshold.RunoffAccuthreshold(
            self.ldd, self.timeStepDurationHours, timeStepsToReportRqs,
            setOfVariablesToReport)

        ######################
        # evapotranspiration #
        ######################

        albedo = pcr.scalar(cfg.albedoValue)
        if swapCatchments:
            albedo = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, albedo, True)

        maxStomatalConductance = pcr.scalar(
            cfg.maxStomatalConductanceValue) * multiplierMaxStomatalConductance
        if swapCatchments:
            maxStomatalConductance = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, maxStomatalConductance, True)

        vegetationHeight = pcr.scalar(cfg.vegetationHeightValue)
        if swapCatchments:
            vegetationHeight = generalfunctions.swapValuesOfTwoRegions(
                cfg.areas, vegetationHeight, True)
        self.d_evapotranspirationPenman = evapotranspirationpenman.EvapotranspirationPenman(
            self.timeStepDurationHours, albedo, maxStomatalConductance,
            vegetationHeight, leafAreaIndex, timeStepsToReportSome,
            setOfVariablesToReport)