Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
projection.hh
Go to the documentation of this file.
1/* Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2023, 2024 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef PISM_PROJECTION_H
21#define PISM_PROJECTION_H
22
23#include <string>
24#include <array>
25
26#include "pism/util/Units.hh"
27#include "pism/util/VariableMetadata.hh"
28
29namespace pism {
30
31class File;
32namespace array {
33class Array3D;
34class Scalar;
35}
36
37/*!
38 * Return the string that describes a 2D grid present in a NetCDF file.
39 *
40 * Here `variable_name` is the name of a 2D variable used to extract
41 * grid information.
42 *
43 * We assume that a file may contain more than one grid, so the file
44 * name alone is not sufficient.
45 *
46 * Appends ":piecewise_constant" if `piecewise_constant` is true.
47 *
48 * The output has the form "input_file.nc:y:x".
49 */
50std::string grid_name(const File &file, const std::string &variable_name,
51 units::System::Ptr sys, bool piecewise_constant);
52
53/*! @brief Convert a proj string with an EPSG code to a set of CF attributes. */
54/*!
55 * Fails if `proj_string` does not contain an EPSG code.
56 */
57VariableMetadata epsg_to_cf(units::System::Ptr system, const std::string &proj_string);
58
60public:
61 MappingInfo(const std::string &mapping_variable_name, units::System::Ptr unit_system);
62 MappingInfo(const VariableMetadata &mapping_variable, const std::string &proj_string);
63
64 /*! @brief Get projection info from a file. */
65 static MappingInfo FromFile(const File &input_file, const std::string &variable_name,
66 units::System::Ptr unit_system);
67
68 //! grid mapping description following CF conventions
70
71 //! a projection definition string in a format recognized by PROJ 6.x+
72 std::string proj_string;
73};
74
75void write_mapping(const File &file, const pism::MappingInfo &info);
76
77/*!
78 * Parse a string "EPSG:XXXX", "epsg:XXXX", "+init=epsg:XXXX" and return the EPSG code
79 * (XXXX).
80 */
81int parse_epsg(const std::string &proj_string);
82
83/*! @brief Check consistency of the "mapping" variable with the EPSG code in the proj string. */
84/*!
85 * If the consistency check fails, throws RuntimeError explaining the failure. Fails if `info.proj`
86 * does not use an EPSG code.
87 */
88void check_consistency_epsg(const VariableMetadata &cf_mapping, const std::string &proj_string);
89
90void compute_longitude(const std::string &projection, array::Scalar &result);
91void compute_latitude(const std::string &projection, array::Scalar &result);
92
93void compute_lon_bounds(const std::string &projection, array::Array3D &result);
94void compute_lat_bounds(const std::string &projection, array::Array3D &result);
95
96/*!
97 * Convert Climate and Forecasting (CF) convention metadata to a PROJ.4 style projection
98 * definition.
99 */
100std::string cf_to_proj(const VariableMetadata &mapping);
101
102} // end of namespace pism
103
104#endif /* PISM_PROJECTION_H */
High-level PISM I/O class.
Definition File.hh:55
VariableMetadata cf_mapping
grid mapping description following CF conventions
Definition projection.hh:69
std::string proj_string
a projection definition string in a format recognized by PROJ 6.x+
Definition projection.hh:72
static MappingInfo FromFile(const File &input_file, const std::string &variable_name, units::System::Ptr unit_system)
Get projection info from a file.
A virtual class collecting methods common to ice and bedrock 3D fields.
Definition Array3D.hh:33
std::shared_ptr< System > Ptr
Definition Units.hh:47
void check_consistency_epsg(const VariableMetadata &cf_mapping, const std::string &proj_string)
Check consistency of the "mapping" variable with the EPSG code in the proj string.
void write_mapping(const File &file, const pism::MappingInfo &info)
void compute_latitude(const std::string &projection, array::Scalar &result)
int parse_epsg(const std::string &proj_string)
Definition projection.cc:54
void compute_longitude(const std::string &projection, array::Scalar &result)
VariableMetadata epsg_to_cf(units::System::Ptr system, const std::string &proj_string)
Return CF-Convention "mapping" variable corresponding to an EPSG code specified in a PROJ string.
Definition projection.cc:90
std::string grid_name(const pism::File &file, const std::string &variable_name, pism::units::System::Ptr sys, bool piecewise_constant)
void compute_lat_bounds(const std::string &projection, array::Array3D &result)
void compute_lon_bounds(const std::string &projection, array::Array3D &result)
std::string cf_to_proj(const VariableMetadata &mapping)