[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[IDV #EWA-848337]: Method to convert Pressure field to Height Field



> On 12/17/2011 02:16 AM, Unidata IDV Support wrote:
> > Ghansham,
> >
> > Can you please tell us a bit more about what you are trying to do? You are 
> > using VisAD notation. I assume you wish to this conversion programmatically 
> > from Jython? In the meantime, I will dig around and see what I can find.
> >
> > Best,
> >
> > Unidata IDV Support
> >
> >> Is there any method to convert Pressure field
> >> (Lat,Lon)->(Pressure[hPa/mbar])
> >> to
> >> (Lat,Lon)->Height
> >>
> >> regards
> >> Ghansham
> >>
> >>
> >
> > Ticket Details
> > ===================
> > Ticket ID: EWA-848337
> > Department: Support IDV
> > Priority: Normal
> > Status: Open
> >
> Thanks for the prompt reply.
> I was trying to find any derived formula that you have for doing this.
> Although I have tried to do it in the following fashion. But I am not
> sure if this is generalized enough. Someone told me that we have such
> stuff in IDV (ucar.unidata.data.grid). But I could find that.
> 
> I think there is scope for generalizing this method by calling a more
> descriptive constructor of new_flatfield. Can you just help in that? I
> thought if I could use a more tested and generalized stuff. It should
> work for both FieldImpl and FlatFields.
> 
> public static FieldImpl createHeightField(FieldImpl pres_field) throws
> VisADException, RemoteException {
> 
> FlatField ff = null;
> if (pres_field instanceof FlatField) {
> ff = (FlatField) pres_field;
> float samples[][] = ff.getFloats(true);
> CoordinateSystem pres_to_height_cs =
> DataUtil.getPressureToHeightCS(DataUtil.STD_ATMOSPHERE);
> Unit cs_units[] =
> pres_to_height_cs.getCoordinateSystemUnits();
> FunctionType ftype = (FunctionType) ff.getType();
> RealTupleType rangeType = (RealTupleType) ftype.getRange();
> MathType rangeComps[] = rangeType.getComponents();
> if (rangeComps == null) {
> throw new VisADException("range cannot be null");
> }
> if (rangeComps.length > 1) {
> throw new VisADException("range should be equal to 1");
> }
> if (rangeComps[0] == null) {
> throw new VisADException("range cannot be null");
> }
> RealType pres_type = (RealType) rangeComps[0];
> Unit pres_unit = pres_type.getDefaultUnit();
> 
> Unit in_units[] = new Unit[]{pres_unit};
> if (!cs_units[0].equals(pres_unit)) {
> samples = Unit.convertTuple(samples, in_units,
> cs_units, false);
> }
> float out_samples[][] =
> pres_to_height_cs.toReference(samples);
> RealType height_type =
> RealType.getRealType(pres_type.getName() + "converted_to_height",
> SI.meter);
> rangeType = new RealTupleType(height_type);
> ftype = new FunctionType(ftype.getDomain(), rangeType);
> ff = new FlatField(ftype, ff.getDomainSet(), null, null,
> ff.getRangeSets(), ff.getDefaultRangeUnits());
> ff.setSamples(out_samples, true);
> } else {
> int num_samples = pres_field.getLength();
> FunctionType field_ftype = (FunctionType)
> pres_field.getType();
> FunctionType ff_ftype = (FunctionType) field_ftype.getRange();
> RealTupleType rangeType = (RealTupleType) ff_ftype.getRange();
> MathType rangeComps[] = rangeType.getComponents();
> if (rangeComps == null) {
> throw new VisADException("range cannot be null");
> }
> if (rangeComps.length > 1) {
> throw new VisADException("range should be equal to 1");
> }
> if (rangeComps[0] == null) {
> throw new VisADException("range cannot be null");
> }
> RealType pres_type = (RealType) rangeComps[0];
> Unit pres_unit = pres_type.getDefaultUnit();
> if (!Unit.canConvert(pres_unit, CommonUnits.HECTOPASCAL)) {
> throw new VisADException("range unit not convertible to
> height");
> }
> Unit in_units[] = new Unit[]{pres_unit};
> RealType height_type =
> RealType.getRealType(pres_type.getName() + "converted_to_height",
> SI.meter);
> FlatField ffs[] = new FlatField[num_samples];
> for (int i = 0; i < num_samples; i++) {
> ffs[i] = (FlatField) pres_field.getSample(i);
> }
> 
> rangeType = new RealTupleType(height_type);
> ff_ftype = new FunctionType(ff_ftype.getDomain(), rangeType);
> field_ftype = new FunctionType(field_ftype.getDomain(),
> ff_ftype);
> pres_field = new FieldImpl(field_ftype,
> pres_field.getDomainSet());
> 
> for (int i = 0; i < num_samples; i++) {
> CoordinateSystem pres_to_height_cs =
> DataUtil.getPressureToHeightCS(DataUtil.STD_ATMOSPHERE);
> Unit cs_units[] =
> pres_to_height_cs.getCoordinateSystemUnits();
> float samples[][] = ffs[i].getFloats(true);
> if (!cs_units[0].equals(pres_unit)) {
> samples = Unit.convertTuple(samples, in_units,
> cs_units, false);
> }
> float out_samples[][] =
> pres_to_height_cs.toReference(samples);
> ffs[i] = new FlatField(ff_ftype, ffs[i].getDomainSet());
> ffs[i].setSamples(out_samples, true);
> pres_field.setSample(i, ffs[i], true);
> }
> }
> return pres_field;
> 
> }
> 
> 
> One more query, out of the way, I have a ticket ID (for NetCDF java) for
> which I have not received any response for quite sometime after initial
> responses. Can I track that down?
> regards
> Ghansham
> 

Ghansham,
       My first reaction is to simply call newUnit(), but the unit Pa is not 
convertible to meter. I am thinking no other easier way to do this kind of 
conversion.
       The status of your netCDF ticket has not changed due to holidays and a 
few conferences at the end of the year.

Sorry about it.


Yuan
> 


Ticket Details
===================
Ticket ID: EWA-848337
Department: Support IDV
Priority: Normal
Status: Closed